예제 #1
0
파일: run.c 프로젝트: csesteban/ccan
int main(void)
{
	XmlNode *x, *t;
	/* This is how many tests you plan to run */
	plan_tests(12);

	ok1(x = xml_load("./test/test.xml1"));
	ok1(!xml_find(x, "Doesn't Exist"));
	ok1(t = xml_find(x, "one"));
	ok1(xml_find(t, "two"));
	ok1(!xml_attr(t, "foobar"));
	ok1(!xml_attr(t, "Doesn't Exist"));
	ok1(xml_attr(t, "barfoo"));
	xml_free(x);
	/* Simple thing we expect to succeed */
	ok1(!test_load("does not exist")); /* A file that doesn't exist */
	ok1(test_load("./test/test.xml1")); /* A basic xml file. */
	ok1(test_load("./test/test.xml2")); /* Very small well-formed xml file. */
	ok1(test_load("./test/test.xml3")); /* Smallest well-formed xml file. */
	ok1(test_load("./test/test.xml4")); /* A single unclosed tag. */
	/* Same, with an explicit description of the test. */
//	ok(some_test(), "%s with no args should return 1", "some_test")
	/* How to print out messages for debugging. */
//	diag("Address of some_test is %p", &some_test)
	/* Conditional tests must be explicitly skipped. */

	/* This exits depending on whether all tests passed */
	return exit_status();
}
예제 #2
0
파일: smtpipe.c 프로젝트: cookrn/openamq
MODULE create_transfer_pipes (THREAD *thread)
{
    XML_ITEM
        *pipe,                          /*  XML pipe item                    */
        *instance;                      /*  XML instance item                */
    XML_ATTR
        *attr;                          /*  XML attribute                    */
    char
        *pipe_name;
    qbyte
        inrate,                         /*  Pipe input rate                  */
        outrate,                        /*  Pipe output rate                 */
        units;                          /*  Transfer rate multiplier         */

    FORCHILDREN (pipe, xml_first_child (pipes))
      {
        pipe_name = xml_get_attr (pipe, "NAME", NULL);
        if (!pipe_name)
          {
            send_smtoper_error (&operq,
                                strprintf ("smtpipe: syntax error in '%s' - no NAME", 
                                           filename));
            continue;
          }

        inrate  = atol (xml_get_attr (pipe, "INRATE",  "0"));
        outrate = atol (xml_get_attr (pipe, "OUTRATE", "0"));
        if (inrate  == 0)
            inrate  = atol (xml_get_attr (pipe, "RATE", "0"));
        if (outrate == 0)
            outrate = atol (xml_get_attr (pipe, "RATE", "0"));

        if (inrate == 0 || outrate == 0)
          {
            send_smtoper_error (&operq,
                                strprintf ("smtpipe: pipe '%s' badly defined",
                                           pipe_name));
            continue;
          }
        units    = atol (xml_get_attr (pipe, "UNITS", "1"));
        inrate  *= units;
        outrate *= units;

        /*  Create each pipe instance that is defined                        */
        FORCHILDREN (instance, pipe)
          {
            attr = xml_attr (instance, "NAME");
            if (attr == NULL)
              {
                send_smtoper_error (&operq,
                                    strprintf ("smtpipe: pipe '%s' instance has no name", 
                                               pipe_name));
                continue;
              }
            send_smttran_pipe_create (&tranq,
                                      xml_attr_value (attr),
                                      inrate, 
                                      outrate);
          }
예제 #3
0
bool_t console_stdio_load(char * file)
{
	struct xml * root;
	struct xml * in, * out, * err;

	root = xml_parse_file(file);
	if(!root || !root->name)
		return FALSE;

	if(strcmp(root->name, "console") != 0)
	{
		xml_free(root);
		return FALSE;
	}

	in = xml_get(root, "stdin", -1);
	if(! in)
	{
		xml_free(root);
		return FALSE;
	}

	out = xml_get(root, "stdout", -1);
	if(! out)
	{
		xml_free(root);
		return FALSE;
	}

	err = xml_get(root, "stderr", -1);
	if(! err)
	{
		xml_free(root);
		return FALSE;
	}

	if(! console_stdio_set(xml_attr(in, "name"), xml_attr(out, "name"), xml_attr(err, "name")))
	{
		xml_free(root);
		return FALSE;
	}

	xml_free(root);
	return TRUE;
}
예제 #4
0
파일: nesc-xml.c 프로젝트: tinyprod/nesc
void nxml_tdecl_ref(tag_declaration tdecl)
{
    char tag[20];

    xml_list_add(xl_tags, tdecl);
    sprintf(tag, "%s-ref", tagkind_name(tdecl->kind));
    xml_tag_start(tag);
    if (tdecl->name)
        xml_attr("name", tdecl->name);
    xml_attr_bool("scoped", !!tdecl->container/* || tdecl->container_function*/);
    xml_attr_ptr("ref", tdecl);
    xml_tag_end_pop();
}
예제 #5
0
파일: nesc-xml.c 프로젝트: tinyprod/nesc
void nxml_ndecl_ref(nesc_declaration ndecl)
{
    if (ndecl->kind == l_interface)
    {
        xml_tag_start("interfacedef-ref");
        xml_list_add(xl_interfacedefs, ndecl);
    }
    else
    {
        xml_list_add(xl_components, ndecl);
        xml_tag_start("component-ref");
    }
    xml_attr("qname", ndecl->instance_name);
    //xml_attr_ptr("ref", ndecl);
    xml_tag_end_pop();
}
예제 #6
0
파일: nesc-xml.c 프로젝트: tinyprod/nesc
static void nxml_value_structured(ivalue value)
{
    ivalue_field field;

    indentedtag("value-structured");
    nxml_type(value->type);
    for (field = value->u.structured; field; field = field->next)
    {
        indentedtag_start("structured-element");
        xml_attr("field", field->field->name);
        xml_attr_ptr("ref", field->field);
        xml_tag_end();
        nxml_value(field->value);
        indentedtag_pop();
    }
    indentedtag_pop();
}
예제 #7
0
파일: xml.cpp 프로젝트: 2202877/acl
const xml_attr* xml_node::first_attr(void) const
{
	ACL_ARRAY* a = node_->attr_list;
	if (a == NULL)
		return NULL;

	if (attr_iter_ == NULL)
		const_cast<xml_node*>(this)->attr_iter_ =
			(ACL_ITER*) acl_mymalloc(sizeof(ACL_ITER));

	ACL_XML_ATTR* attr = (ACL_XML_ATTR*) a->iter_head(attr_iter_, a);
	if (attr == NULL)
		return NULL;
	if (attr_ == NULL)
		const_cast<xml_node*>(this)->attr_ = NEW xml_attr();
	const_cast<xml_node*>(this)->attr_->node_ = const_cast<xml_node*>(this);
	const_cast<xml_node*>(this)->attr_->attr_ = attr;
	return attr_;
}
예제 #8
0
파일: xml.cpp 프로젝트: neland/acl
const xml_attr* xml_node::next_attr(void) const
{
	ACL_ARRAY* a = node_->attr_list;
	if (a == NULL)
		return NULL;

	acl_assert(attr_iter_);

	ACL_XML_ATTR* attr = (ACL_XML_ATTR*) a->iter_next(attr_iter_, a);
	if (attr == NULL)
		return NULL;

	xml_attr* xa = NEW xml_attr();
	xa->node_ = const_cast<xml_node*>(this);
	xa->attr_ = attr;

	const_cast<xml_node*>(this)->attrs_tmp_.push_back(xa);
	return xa;
}
예제 #9
0
파일: nesc-xml.c 프로젝트: tinyprod/nesc
void nxml_ddecl_ref(data_declaration ddecl)
{
    xml_list l = NULL;

    switch (ddecl->kind)
    {
    case decl_variable:
        xml_tag_start("variable-ref");
        l = xl_variables;
        break;
    case decl_constant:
        xml_tag_start("constant-ref");
        l = xl_constants;
        break;
    case decl_function:
        xml_tag_start("function-ref");
        l = xl_functions;
        break;
    case decl_typedef:
        xml_tag_start("typedef-ref");
        l = xl_typedefs;
        break;
    case decl_interface_ref:
        xml_tag_start("interface-ref");
        l = xl_interfaces;
        break;
    case decl_component_ref:
        xml_tag_start("internal-component-ref");
        l = xl_icomponents;
        break;
    default:
        assert(0);
    }
    xml_list_add(l, ddecl);
    xml_attr("name", ddecl->name);
    if (ddecl->container || ddecl->container_function)
        xml_attr_noval("scoped");
    xml_attr_ptr("ref", ddecl);
    xml_tag_end_pop();
}
예제 #10
0
파일: xiddns.c 프로젝트: imatix/Xitami-25
MODULE get_next_ddns_profile (THREAD *thread)
{
    char
        ddns_prefix [10];               /*  "ddns.." config table prefix     */
    XML_ATTR
        *attr;                          /*  XML attribute                    */

    /*  If we have a symbol with the name ddns... then we can assume that
     *  this is the start of a DDNS entry.
     */
    sprintf (ddns_prefix, "ddns%.0d", ddns_index++);
    ddns_service = ini_dyn_value (config, ddns_prefix, "service", NULL);

    if (ddns_service)
      {
        the_next_event = ok_event;
        ddns_username = ini_dyn_value (config, ddns_prefix, "username", "");
        ddns_password = ini_dyn_value (config, ddns_prefix, "password", "");
        ddns_domain   = ini_dyn_value (config, ddns_prefix, "domain",   "");

        /*  Now find service properties                                      */
        FORCHILDREN (service_item, xml_first_child (services))
          {
            attr = xml_attr (service_item, "NAME");
            if (attr == NULL)
                sendfmt (&operq, "ERROR",
                         "xiddns: syntax error in definition file - no NAME");
            else
            if (streq (ddns_service, xml_attr_value (attr)))
                break;
           }
        if (service_item == NULL)
          {
            sendfmt (&operq, "ERROR",
                     "xiddns: service '%s' not defined", ddns_service);
            the_next_event = error_event;
          }
      }
예제 #11
0
static void xml_start_element( GMarkupParseContext *ctx, const gchar *element_name, const gchar **attr_names, const gchar **attr_values, gpointer data, GError **error )
{
	struct xml_parsedata *xd = data;
	irc_t *irc = xd->irc;
	
	if( xd->unknown_tag > 0 )
	{
		xd->unknown_tag ++;
	}
	else if( g_strcasecmp( element_name, "user" ) == 0 )
	{
		char *nick = xml_attr( attr_names, attr_values, "nick" );
		char *pass = xml_attr( attr_names, attr_values, "password" );
		int st;
		
		if( !nick || !pass )
		{
			g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
			             "Missing attributes for %s element", element_name );
		}
		else if( ( st = md5_verify_password( xd->given_pass, pass ) ) == -1 )
		{
			xd->pass_st = XML_PASS_WRONG;
			g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
			             "Error while decoding password attribute" );
		}
		else if( st == 0 )
		{
			if( xd->pass_st != XML_PASS_CHECK_ONLY )
				xd->pass_st = XML_PASS_OK;
		}
		else
		{
			xd->pass_st = XML_PASS_WRONG;
			g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
			             "Password mismatch" );
		}
	}
	else if( xd->pass_st < XML_PASS_OK )
	{
		/* Let's not parse anything else if we only have to check
		   the password. */
	}
	else if( g_strcasecmp( element_name, "account" ) == 0 )
	{
		char *protocol, *handle, *server, *password = NULL, *autoconnect, *tag;
		char *pass_b64 = NULL;
		unsigned char *pass_cr = NULL;
		int pass_len;
		struct prpl *prpl = NULL;
		
		handle = xml_attr( attr_names, attr_values, "handle" );
		pass_b64 = xml_attr( attr_names, attr_values, "password" );
		server = xml_attr( attr_names, attr_values, "server" );
		autoconnect = xml_attr( attr_names, attr_values, "autoconnect" );
		tag = xml_attr( attr_names, attr_values, "tag" );
		
		protocol = xml_attr( attr_names, attr_values, "protocol" );
		if( protocol )
			prpl = find_protocol( protocol );
		
		if( !handle || !pass_b64 || !protocol )
			g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
			             "Missing attributes for %s element", element_name );
		else if( !prpl )
			g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
			             "Unknown protocol: %s", protocol );
		else if( ( pass_len = base64_decode( pass_b64, (unsigned char**) &pass_cr ) ) &&
		         arc_decode( pass_cr, pass_len, &password, xd->given_pass ) >= 0 )
		{
			xd->current_account = account_add( irc->b, prpl, handle, password );
			if( server )
				set_setstr( &xd->current_account->set, "server", server );
			if( autoconnect )
				set_setstr( &xd->current_account->set, "auto_connect", autoconnect );
			if( tag )
				set_setstr( &xd->current_account->set, "tag", tag );
		}
		else
		{
			/* Actually the _decode functions don't even return error codes,
			   but maybe they will later... */
			g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
			             "Error while decrypting account password" );
		}
		
		g_free( pass_cr );
		g_free( password );
	}
	else if( g_strcasecmp( element_name, "setting" ) == 0 )
	{
		char *setting;
		
		if( xd->current_setting )
		{
			g_free( xd->current_setting );
			xd->current_setting = NULL;
		}
		
		if( ( setting = xml_attr( attr_names, attr_values, "name" ) ) )
		{
			if( xd->current_channel != NULL )
				xd->current_set_head = &xd->current_channel->set;
			else if( xd->current_account != NULL )
				xd->current_set_head = &xd->current_account->set;
			else
				xd->current_set_head = &xd->irc->b->set;
			
			xd->current_setting = g_strdup( setting );
		}
		else
			g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
			             "Missing attributes for %s element", element_name );
	}
	else if( g_strcasecmp( element_name, "buddy" ) == 0 )
	{
		char *handle, *nick;
		
		handle = xml_attr( attr_names, attr_values, "handle" );
		nick = xml_attr( attr_names, attr_values, "nick" );
		
		if( xd->current_account && handle && nick )
		{
			nick_set_raw( xd->current_account, handle, nick );
		}
		else
		{
			g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
			             "Missing attributes for %s element", element_name );
		}
	}
	else if( g_strcasecmp( element_name, "channel" ) == 0 )
	{
		char *name, *type;
		
		name = xml_attr( attr_names, attr_values, "name" );
		type = xml_attr( attr_names, attr_values, "type" );
		
		if( !name || !type )
		{
			g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
			             "Missing attributes for %s element", element_name );
			return;
		}
		
		/* The channel may exist already, for example if it's &bitlbee.
		   Also, it's possible that the user just reconnected and the
		   IRC client already rejoined all channels it was in. They
		   should still get the right settings. */
		if( ( xd->current_channel = irc_channel_by_name( irc, name ) ) ||
		    ( xd->current_channel = irc_channel_new( irc, name ) ) )
			set_setstr(&xd->current_channel->set, "type", type );
	}
	/* Backward compatibility: Keep this around for a while for people
	   switching from BitlBee 1.2.4+. */
	else if( g_strcasecmp( element_name, "chat" ) == 0 )
	{
		char *handle, *channel;
		
		handle = xml_attr( attr_names, attr_values, "handle" );
		channel = xml_attr( attr_names, attr_values, "channel" );
		
		if( xd->current_account && handle && channel )
		{
			irc_channel_t *ic;
			
			if( ( ic = irc_channel_new( irc, channel ) ) &&
			    set_setstr( &ic->set, "type", "chat" ) &&
			    set_setstr( &ic->set, "chat_type", "room" ) &&
			    set_setstr( &ic->set, "account", xd->current_account->tag ) &&
			    set_setstr( &ic->set, "room", handle ) )
			{
				/* Try to pick up some settings where possible. */
				xd->current_channel = ic;
			}
			else if( ic )
				irc_channel_free( ic );
		}
		else
		{
			g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
			             "Missing attributes for %s element", element_name );
		}
	}
	else
	{
		xd->unknown_tag ++;
		irc_rootmsg( irc, "Warning: Unknown XML tag found in configuration file (%s). "
		                  "This may happen when downgrading BitlBee versions. "
		                  "This tag will be skipped and the information will be lost "
		                  "once you save your settings.", element_name );
		/*
		g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT,
		             "Unkown element: %s", element_name );
		*/
	}
}