replace chunk code
This commit is contained in:
parent
25d535703e
commit
09cbea65c7
6 changed files with 56 additions and 39 deletions
|
|
@ -29,6 +29,7 @@
|
|||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
|
||||
|
||||
- The netconf support has been extended with lock/unlock
|
||||
- clicon_rpc_call() has been removed and should be replaced by extending the
|
||||
internal netconf protocol.
|
||||
|
|
@ -46,6 +47,12 @@
|
|||
clicon_rpc_get_config(h, dbstr, api_path, &xt);
|
||||
xpath_vec(xt, api_path, &xvec, &xlen)
|
||||
|
||||
- clicon_rpc_change() is replaced with clicon_rpc_edit_config().
|
||||
Note modify argument 5:
|
||||
clicon_rpc_change(h, db, op, apipath, "value")
|
||||
to:
|
||||
clicon_rpc_edit_config(h, db, op, apipath, "<config>value</config>")
|
||||
|
||||
- xmdlb_put_xkey() and xmldb_put_tree() have been folded into xmldb_put()
|
||||
Replace xmldb_put_xkey with xmldb_put as follows:
|
||||
xmldb_put_xkey(h, "candidate", cbuf_get(cb), str, OP_REPLACE);
|
||||
|
|
|
|||
|
|
@ -256,8 +256,6 @@ catch:
|
|||
*
|
||||
* @param[in] h clicon handle
|
||||
* @param[in] xn Sub-tree (under xorig) at child of rpc: <rpc><xn></rpc>.
|
||||
* @param[out] cb Output xml stream. For reply
|
||||
* @param[out] cb_err Error xml stream. For error reply
|
||||
* @param[out] xret Return XML, error or OK
|
||||
*
|
||||
* @retval -1 Error
|
||||
|
|
|
|||
|
|
@ -77,8 +77,6 @@
|
|||
/*! Get configuration
|
||||
* @param[in] h Clicon handle
|
||||
* @param[in] xn Sub-tree (under xorig) at <rpc>...</rpc> level.
|
||||
* @param[out] cb Output xml stream. For reply
|
||||
* @param[out] cb_err Error xml stream. For error reply
|
||||
* @param[out] xret Return XML, error or OK
|
||||
* @note filter type subtree and xpath is supported, but xpath is preferred, and
|
||||
* better performance and tested. Please use xpath.
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ static inline char * strdup4(char *str)
|
|||
*/
|
||||
char **clicon_sepsplit (char *string, char *delim, int *nvec, const char *label);
|
||||
char **clicon_strsplit (char *string, char *delim, int *nvec, const char *label);
|
||||
char **clicon_strsep(char *string, char *delim, int *nvec0);
|
||||
char *clicon_strjoin (int argc, char **argv, char *delim, const char *label);
|
||||
char *clicon_strtrim(char *str, const char *label);
|
||||
int clicon_sep(char *s, const char sep[2], const char *label, char**a0, char **b0);
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@
|
|||
* @retval NULL Error
|
||||
* @see clicon_strsplit Operates on full string delimiters rather than
|
||||
* individual character delimiters.
|
||||
* @see clicon_strsep Use malloc instead of chunk
|
||||
*/
|
||||
char **
|
||||
clicon_sepsplit (char *string,
|
||||
|
|
@ -111,8 +112,6 @@ clicon_sepsplit (char *string,
|
|||
* the full delimiter string. The matched delimiters are not part of the
|
||||
* resulting vector.
|
||||
*
|
||||
* See also clicon_sepsplit() which is similar
|
||||
*
|
||||
* The vector returned is one single memory chunk that must be unchunked
|
||||
* by the caller
|
||||
*
|
||||
|
|
@ -124,6 +123,7 @@ clicon_sepsplit (char *string,
|
|||
* @retval NULL Error
|
||||
* @see clicon_sepsplit Operates on individual character delimiters rather
|
||||
* than full string delimiter.
|
||||
* @see clicon_strsep Use malloc instead of chunk
|
||||
*/
|
||||
char **
|
||||
clicon_strsplit (char *string,
|
||||
|
|
@ -165,6 +165,50 @@ clicon_strsplit (char *string,
|
|||
return vec;
|
||||
}
|
||||
|
||||
/*! Split string into a vector based on character delimiters. Using malloc
|
||||
*
|
||||
* The given string is split into a vector where the delimiter can be
|
||||
* any of the characters in the specified delimiter string.
|
||||
*
|
||||
* The vector returned is one single memory block that must be freed
|
||||
* by the caller
|
||||
*
|
||||
* @param[in] string String to be split
|
||||
* @param[in] delim String of delimiter characters
|
||||
* @param[out] nvec Number of entries in returned vector
|
||||
* @retval vec Vector of strings. Free after use
|
||||
* @retval NULL Error *
|
||||
*/
|
||||
char **
|
||||
clicon_strsep(char *string,
|
||||
char *delim,
|
||||
int *nvec0)
|
||||
{
|
||||
char **vec = NULL;
|
||||
char *ptr;
|
||||
char *p;
|
||||
int nvec = 1;
|
||||
int i;
|
||||
|
||||
for (i=0; i<strlen(string); i++)
|
||||
if (index(delim, string[i]))
|
||||
nvec++;
|
||||
/* alloc vector and append copy of string */
|
||||
if ((vec = (char**)malloc(nvec* sizeof(char*) + strlen(string)+1)) == NULL){
|
||||
clicon_err(OE_YANG, errno, "malloc");
|
||||
goto err;
|
||||
}
|
||||
ptr = (char*)vec + nvec* sizeof(char*); /* this is where ptr starts */
|
||||
strncpy(ptr, string, strlen(string)+1);
|
||||
i = 0;
|
||||
while ((p = strsep(&ptr, delim)) != NULL)
|
||||
vec[i++] = p;
|
||||
*nvec0 = nvec;
|
||||
err:
|
||||
return vec;
|
||||
}
|
||||
|
||||
|
||||
/*! Concatenate elements of a string array into a string.
|
||||
* An optional delimiter string can be specified which will be inserted betwen
|
||||
* each element.
|
||||
|
|
|
|||
|
|
@ -1676,37 +1676,6 @@ yang_xpath_vec(yang_node *yn,
|
|||
return yret;
|
||||
}
|
||||
|
||||
/* Alternative to clicon_strsplit using malloc. Note delim can only be one char
|
||||
* Free return value after use
|
||||
*/
|
||||
static char **
|
||||
clicon_strsplit_malloc(char *string,
|
||||
char *delim,
|
||||
int *nvec0)
|
||||
{
|
||||
char **vec = NULL;
|
||||
char *ptr;
|
||||
char *p;
|
||||
int nvec = 1;
|
||||
int i;
|
||||
|
||||
for (i=0; i<strlen(string); i++)
|
||||
if (string[i]==*delim)
|
||||
nvec++;
|
||||
/* alloc vector and append copy of string */
|
||||
if ((vec = (char**)malloc(nvec* sizeof(char*) + strlen(string)+1)) == NULL){
|
||||
clicon_err(OE_YANG, errno, "malloc");
|
||||
goto err;
|
||||
}
|
||||
ptr = (char*)vec + nvec* sizeof(char*); /* this is where ptr starts */
|
||||
strncpy(ptr, string, strlen(string)+1);
|
||||
i = 0;
|
||||
while ((p = strsep(&ptr, delim)) != NULL)
|
||||
vec[i++] = p;
|
||||
*nvec0 = nvec;
|
||||
err:
|
||||
return vec;
|
||||
}
|
||||
|
||||
/*! Given an absolute xpath (eg /a/b/c) find matching yang specification
|
||||
* @param[in] yn Yang node
|
||||
|
|
@ -1725,7 +1694,7 @@ yang_xpath_abs(yang_node *yn,
|
|||
char *id;
|
||||
char *prefix = NULL;
|
||||
|
||||
if ((vec = clicon_strsplit_malloc(xpath, "/", &nvec)) == NULL){
|
||||
if ((vec = clicon_strsep(xpath, "/", &nvec)) == NULL){
|
||||
clicon_err(OE_YANG, errno, "%s: strsplit", __FUNCTION__);
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -1807,7 +1776,7 @@ yang_xpath(yang_node *yn,
|
|||
/* check absolute path */
|
||||
if (xpath[0] == '/')
|
||||
return yang_xpath_abs(yn, xpath);
|
||||
if ((vec = clicon_strsplit_malloc(xpath, "/", &nvec)) == NULL)
|
||||
if ((vec = clicon_strsep(xpath, "/", &nvec)) == NULL)
|
||||
goto err;
|
||||
ys = yang_xpath_vec((yang_node*)yn, vec, nvec);
|
||||
err:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue