bool c_XMLWriter::t_startdtd(const String& qualifiedname, const String& publicid /* = null_string */, const String& systemid /* = null_string */) { int ret = -1; if (m_ptr) { ret = xmlTextWriterStartDTD(m_ptr, (xmlChar*)qualifiedname.data(), xmls(publicid), xmls(systemid)); } return ret != -1; }
bool c_xmlwriter::t_startdtd(CStrRef qualifiedname, CStrRef publicid /* = null_string */, CStrRef systemid /* = null_string */) { int ret = -1; if (m_ptr) { ret = xmlTextWriterStartDTD(m_ptr, (xmlChar*)qualifiedname.data(), xmls(publicid), xmls(systemid)); } return ret != -1; }
bool c_XMLWriter::t_startdtd(CStrRef qualifiedname, CStrRef publicid /* = null_string */, CStrRef systemid /* = null_string */) { INSTANCE_METHOD_INJECTION_BUILTIN(XMLWriter, XMLWriter::startdtd); int ret = -1; if (m_ptr) { ret = xmlTextWriterStartDTD(m_ptr, (xmlChar*)qualifiedname.data(), xmls(publicid), xmls(systemid)); } return ret != -1; }
axis2_status_t AXIS2_CALL axis2_libxml2_writer_wrapper_write_dtd( axiom_xml_writer_t * writer, const axutil_env_t * env, axis2_char_t * dtd) { axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL; int status = 0; AXIS2_ENV_CHECK(env, AXIS2_FAILURE); AXIS2_PARAM_CHECK(env->error, dtd, AXIS2_FAILURE); status = xmlTextWriterStartDTD(writer_impl->xml_writer, BAD_CAST dtd, NULL, NULL); if(status < 0) { AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_DTD, AXIS2_FAILURE); return AXIS2_FAILURE; } return AXIS2_SUCCESS; }
void write_config() { const char *uri=config_path; int rc; char str_ip[IP6_STR_SIZE]; xmlTextWriterPtr writer; router_list_t *tmp = routers; #ifdef _COUNTERMEASURES_ char config_kill_illegitimate_router[CM_GUARD_REPRESENTATION_SIZE]; char config_kill_wrong_prefix[CM_GUARD_REPRESENTATION_SIZE]; char config_propagate_router_params[CM_GUARD_REPRESENTATION_SIZE]; char config_indicate_ndpmon_presence[CM_GUARD_REPRESENTATION_SIZE]; #endif printf("Writing config...\n"); print_routers(routers); /* Create a new XmlWriter for uri, with no compression. */ writer = xmlNewTextWriterFilename(uri, 0); if (writer == NULL) { printf("testXmlwriterFilename: Error creating the xml writer\n"); return; } xmlTextWriterSetIndent(writer, 1); /* Start the document with the xml default for the version, * encoding ISO 8859-1 and the default for the standalone * declaration. */ rc = xmlTextWriterStartDocument(writer, NULL, MY_ENCODING, NULL); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterStartDocument\n"); return; } xmlTextWriterStartDTD (writer, (xmlChar*)"config_ndpmon", NULL, (xmlChar*)dtd_config_path); xmlTextWriterEndDTD (writer); /* Give the stylesheet for display in the web interface */ xmlTextWriterWriteRaw(writer, (xmlChar*)"<?xml-stylesheet type=\"text/xsl\" href=\"config.xsl\" ?>\n"); /* Start an element named "config_ndpmon". Since this is the first * element, this will be the root element of the document. */ rc = xmlTextWriterStartElement(writer, BAD_CAST "config_ndpmon"); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterStartElement\n"); return; } /* Attribute ignor_autoconf */ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ignor_autoconf", "%d", ignor_autoconf); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n"); return; } /* Attribute syslog_facility */ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "syslog_facility", "%s", syslog_facility); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n"); return; } /* Attribute admin_mail */ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "admin_mail", "%s", admin_mail); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n"); return; } /* Elements of actions_low_pri */ rc = xmlTextWriterStartElement(writer, BAD_CAST "actions_low_pri"); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n"); return; } /* Attribute sendmail */ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "sendmail", "%d", action_low_pri.sendmail); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n"); return; } /* Attribute syslog */ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "syslog", "%d", action_low_pri.syslog); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n"); return; } /* Attribute exec_pipe_program */ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "exec_pipe_program", "%s", action_low_pri.exec_pipe_program); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n"); return; } /* Close actions_low_pri */ rc = xmlTextWriterEndElement(writer); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterEndElement\n"); return; } /* Elements of actions_high_pri */ rc = xmlTextWriterStartElement(writer, BAD_CAST "actions_high_pri"); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n"); return; } /* Attribute sendmail */ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "sendmail", "%d", action_high_pri.sendmail); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n"); return; } /* Attribute syslog */ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "syslog", "%d", action_high_pri.syslog); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n"); return; } /* Attribute exec_pipe_program */ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "exec_pipe_program", "%s", action_high_pri.exec_pipe_program); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n"); return; } /* Close actions_high_pri */ rc = xmlTextWriterEndElement(writer); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterEndElement\n"); return; } /* Attribute use_reverse_hostlookups */ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "use_reverse_hostlookups", "%d", use_reverse_hostlookups); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n"); return; } /* Start an element named routers containing the routers' definition */ rc = xmlTextWriterStartElement(writer, BAD_CAST "routers"); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterStartElement\n"); return; } /*for each router a new neighbor with its attributes is created in the file */ while(tmp != NULL) { address_t *tmp_address = tmp->addresses; prefix_t *tmp_prefix = tmp->prefixes; ipv6_ntoa(str_ip, tmp->lla); /* Start an element named "router" as child of routers. */ rc = xmlTextWriterStartElement(writer, BAD_CAST "router"); if (rc < 0) goto start_element_error; /* Element mac */ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "mac", "%s", ether_ntoa(&(tmp->mac))); if (rc < 0) goto format_element_error; /* Element lla */ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "lla", "%s", str_ip); if (rc < 0) goto format_element_error; /* Elements for Router Advertisement Parameters: */ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "param_curhoplimit", "%u", tmp->param_curhoplimit); if (rc < 0) goto format_element_error; rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "param_flags_reserved", "%u", tmp->param_flags_reserved); if (rc < 0) goto format_element_error; rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "param_router_lifetime", "%u", tmp->param_router_lifetime); if (rc < 0) goto format_element_error; rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "param_reachable_timer", "%u", tmp->param_reachable_timer); if (rc < 0) goto format_element_error; rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "param_retrans_timer", "%u", tmp->param_retrans_timer); if (rc < 0) goto format_element_error; rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "param_mtu", "%u", tmp->param_mtu); if (rc < 0) goto format_element_error; rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "params_volatile", "%i", tmp->params_volatile); if (rc < 0) goto format_element_error; /* Start an element named prefixes */ rc = xmlTextWriterStartElement(writer, BAD_CAST "prefixes"); if (rc < 0) goto start_element_error; while(tmp_prefix != NULL) { ipv6_ntoa(str_ip, tmp_prefix->prefix); rc = xmlTextWriterStartElement(writer, BAD_CAST "prefix"); if (rc < 0) goto start_element_error; /* Elements for prefix address and mask:*/ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "address", "%s", str_ip); if (rc < 0) goto format_element_error; rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "mask", "%i", tmp_prefix->mask); if (rc < 0) goto format_element_error; /* Elements for prefix parameters:*/ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "param_flags_reserved", "%u", tmp_prefix->param_flags_reserved); if (rc < 0) goto format_element_error; rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "param_valid_time", "%u", tmp_prefix->param_valid_time); if (rc < 0) goto format_element_error; rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "param_preferred_time", "%u", tmp_prefix->param_preferred_time); if (rc < 0) goto format_element_error; rc = xmlTextWriterEndElement(writer); if (rc < 0) goto end_element_error; /* Fetch next prefix:*/ tmp_prefix = tmp_prefix->next; } rc = xmlTextWriterEndElement(writer); if (rc < 0) goto end_element_error; /* Addresses */ rc = xmlTextWriterStartElement(writer, BAD_CAST "addresses"); if (rc < 0) goto start_element_error; while(tmp_address != NULL) { ipv6_ntoa(str_ip, tmp_address->address); /*Element for address.*/ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "address", "%s", str_ip); if (rc < 0) goto format_element_error; tmp_address = tmp_address->next; } /* close addresses */ rc = xmlTextWriterEndElement(writer); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterEndElement\n"); return; } /* close router */ rc = xmlTextWriterEndElement(writer); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterEndElement\n"); return; } tmp = tmp->next; } /* Close routers */ rc = xmlTextWriterEndElement(writer); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterEndElement\n"); return; } #ifdef _COUNTERMEASURES_ cm_guard_all_to_representation( config_kill_illegitimate_router, config_kill_wrong_prefix, config_propagate_router_params, config_indicate_ndpmon_presence ); /* Start an element named countermeasures containing the counter measures configuration. */ rc = xmlTextWriterStartElement(writer, BAD_CAST "countermeasures"); if (rc < 0) goto start_element_error; /* Write guard configurations. */ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "kill_illegitimate_router", "%s", config_kill_illegitimate_router); if (rc < 0) goto format_element_error; rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "kill_wrong_prefix", "%s", config_kill_wrong_prefix); if (rc < 0) goto format_element_error; rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "propagate_router_params", "%s", config_propagate_router_params); if (rc < 0) goto format_element_error; rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "indicate_ndpmon_presence", "%s", config_indicate_ndpmon_presence); if (rc < 0) goto format_element_error; /* Close countermeasures */ rc = xmlTextWriterEndElement(writer); if (rc < 0) goto end_element_error; #endif /* Close config_ndpmon */ rc = xmlTextWriterEndElement(writer); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterEndElement\n"); return; } xmlFreeTextWriter(writer); return; format_element_error: printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n"); xmlFreeTextWriter(writer); return; start_element_error: printf("testXmlwriterFilename: Error at xmlTextWriterStartElement\n"); xmlFreeTextWriter(writer); return; end_element_error: printf("testXmlwriterFilename: Error at xmlTextWriterEndElement\n"); xmlFreeTextWriter(writer); return; }
void write_cache() { const char *uri=cache_path; int rc; char str_ip[IP6_STR_SIZE]; xmlTextWriterPtr writer; neighbor_list_t *tmp = neighbors; FILE *dat = NULL; printf("Writing cache...\n"); /* Create a new XmlWriter for uri, with no compression. */ writer = xmlNewTextWriterFilename(uri, 0); if (writer == NULL) { printf("testXmlwriterFilename: Error creating the xml writer\n"); return; } xmlTextWriterSetIndent(writer, 1); /* Start the document with the xml default for the version, * encoding ISO 8859-1 and the default for the standalone * declaration. */ rc = xmlTextWriterStartDocument(writer, NULL, MY_ENCODING, NULL); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterStartDocument\n"); return; } xmlTextWriterStartDTD (writer, (xmlChar*)"neighbor_list", NULL, (xmlChar*)dtd_path); xmlTextWriterEndDTD (writer); /* Give the stylesheet for display in the web interface */ xmlTextWriterWriteRaw(writer, (xmlChar*)"<?xml-stylesheet type=\"text/xsl\" href=\"neighbor.xsl\" ?>\n"); /* Start an element named "neighbor_list". Since this is the first * element, this will be the root element of the document. */ rc = xmlTextWriterStartElement(writer, BAD_CAST "neighbor_list"); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterStartElement\n"); return; } /*for each neighbor in the cache a new neighbor element with its *attributes is created in the file */ while(tmp != NULL) { address_t *atmp = tmp->addresses; ethernet_t *etmp = tmp->old_mac; /* to format the time */ time_t timep; char time_str[27]; char vlan_str[10]; /* Start an element named "neighbor" as child of neighbor_list. */ rc = xmlTextWriterStartElement(writer, BAD_CAST "neighbor"); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterStartElement\n"); return; } /* Attribute vlan_id */ snprintf(vlan_str,9,"%d",(int) tmp->vlan_id); rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "vlan_id", "%s", vlan_str); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n"); return; } /* Attribute mac */ rc = xmlTextWriterStartElement(writer, BAD_CAST "mac"); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n"); return; } #ifdef _MACRESOLUTION_ rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "vendor", "%s", tmp->vendor); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterWriteAttribute %d\n",rc); } #endif rc = xmlTextWriterWriteRaw(writer, BAD_CAST ether_ntoa(&(tmp->mac))); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n"); return; } rc = xmlTextWriterEndElement(writer); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterEndElement\n"); return; } /* rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "mac", "%s", ether_ntoa(&(tmp->mac))); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n"); return; } */ /* Attribute lla */ ipv6_ntoa(str_ip, tmp->lla); rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "lla", "%s", str_ip); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n"); return; } /* element time */ rc = xmlTextWriterStartElement(writer, BAD_CAST "time"); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n"); return; } #if 0 rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "time", "%d",tmp->timer); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n"); return; } #endif /* convert to str representation in order to display it in the web interface */ timep = tmp->timer; strcpy(time_str, ctime(&timep)); rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "timestr", "%s", time_str); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterWriteAttribute %d\n",rc); } /* the content */ snprintf(time_str,27,"%d",(int) tmp->timer); rc = xmlTextWriterWriteRaw(writer, BAD_CAST time_str); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n"); return; } rc = xmlTextWriterEndElement(writer); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterEndElement\n"); return; } /* Addresses */ /* rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "adresses", NULL, NULL); */ rc = xmlTextWriterStartElement(writer, BAD_CAST "addresses"); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n"); return; } while(atmp != NULL) { /* to store a char * version of the int + \O */ ipv6_ntoa(str_ip, atmp->address); /* the address element */ rc = xmlTextWriterStartElement(writer, BAD_CAST "address"); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n"); return; } /* lastseen timer */ rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "lastseen", "%d", (int)atmp->lastseen); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterWriteAttribute %d\n",rc); } /* convert to str representation in order to display it in the web interface */ timep = atmp->lastseen; strcpy(time_str, ctime(&timep)); rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "lastseenstr", "%s", time_str); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterWriteAttribute %d\n",rc); } /* firstseen timer */ rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "firstseen", "%d", (int)atmp->firstseen); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterWriteAttribute %d\n",rc); } /* convert to str representation in order to display it in the web interface */ timep = atmp->firstseen; strcpy(time_str, ctime(&timep)); rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "firstseenstr", "%s", time_str); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterWriteAttribute %d\n",rc); } /* the content */ rc = xmlTextWriterWriteRaw(writer, BAD_CAST str_ip); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n"); return; } rc = xmlTextWriterEndElement(writer); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterEndElement\n"); return; } atmp = atmp->next; } rc = xmlTextWriterEndElement(writer); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterEndElement\n"); return; } /* Old Mac */ rc = xmlTextWriterStartElement(writer, BAD_CAST "old_mac"); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n"); return; } while(etmp != NULL) { rc = xmlTextWriterStartElement(writer, BAD_CAST "mac"); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n"); return; } if(!MEMCMP(&(etmp->mac),&(tmp->previous_mac), sizeof(struct ether_addr))) { rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "last", "%s", "true"); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterWriteAttribute %d\n",rc); } } #ifdef _MACRESOLUTION_ rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "vendor", "%s", etmp->vendor); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterWriteAttribute %d\n",rc); } #endif rc = xmlTextWriterWriteRaw(writer, BAD_CAST ether_ntoa(&(etmp->mac))); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n"); return; } rc = xmlTextWriterEndElement(writer); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterEndElement\n"); return; } etmp = etmp->next; } rc = xmlTextWriterEndElement(writer); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterEndElement\n"); return; } /* Close neighbor */ rc = xmlTextWriterEndElement(writer); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterEndElement\n"); return; } tmp = tmp->next; } /* Close neighbor_list */ rc = xmlTextWriterEndElement(writer); if (rc < 0) { printf("testXmlwriterFilename: Error at xmlTextWriterEndElement\n"); return; } xmlFreeTextWriter(writer); /* Write in discovery_history.dat the number of neighbors in the cache for statistics */ if( (dat = fopen(discovery_history_path,"a")) != NULL) { fprintf(dat,"%d %d\n", (int)time(NULL), nb_neighbor(neighbors) ); fclose(dat); } }