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; }
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); }
void test_output() { xml_body_ptr body = NULL; xml_table_ptr table = NULL; xml_item_ptr item = NULL; xml_item_attr_ptr attr = NULL; xml_handel handel = NULL; char *buf; int len, i, t_cnt = 1; printf("\n*** test_output ***\n"); /* new body with [t_cnt] tables */ body = xml_body_new(t_cnt); for ( i = 0; i < t_cnt; i++ ) { /* init every table with 1 item, each item 1 attribute */ xml_table_init(body->t_list + i, 1, 1); } /* init xml_body here */ body->unit_code = xml_strdup(body, "场所编码"); table = xml_get_table(body, 0); /* init xml_table[0] here */ table->name = xml_strdup(body, "记录集名称"); item = xml_get_item(table, 0); attr = xml_get_attr(item, 0); /* init xml_item[0].attr[0] */ attr->name = xml_strdup(body, "item1"); attr->value = xml_strdup(body, "值1"); /* get xml buffer */ handel = xml_output(body, &buf, &len); printf("%s", buf); /* clean xml buffer */ xml_output_clean(handel); /* clean body */ xml_body_clean(body); }
void xml_walk_tree(xmlNode * a_node, char *url, OMS_PAGE *p) { xmlNode *cur_node = NULL; xmlNode *ch_node = NULL; xmlAttr *cur_attr = NULL; char *i; int j; for (cur_node = a_node; cur_node; cur_node = cur_node->next) { if (cur_node->type == XML_ELEMENT_NODE) { //printf("Tag: %s\n", cur_node->name); char *l, *link, *name; switch(xml_get_tag_id(cur_node->name)) { case HTML_TAG_HTML: case HTML_TAG_HEAD: break; case HTML_TAG_TITLE: name = "Page title"; ch_node = xml_find_text_node(cur_node); if (ch_node) { // Dirty hack ch_node->extra = XML_TEXT_MAGIC; oms_add_plus(p); oms_add_text(p, ch_node->content); } break; case HTML_TAG_BODY: l = xml_get_attr(cur_node, "bgcolor"); if (l) oms_add_bgcolor(p, l); l = xml_get_attr(cur_node, "text"); if (l) oms_add_textcolor(p, l); break; case HTML_TAG_BR: oms_add_break(p); break; case HTML_TAG_P: oms_add_paragraph(p); break; case HTML_TAG_A: //printf("z"); l = xml_get_attr(cur_node, "href"); if (l != 0) { link = malloc(strlen(l) + 10 + strlen(url)); if(!strstr(l, "://")) // Нет протокола -> ссылка неполная (не всегда так, но пох) { if (l[0] == '/') // Путь от корня сайта i = strchr(url+7, '/'); else // Относительно текущей директории { i = strrchr(url, '/'); if (i == (url+6)) // А нету в конце слеша i = NULL; } if (i != NULL) *i = 0; sprintf(link, "0/%s/%s", url, l); if (i != NULL) *i = '/'; } else sprintf(link, "0/%s", l); } else { link = strcpy(malloc(12), "error:link"); } name = "Link"; //printf("e"); ch_node = xml_find_text_node(cur_node); if (ch_node) { // Dirty hack ch_node->extra = XML_TEXT_MAGIC; name = ch_node->content; } oms_add_link(p, link, name); free(link); //printf("q"); break; case HTML_TAG_IMG: oms_add_text(p, "[Img]"); break; case HTML_TAG_FORM: link = xml_get_attr(cur_node, "action"); oms_add_form(p, link); break; case HTML_TAG_TEXTAREA: // HACK for google.com and similar name = xml_get_attr(cur_node, "style"); if (!name || !strstr(name, "display:none")) { name = xml_get_attr(cur_node, "name"); if (!name) name = "dname"; link = xml_get_attr(cur_node, "value"); if (!link) link = ""; oms_add_text_input(p, name, link); } break; case HTML_TAG_INPUT: l = xml_get_attr(cur_node, "type"); if (!l) l = "text"; name = xml_get_attr(cur_node, "name"); if (!name) name = "dname"; link = xml_get_attr(cur_node, "value"); if (!link) link = ""; if (!SCMP(l, "text")) oms_add_text_input(p, name, link); else if (!SCMP(l, "password")) oms_add_pass_input(p, name, link); else if (!SCMP(l, "submit")) oms_add_submit(p, name, link); else if (!SCMP(l, "checkbox")) { link = xml_get_attr(cur_node, "checked"); j = 0; if (link && (!SCMP(link, "true"))) j = 1; oms_add_checkbox(p, name, 1); } break; default: break; } /* for (cur_attr = cur_node->properties; cur_attr; cur_attr = cur_attr->next) { if (cur_attr->type == XML_ATTRIBUTE_NODE) { printf("Attribute %s, value %s\n", cur_attr->name, cur_attr->children->content); } }*/ } else if ((cur_node->type == XML_TEXT_NODE) && (cur_node->extra != XML_TEXT_MAGIC)) { //printf("Text node %s\n", cur_node->content); oms_add_text(p, cur_node->content); } xml_walk_tree(cur_node->children, url, p); // printf("Boo!\n"); } }
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; }
const char* __xmlcontext::get_attr(const char *name) const { return xml_get_attr(xml_node_, name); }
void instruction_call_template(template_context *context, XMLNODE *instruction) { XMLSTRING template_name = xml_get_attr(instruction, xsl_a_name); XMLNODE *template = template_byname(context->context, template_name);