Пример #1
0
static int
eval_name (int argc, SCRIPT_NODE **argv, SCRIPT_NODE *result)
{
    SCOPE_BLOCK
        *scope_block;
    SCRIPT_NODE
        *scope = argc > 0 ? argv [0] : NULL;

    scope_block = lookup_data_scope_from_parameter (scope);
    if (! scope_block)
        return -1;

    if ((scope_block-> xml_item)
    &&  (xml_item_name (scope_block-> xml_item)))
      {
        result-> result_type = TYPE_STRING;
        result-> result_s    = mem_strdup (
                                   xml_item_name (scope_block-> xml_item));
      }
    else
        result-> result_type = TYPE_UNDEFINED;

    return 0;
}
Пример #2
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, "/>");
      }
Пример #3
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;
}
Пример #4
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;
}