Exemplo n.º 1
0
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);
    }
}
Exemplo n.º 2
0
Bool load_config (const char *filename)
{
    int rc;
    XML_ITEM *config = NULL;
    XML_ITEM *root   = NULL;
    char fullname[FILE_NAME_MAX + 1];

    root = xml_create ("root", NULL);

    ASSERT (filename != NULL);
    ASSERT (strlen(filename) < FILE_NAME_MAX);
    default_extension (fullname, filename, "cfg");

    rc = xml_load_file (&root, ".", fullname, FALSE);

    if (rc != XML_NOERROR)
      {
        coprintf ("Error while loading \"%s\". Check file presence and consistence",
                   fullname);
        display_usage ();
        return FALSE;;
      }

    config = xml_first_child (root);
    ASSERT (config);

    /* default server is localhost */
    main_server =   mem_strdup (xml_get_attr (config, "smtp",    "127.0.0.1"));
    main_sender =   mem_strdup (xml_get_attr (config, "sender",  "admin@crjo"));
    main_dest   =   mem_strdup (xml_get_attr (config, "dest",    "user@crjo"));

    xml_free (root);

    return TRUE;
}
Exemplo n.º 3
0
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);
          }
Exemplo n.º 4
0
static xmlChar*
xml_first_child_content(xmlNodePtr root, const xmlChar *child)
{
	xmlNodePtr p = xml_first_child(root, child);
	if (p){
		return xmlNodeGetContent(p);
	}

	return NULL;
}
Exemplo n.º 5
0
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;
          }
      }
