datastore text works with replace
This commit is contained in:
parent
ee9b74d735
commit
d02015f456
15 changed files with 627 additions and 160 deletions
|
|
@ -110,96 +110,6 @@ clicon_debug_xml(int dbglevel,
|
|||
return retval;
|
||||
}
|
||||
|
||||
/*! Split a string into a cligen variable vector using 1st and 2nd delimiter
|
||||
* Split a string first into elements delimited by delim1, then into
|
||||
* pairs delimited by delim2.
|
||||
* @param[in] string String to split
|
||||
* @param[in] delim1 First delimiter char that delimits between elements
|
||||
* @param[in] delim2 Second delimiter char for pairs within an element
|
||||
* @param[out] cvp Created cligen variable vector, NOTE: can be NULL
|
||||
* @retval 0 on OK
|
||||
* @retval -1 error
|
||||
*
|
||||
* Example, assuming delim1 = '&' and delim2 = '='
|
||||
* a=b&c=d -> [[a,"b"][c="d"]
|
||||
* kalle&c=d -> [[c="d"]] # Discard elements with no delim2
|
||||
* XXX differentiate between error and null cvec.
|
||||
*/
|
||||
int
|
||||
str2cvec(char *string,
|
||||
char delim1,
|
||||
char delim2,
|
||||
cvec **cvp)
|
||||
{
|
||||
int retval = -1;
|
||||
char *s;
|
||||
char *s0 = NULL;;
|
||||
char *val; /* value */
|
||||
char *valu; /* unescaped value */
|
||||
char *snext; /* next element in string */
|
||||
cvec *cvv = NULL;
|
||||
cg_var *cv;
|
||||
|
||||
clicon_debug(1, "%s %s", __FUNCTION__, string);
|
||||
if ((s0 = strdup(string)) == NULL){
|
||||
clicon_debug(1, "error strdup %s", strerror(errno));
|
||||
goto err;
|
||||
}
|
||||
s = s0;
|
||||
if ((cvv = cvec_new(0)) ==NULL){
|
||||
clicon_debug(1, "error cvec_new %s", strerror(errno));
|
||||
goto err;
|
||||
}
|
||||
while (s != NULL) {
|
||||
/*
|
||||
* In the pointer algorithm below:
|
||||
* name1=val1; name2=val2;
|
||||
* ^ ^ ^
|
||||
* | | |
|
||||
* s val snext
|
||||
*/
|
||||
if ((snext = index(s, delim1)) != NULL)
|
||||
*(snext++) = '\0';
|
||||
if ((val = index(s, delim2)) != NULL){
|
||||
*(val++) = '\0';
|
||||
if (percent_decode(val, &valu) < 0)
|
||||
goto err;
|
||||
if ((cv = cvec_add(cvv, CGV_STRING)) == NULL){
|
||||
clicon_debug(1, "error cvec_add %s", strerror(errno));
|
||||
goto err;
|
||||
}
|
||||
while ((strlen(s) > 0) && isblank(*s))
|
||||
s++;
|
||||
cv_name_set(cv, s);
|
||||
cv_string_set(cv, valu);
|
||||
free(valu); valu = NULL;
|
||||
}
|
||||
else{
|
||||
if (strlen(s)){
|
||||
if ((cv = cvec_add(cvv, CGV_STRING)) == NULL){
|
||||
clicon_debug(1, "error cvec_add %s", strerror(errno));
|
||||
goto err;
|
||||
}
|
||||
cv_name_set(cv, s);
|
||||
cv_string_set(cv, "");
|
||||
}
|
||||
}
|
||||
s = snext;
|
||||
}
|
||||
retval = 0;
|
||||
done:
|
||||
*cvp = cvv;
|
||||
if (s0)
|
||||
free(s0);
|
||||
return retval;
|
||||
err:
|
||||
if (cvv){
|
||||
cvec_free(cvv);
|
||||
cvv = NULL;
|
||||
}
|
||||
goto done;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @param[in] r Fastcgi request handle
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue