documentation

This commit is contained in:
Olof hagsand 2019-07-09 13:15:25 +02:00
parent 40d5b99d3b
commit bb04f778ab
3 changed files with 31 additions and 19 deletions

View file

@ -262,7 +262,7 @@ clicon_rpc_generate_error(char *prefix,
* cxobj *xt = NULL; * cxobj *xt = NULL;
* if (clicon_rpc_get_config(h, "running", "/hello/world", "urn:example:hello", &xt) < 0) * if (clicon_rpc_get_config(h, "running", "/hello/world", "urn:example:hello", &xt) < 0)
* err; * err;
* if ((xerr = xpath_first(xt, "/rpc-error")) != NULL){ * if ((xerr = xpath_first(xt, "/rpc-error")) != NULL){
* clicon_rpc_generate_error("", xerr); * clicon_rpc_generate_error("", xerr);
* err; * err;
* } * }
@ -297,7 +297,7 @@ clicon_rpc_get_config(clicon_handle h,
if (namespace) if (namespace)
cprintf(cb, "<nc:filter nc:type=\"xpath\" nc:select=\"%s\" xmlns=\"%s\"/>", cprintf(cb, "<nc:filter nc:type=\"xpath\" nc:select=\"%s\" xmlns=\"%s\"/>",
xpath, namespace); xpath, namespace);
else /* XXX shouldnt happen */ else /* If xpath != /, this will probably yield an error later */
cprintf(cb, "<filter type=\"xpath\" select=\"%s\"/>", xpath); cprintf(cb, "<filter type=\"xpath\" select=\"%s\"/>", xpath);
} }
cprintf(cb, "</get-config></rpc>"); cprintf(cb, "</get-config></rpc>");
@ -584,7 +584,7 @@ clicon_rpc_get(clicon_handle h,
if (namespace) if (namespace)
cprintf(cb, "<nc:filter nc:type=\"xpath\" nc:select=\"%s\" xmlns=\"%s\"/>", cprintf(cb, "<nc:filter nc:type=\"xpath\" nc:select=\"%s\" xmlns=\"%s\"/>",
xpath, namespace); xpath, namespace);
else /* XXX shouldnt happen */ else /* If xpath != /, this will probably yield an error later */
cprintf(cb, "<filter type=\"xpath\" select=\"%s\"/>", xpath); cprintf(cb, "<filter type=\"xpath\" select=\"%s\"/>", xpath);
} }
cprintf(cb, "</get></rpc>"); cprintf(cb, "</get></rpc>");

View file

@ -2279,10 +2279,9 @@ xml_spec_populate(cxobj *x,
return retval; return retval;
} }
/*! Translate from restconf api-path in cvv form to xml xpath /*! Translate from restconf api-path(cvv) to xml xpath(cbuf) and namespace
* eg a/b=c -> a/[b=c] *
* eg example:a/b -> ex:a/b * @param[in] api_path URI-encoded path expression" (RFC8040 3.5.3) as cvec
* @param[in] api_path api-path as cvec
* @param[in] offset Offset of cvec, where api-path starts * @param[in] offset Offset of cvec, where api-path starts
* @param[in] yspec Yang spec * @param[in] yspec Yang spec
* @param[in,out] xpath The xpath as cbuf (must be created and may have content) * @param[in,out] xpath The xpath as cbuf (must be created and may have content)
@ -2303,18 +2302,15 @@ xml_spec_populate(cxobj *x,
* cvec *cvv = NULL; * cvec *cvv = NULL;
* if (str2cvec("www.foo.com/restconf/a/b=c", '/', '=', &cvv) < 0) * if (str2cvec("www.foo.com/restconf/a/b=c", '/', '=', &cvv) < 0)
* err; * err;
* if ((ret = api_path2xpath(yspec, cvv, 0, cxpath, NULL)) < 0) * if ((ret = api_path2xpath_cvv(yspec, cvv, 0, cxpath, NULL)) < 0)
* err; * err;
* if (ret == 0){ * if (ret == 1)
* ... access error string in clicon_err_reason * ... access xpath as cbuf_get(xpath)
* clicon_err_reset();
* return;
* }
* ... access xpath as cbuf_get(xpath)
* cbuf_free(xpath) * cbuf_free(xpath)
* @endcode * @endcode
* @note "api-path" is "URI-encoded path expression" definition in RFC8040 3.5.3 * @note "api-path" is "URI-encoded path expression" definition in RFC8040 3.5.3
* @see api_path2xml For api-path to xml tree * @see api_path2xml For api-path to xml tree
* @see api_path2xpath Using strings as parameters
*/ */
int int
api_path2xpath_cvv(cvec *api_path, api_path2xpath_cvv(cvec *api_path,
@ -2408,10 +2404,24 @@ api_path2xpath_cvv(cvec *api_path,
goto done; goto done;
} }
/*! Translate from restconf api-path to xml xpath as cbuf and yang module /*! Translate from restconf api-path to xml xpath and namespace
* @retval 1 OK * @param[in] api_path URI-encoded path expression" (RFC8040 3.5.3)
* @retval 0 Invalid api_path or associated XML, clicon_err called * @param[in] yspec Yang spec
* @retval -1 Fatal error, clicon_err called * @param[out] xpath xpath (use free() to deallocate)
* @param[out] namespace Namespace of xpath (direct pointer don't free)
* @retval 1 OK
* @retval 0 Invalid api_path or associated XML, clicon_err called
* @retval -1 Fatal error, clicon_err called
* @code
* char *xpath = NULL;
* if ((ret = api_path2xpath("/module:a/b", yspec, &xpath, &namespace)) < 0)
* err;
* if (ret == 1)
* ... access xpath as cbuf_get(xpath)
* free(xpath)
* @endcode
* @see api_path2xml_cvv which uses other parameter formats
*/ */
int int
api_path2xpath(char *api_path, api_path2xpath(char *api_path,

View file

@ -159,13 +159,15 @@ nodetest_eval_node(cxobj *x,
else else
retval = strcmp(prefix1, prefix2) == 0; retval = strcmp(prefix1, prefix2) == 0;
} }
#if 0 /* debugging */
/* If retval == 0 here, then there is name match, but not ns match */ /* If retval == 0 here, then there is name match, but not ns match */
if (retval == 0){ if (retval == 0){
fprintf(stderr, "%s NOMATCH xml: (%s)%s\n\t\t xpath: (%s)%s\n", __FUNCTION__, fprintf(stderr, "%s NOMATCH xml: (%s)%s\n\t\t xpath: (%s)%s\n", __FUNCTION__,
name1, nsxml, name1, nsxml,
name2, nsxpath); name2, nsxpath);
} }
done: #endif
done: /* retval set in preceeding statement */
return retval; return retval;
} }