本文整理汇总了C++中xml_free函数的典型用法代码示例。如果您正苦于以下问题:C++ xml_free函数的具体用法?C++ xml_free怎么用?C++ xml_free使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xml_free函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadenv
/*
* load environment variable
*/
bool_t loadenv(char * file)
{
struct xml * root, * env;
root = xml_parse_file(file);
if(!root || !root->name)
return FALSE;
if(strcmp(root->name, "environment") != 0)
{
xml_free(root);
return FALSE;
}
clearenv();
for(env = xml_child(root, "env"); env; env = env->next)
{
if(env->txt)
putenv(env->txt);
}
xml_free(root);
return TRUE;
}
示例2: fprintf
xml_node *xml_parse( const char *filename ) {
int done = 0;
FILE *xptr;
XML_Parser p;
static char buf[BUFSIZE];
xml_node root, *ret;
if( (xptr = fopen( filename, "r" )) == NULL ) {
fprintf( stderr, "Unable to open file: %s\n", filename );
return NULL;
}
root.child = NULL;
if( (ret = xml_alloc(&root)) == NULL ) {
fclose( xptr );
fprintf( stderr, "Out of memory\n" );
return NULL;
}
if( (p = XML_ParserCreate( NULL )) == NULL ) {
fclose( xptr );
fprintf( stderr, "Out of memory\n" );
return NULL;
}
XML_SetUserData( p, &ret );
XML_SetElementHandler( p, xml_el_start, xml_el_end );
XML_SetCharacterDataHandler( p, xml_charhndl );
while( !done ) {
int len;
len = fread( buf, 1, BUFSIZE, xptr );
if( ferror( xptr ) ) {
fprintf( stderr, "Read error\n" );
xml_free( ret );
ret = NULL;
break;
}
done = feof( xptr );
if( XML_Parse(p, buf, len, done) == 0 ) {
fprintf( stderr, "Parse error at line %d:\n%s\n",
(int) XML_GetCurrentLineNumber(p),
XML_ErrorString( XML_GetErrorCode(p) ) );
xml_free( ret );
ret = NULL;
break;
}
}
if( ret != NULL )
ret->parent = NULL;
fclose( xptr );
XML_ParserFree( p );
return ret;
}
示例3: xml_free
/* free a previously allocated XmlNode */
void xml_free(XmlNode *target)
{
int i;
for(i=0; i<target->nattrib*2; i++)
if(target->attrib[i])
free(target->attrib[i]);
if(target->attrib)free(target->attrib);
if(target->child)xml_free(target->child);
if(target->next)xml_free(target->next);
free(target->name);
free(target);
}
示例4: clicon_rpc_create_subscription
/*! Create a new notification subscription
* @param[in] h Clicon handle
* @param{in] stream name of notificatio/log stream (CLICON is predefined)
* @param{in] filter message filter, eg xpath for xml notifications
* @param[out] s0 socket returned where notification mesages will appear
* @retval 0 OK
* @retval -1 Error and logged to syslog
* @note When using netconf create-subsrciption,status and format is not supported
*/
int
clicon_rpc_create_subscription(clicon_handle h,
char *stream,
char *filter,
int *s0)
{
int retval = -1;
struct clicon_msg *msg = NULL;
cxobj *xret = NULL;
cxobj *xerr;
char *username;
username = clicon_username_get(h);
if ((msg = clicon_msg_encode("<rpc username=\"%s\"><create-subscription xmlns=\"urn:ietf:params:xml:ns:netmod:notification\">"
"<stream>%s</stream>"
"<filter type=\"xpath\" select=\"%s\" />"
"</create-subscription></rpc>",
username?username:"",
stream?stream:"", filter?filter:"")) == NULL)
goto done;
if (clicon_rpc_msg(h, msg, &xret, s0) < 0)
goto done;
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
clicon_rpc_generate_error("Create subscription", xerr);
goto done;
}
retval = 0;
done:
if (xret)
xml_free(xret);
if (msg)
free(msg);
return retval;
}
示例5: clicon_rpc_debug
/*! Send a debug request to backend server
* @param[in] h CLICON handle
* @param[in] level Debug level
* @retval 0 OK
* @retval -1 Error and logged to syslog
*/
int
clicon_rpc_debug(clicon_handle h,
int level)
{
int retval = -1;
struct clicon_msg *msg = NULL;
cxobj *xret = NULL;
cxobj *xerr;
char *username;
username = clicon_username_get(h);
/* XXX: hardcoded example yang, should be clixon-config!!! */
if ((msg = clicon_msg_encode("<rpc username=\"%s\"><debug xmlns=\"http://clicon.org/lib\"><level>%d</level></debug></rpc>", username?username:"", level)) == NULL)
goto done;
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
goto done;
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
clicon_rpc_generate_error("Debug",xerr);
goto done;
}
if (xpath_first(xret, "//rpc-reply/ok") == NULL){
clicon_err(OE_XML, 0, "rpc error"); /* XXX extract info from rpc-error */
goto done;
}
retval = 0;
done:
if (msg)
free(msg);
if (xret)
xml_free(xret);
return retval;
}
示例6: clicon_rpc_commit
/*! Commit changes send a commit request to backend daemon
* @param[in] h CLICON handle
* @retval 0 OK
* @retval -1 Error and logged to syslog
*/
int
clicon_rpc_commit(clicon_handle h)
{
int retval = -1;
struct clicon_msg *msg = NULL;
cxobj *xret = NULL;
cxobj *xerr;
char *username;
username = clicon_username_get(h);
if ((msg = clicon_msg_encode("<rpc username=\"%s\"><commit/></rpc>", username?username:"")) == NULL)
goto done;
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
goto done;
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
clicon_rpc_generate_error(CLIXON_ERRSTR_COMMIT_FAILED, xerr);
goto done;
}
retval = 0;
done:
if (xret)
xml_free(xret);
if (msg)
free(msg);
return retval;
}
示例7: clicon_rpc_discard_changes
/*! Discard all changes in candidate / revert to running
* @param[in] h CLICON handle
* @retval 0 OK
* @retval -1 Error and logged to syslog
*/
int
clicon_rpc_discard_changes(clicon_handle h)
{
int retval = -1;
struct clicon_msg *msg = NULL;
cxobj *xret = NULL;
cxobj *xerr;
char *username;
username = clicon_username_get(h);
if ((msg = clicon_msg_encode("<rpc username=\"%s\"><discard-changes/></rpc>", username?username:"")) == NULL)
goto done;
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
goto done;
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
clicon_rpc_generate_error("Discard changes", xerr);
goto done;
}
retval = 0;
done:
if (xret)
xml_free(xret);
if (msg)
free(msg);
return retval;
}
示例8: clicon_rpc_kill_session
/*! Kill other user sessions
* @param[in] h CLICON handle
* @param[in] session_id Session id of other user session
* @retval 0 OK
* @retval -1 Error and logged to syslog
*/
int
clicon_rpc_kill_session(clicon_handle h,
int session_id)
{
int retval = -1;
struct clicon_msg *msg = NULL;
cxobj *xret = NULL;
cxobj *xerr;
char *username;
username = clicon_username_get(h);
if ((msg = clicon_msg_encode("<rpc username=\"%s\"><kill-session><session-id>%d</session-id></kill-session></rpc>",
username?username:"", session_id)) == NULL)
goto done;
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
goto done;
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
clicon_rpc_generate_error("Kill session", xerr);
goto done;
}
retval = 0;
done:
if (xret)
xml_free(xret);
if (msg)
free(msg);
return retval;
}
示例9: clicon_rpc_validate
/*! Send validate request to backend daemon
* @param[in] h CLICON handle
* @param[in] db Name of database
* @retval 0 OK
* @retval -1 Error and logged to syslog
*/
int
clicon_rpc_validate(clicon_handle h,
char *db)
{
int retval = -1;
struct clicon_msg *msg = NULL;
cxobj *xret = NULL;
cxobj *xerr;
char *username;
username = clicon_username_get(h);
if ((msg = clicon_msg_encode("<rpc username=\"%s\"><validate><source><%s/></source></validate></rpc>", username?username:"", db)) == NULL)
goto done;
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
goto done;
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
clicon_rpc_generate_error(CLIXON_ERRSTR_VALIDATE_FAILED, xerr);
goto done;
}
retval = 0;
done:
if (msg)
free(msg);
if (xret)
xml_free(xret);
return retval;
}
示例10: clicon_rpc_unlock
/*! Unlock a database
* @param[in] h CLICON handle
* @param[in] db database, eg "running"
* @retval 0 OK
* @retval -1 Error and logged to syslog
*/
int
clicon_rpc_unlock(clicon_handle h,
char *db)
{
int retval = -1;
struct clicon_msg *msg = NULL;
cxobj *xret = NULL;
cxobj *xerr;
char *username;
username = clicon_username_get(h);
if ((msg = clicon_msg_encode("<rpc username=\"%s\"><unlock><target><%s/></target></unlock></rpc>", username?username:"", db)) == NULL)
goto done;
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
goto done;
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
clicon_rpc_generate_error("Configuration unlock", xerr);
goto done;
}
retval = 0;
done:
if (xret)
xml_free(xret);
if (msg)
free(msg);
return retval;
}
示例11: clicon_rpc_delete_config
/*! Send a request to backend to delete a config database
* @param[in] h CLICON handle
* @param[in] db database, eg "running"
* @retval 0 OK
* @retval -1 Error and logged to syslog
* @code
* if (clicon_rpc_delete_config(h, "startup") < 0)
* err;
* @endcode
*/
int
clicon_rpc_delete_config(clicon_handle h,
char *db)
{
int retval = -1;
struct clicon_msg *msg = NULL;
cxobj *xret = NULL;
cxobj *xerr;
char *username;
username = clicon_username_get(h);
if ((msg = clicon_msg_encode("<rpc username=\"%s\"><edit-config><target><%s/></target><default-operation>none</default-operation><config operation=\"delete\"/></edit-config></rpc>",
username?username:"", db)) == NULL)
goto done;
if (clicon_rpc_msg(h, msg, &xret, NULL) < 0)
goto done;
if ((xerr = xpath_first(xret, "//rpc-error")) != NULL){
clicon_rpc_generate_error("Deleting configuration", xerr);
goto done;
}
retval = 0;
done:
if (xret)
xml_free(xret);
if (msg)
free(msg);
return retval;
}
示例12: free_switches_structure
MODULE free_switches_structure (void)
{
if (xml_switches)
xml_free (xml_switches);
xml_switches = NULL;
}
示例13: xml_el_start
void xml_el_start( void *data, const char *name, const char **attr ) {
int i, nattr = 1;
xml_node *node = xml_alloc( *((xml_node **) data) );
if( node == NULL ) {
fprintf( stderr, "Out of memory\n" );
return;
}
node->key = strdup( name );
for( i=0;attr[i];i++ )
nattr++;
if( (node->attr = (char **) malloc( sizeof( char * ) *nattr )) == NULL ) {
fprintf( stderr, "Out of memory\n" );
xml_free( node );
return;
}
for( i=0;attr[i];i++ ) {
node->attr[i] = strdup( attr[i] );
//printf("ATTR: %s\n", attr[i]);
}
node->attr[i] = NULL;
*((xml_node **) data) = node;
}
示例14: fopen
char *test_read_input()
{
FILE *f;
/* open, read and parse some invalid xml */
f = fopen("test.invalid.xml", "r");
mu_assert("read invalid xml", read_input(f) == 0);
fclose(f);
mu_assert("parse invalid xml", xml_parse(buf) == XML_STATUS_INVALID);
/* open, read and parse some valid xml */
f = fopen("test.xml", "r");
mu_assert("read valid xml", read_input(f) == 0);
fclose(f);
mu_assert("buffer contains request", strncmp(buf,"<request>", 9) == 0);
mu_assert("parse some valid xml", xml_parse(buf) == XML_STATUS_OK);
/* fetch value of an element */
char *value = xml_element("//username");
mu_assert("perform xpath search for element", value != NULL);
mu_assert("get value of xml element", strcmp(value, "iamauser") == 0);
xml_free(value);
xml_cleanup();
return 0;
}
示例15: prepare_xml_file
void
prepare_xml_file (char *filename)
{
int
rc;
rc = xml_load_file (& xml_root, PATH, filename, FALSE);
if (rc == XML_NOERROR)
{
xml_source = xml_first_child (xml_root);
if (xml_source)
{
xml_put_attr (xml_switches, "filename", filename);
xml_put_attr (xml_switches, "template", "1");
}
else
xml_free (xml_root);
}
else
{
coprintf ("%s E: Error processing %s...", me, filename);
coprintf (xml_error ());
raise_exception (anomaly_event);
}
}