Exemplo n.º 6
0
static gint
parse_track_list_data(GString *data, GList **list)
{
	gint result = 1;
	xmlDocPtr doc = NULL;

	doc = xmlReadMemory(data->str, data->len, NULL, NULL,
				XML_PARSE_RECOVER | XML_PARSE_NOERROR);

	if (doc == NULL)
		return result;

	do
	{
		xmlNodePtr root;
		xmlNodePtr track_list;
		xmlNodePtr p;

		root = xmlDocGetRootElement(doc);
		if (root == NULL)
			break;

		track_list = xml_first_child(root, BAD_CAST "trackList");
		if (track_list == NULL)
			break;

		for(p = xmlFirstElementChild(track_list); p ; p = xmlNextElementSibling(p))
			get_track(p, list);

		result = 0;
	}
	while(0);

	xmlFreeDoc(doc);

	return result;
}
Exemplo n.º 7
0
static int
xml_save_file_item (FILE *xmlfile, XML_ITEM *item, int generation)
{
    int
        count = 1;                      /*  Count 1 for current item         */
    XML_ITEM
        *child,
        *sibling;
    XML_ATTR
        *attr;
    char
        *item_name,
        *attr_name,
        *ptr;
    Bool
        pretty;

    /*  First output item name and attributes                                */
    item_name  = xml_item_name  (item);
    if (item_name)
      {
        fprintf (xmlfile, "<%s", item_name);
        FORATTRIBUTES (attr, item)
          {
            attr_name  = xml_attr_name  (attr);
            ptr        = xml_attr_value (attr);
            http_encode_meta (token, &ptr, LINE_MAX, FALSE);
            fprintf (xmlfile, "\n%*s%s = \"%s", (generation + 1) * 4, "",
                                              attr_name, token);
            while (*ptr)
              {
                http_encode_meta (token, &ptr, LINE_MAX, FALSE);
                fprintf (xmlfile, "\n%s", token);
              }
            fprintf (xmlfile, "\"");
          }

        /*  If value or children exist, use long form, otherwise short form  */
        if ((child = xml_first_child (item)))
          {
            fprintf (xmlfile, ">");

            pretty = TRUE;
            for (sibling = child ;
                 sibling != NULL ;
                 sibling = xml_next_sibling (sibling))
                if (! xml_item_name (sibling))
                    pretty = FALSE;
                else
                    break;

            for ( ; child != NULL; child  = xml_next_sibling (child))
              {
                if (pretty)
                    fprintf (xmlfile, "\n%*s", (generation + 1) * 4, "");

                count += xml_save_file_item (xmlfile, child,
                                             generation + 1);

                if (xml_item_name (child))
                  {
                    pretty = TRUE;
                    for (sibling = xml_next_sibling (child) ;
                         sibling != NULL ;
                         sibling = xml_next_sibling (sibling))
                        if (! xml_item_name (sibling))
                            pretty = FALSE;
                        else
                            break;
                  }
              }
            
            if (pretty)
                fprintf (xmlfile, "\n%*s", generation * 4, "");

            fprintf (xmlfile, "</%s>", item_name);
          }
        else
            fprintf (xmlfile, "/>");
      }
Exemplo n.º 8
0
static int 
load_service_config (const char *binary_name)
{
    XML_ITEM 
        *root = NULL,
        *item,
        *child;
    int
        res = 0,
        rc;

    if (! file_exists (application_config))
      {
        log_printf ("ERROR: cannot find config file '%s'", application_config);
        return -1;
      }

    rc = xml_load_file (&root, NULL, application_config, FALSE);
    if (rc != XML_NOERROR)
      {
        log_printf ("ERROR: cannot load XML file '%s' (%s)", application_config, xml_error());
        return -1;
      }

    item = xml_first_child (root);
    if (item)
      {
        FORCHILDREN (child, item)
          {
            if (streq (xml_item_name(child), "service"))
              {
                service_name =  
                    mem_strdup (xml_get_attr (child, "name", NULL));
                service_display_name = 
                    mem_strdup (xml_get_attr (child, "display_name", NULL));
                service_trace_file =
                    mem_strdup (xml_get_attr (child, "trace_file", "smt_service.log"));
                service_debug = 
                    atoi (xml_get_attr(child, "debug", "0"));
                break;
              }
          }
      }

#if (defined(WIN32))
    /* service_name and service_display_name are only used with windows     */
    /* services, when registering or removing the service.                  */
    /* these fields are mandatory in Windows service configuration, but     */
    /* not used in UNIX daemons                                             */
    if (!service_name)
      {
        log_printf (
            "ERROR: item 'service_name' is missing in XML file '%s'", 
            application_config);
        res = -1;
      }
    if (!service_display_name)
      {
        log_printf (
            "ERROR: item 'service_text' is missing in XML file '%s'", 
            application_config);
        res = -1;
      }
#endif    

    xml_free (root);

    if (!res)
      {
        debug_printf ("Service configuration successfully loaded");
      }
    else
        free_resources ();

    return res;
}
Exemplo n.º 9
0
static gint
parse_login_status(XmrService *xs, GString *data, gchar **message)
{
	gboolean result = 1;
	xmlDocPtr doc = NULL;
	xmlNodePtr node = NULL;

	doc = xmlReadMemory(data->str, data->len, NULL, NULL,
				XML_PARSE_RECOVER | XML_PARSE_NOERROR);
	if (doc == NULL)
		return result;

	do
	{
		xmlNodePtr child;
		xmlChar *value;

		node = xmlDocGetRootElement(doc);
		if (node == NULL)
			break;

		if (message)
		{
			child = xml_first_child(node, BAD_CAST "message");
			if (child)
			{
				value = xmlNodeGetContent(child);
				*message = (gchar *)value;
			}
		}

		child = xml_first_child(node, BAD_CAST "status");
		if (child == NULL)
			break;

		value = xmlNodeGetContent(child);
		if (value == NULL)
			break;
		 
		result = g_strtod((gchar *)value, NULL);
		xmlFree(value);

		// get user info
		if (result == 0)
		{
			node = xml_first_child(node, BAD_CAST "user");
			if (node == NULL)
				break;

			value = xml_first_child_content(node, BAD_CAST "user_id");
			if (value)
			{
				g_object_set(xs, "usr-id", value, NULL);
				xmlFree(value);
			}

			value = xml_first_child_content(node, BAD_CAST "nick_name");
			if (value)
			{
				g_object_set(xs, "usr-name", value, NULL);
				xmlFree(value);
			}
		}
		 
	}
	while(0);

	xmlFreeDoc(doc);

	return result;
}
Exemplo n.º 10
0
static int
eval_count (int argc, SCRIPT_NODE **argv, SCRIPT_NODE *result)
{
    long
        item,
        n;
    SCRIPT_NODE
        *identifier = argc > 0 ? argv [0] : NULL,
        *condition  = argc > 1 ? argv [1] : NULL;
    char
        *name,
        *xml_name;
    SCOPE_BLOCK
        *for_block;
    SCOPE_ITEM
        *scope_item;
    XML_ITEM
        *from_xml,
        *xml_item;
    Bool
        error = FALSE;

    if (identifier-> type == GG_SYMBOL)
      {
        if ((evaluate_script_node (identifier-> op1) != 0)
        ||  (evaluate_script_node (identifier-> op2) != 0))
            return -1;

	from_xml = lookup_from_xml (identifier-> op1);
	if (! from_xml)
            return -1;
        name  = (identifier-> op2) ? string_result (identifier-> op2) : NULL;
      }
    else
      {
        gg_report_error ('E', "Function argument must be an identifier.");
        return -1;
      }

    n = 0;
    if (from_xml)
      {
        for_block = create_scope_block ("count");
        for_block-> children = TRUE;
        xml_item = xml_first_child (from_xml);
        item = 0;
        while (xml_item)
          {
            while (xml_item)
              {
                xml_name = xml_item_name (xml_item);
                if (xml_name && name)
                  {
                    if (ignorecase)
                      {
                        if (lexcmp (xml_name, name) == 0)
                            break;
                      }
                    else
                      {
                        if (streq (xml_name, name))
                            break;
                      }
                  }
                else
                    /*  Take all named children; others are part of value  */
                    if (xml_name && (! name))
                        break;

                xml_item = xml_next_sibling (xml_item);
              }
            item++;
            
            if (xml_item)
              {
                if (condition)
                  {
                    scope_item = create_scope_item (for_block, xml_item, item);
                    for_block-> scope_item = scope_item;
                    for_block-> xml_item   = xml_item;
                    if (evaluate_script (condition) != 0)
                      {
                        error = TRUE;
                        break;
                      }
                    number_result (condition);
                    if ((condition-> result_type == TYPE_NUMBER)
                    &&  (condition-> result_n    != 0))
                        n++;
                    gg_clean (condition);
                  }
                else
                    n++;
                
                xml_item = xml_next_sibling (xml_item);
              }
          }
        destroy_scope_block ();
    
        if (error)
            return -1;
      }

    result-> result_type = TYPE_NUMBER;
    result-> result_n    = n;
    return 0;
}