Exemplo n.º 1
0
 SDOXMLString SDOXMLString::operator+(const SDOXMLString& str) const
 {
     xmlChar* newString = xmlStrncatNew(xmlForm, str.xmlForm, xmlStrlen(str.xmlForm));
     SDOXMLString retString(newString);
     if (newString)
         xmlFree(newString);
     return retString;
 }
Exemplo n.º 2
0
void CategoryXmlHandler::characters(void* user_data, const xmlChar* ch, int len) {
    Stub_Categories* stub = static_cast<Stub_Categories*>(user_data);
    string value = (const char *)(xmlStrncatNew(BAD_CAST "", xmlStrsub(ch, 0, len), len));
    Category* category = stub->GetCategory();

    if (stub->GetCurrent() == "name") {
        category->SetName(category->GetName() + value);
    } else if (stub->GetCurrent() == "weight") {
        category->SetWeight(atof(value.c_str()));
    } else if (stub->GetCurrent() == "sample") {
        category->AddSample(value);
    }
}
Exemplo n.º 3
0
static void
_start_element_handler(void *user, const xmlChar *name, const xmlChar **attributes)
{
	XML_Parser  parser = (XML_Parser) user;
	xmlChar    *qualified_name = NULL;

	if (parser->h_start_element == NULL) {
		if (parser->h_default) {
			int attno = 0;

			qualified_name = xmlStrncatNew((xmlChar *)"<", name, xmlStrlen(name));
			if (attributes) {
				while (attributes[attno] != NULL) {
					int att_len;
					char *att_string, *att_name, *att_value;

					att_name = (char *)attributes[attno++];
					att_value = (char *)attributes[attno++];

					att_len = spprintf(&att_string, 0, " %s=\"%s\"", att_name, att_value);

					qualified_name = xmlStrncat(qualified_name, (xmlChar *)att_string, att_len);
					efree(att_string);
				}

			}
			qualified_name = xmlStrncat(qualified_name, (xmlChar *)">", 1);
			parser->h_default(parser->user, (const XML_Char *) qualified_name, xmlStrlen(qualified_name));
			xmlFree(qualified_name);
		}
		return;
	}

	qualified_name = xmlStrdup(name);

	parser->h_start_element(parser->user, (const XML_Char *) qualified_name, (const XML_Char **) attributes);

	xmlFree(qualified_name);
}
Exemplo n.º 4
0
static void
_start_element_handler_ns(void *user, const xmlChar *name, const xmlChar *prefix, const xmlChar *URI, int nb_namespaces, const xmlChar ** namespaces, int nb_attributes, int nb_defaulted, const xmlChar ** attributes)
{
	XML_Parser  parser = (XML_Parser) user;
	xmlChar    *qualified_name = NULL;
	xmlChar **attrs = NULL;
	int i;
	int z = 0;
	int y = 0;
	
	if (nb_namespaces > 0 && parser->h_start_ns != NULL) {
		for (i = 0; i < nb_namespaces; i += 1) {
			parser->h_start_ns(parser->user, (const XML_Char *) namespaces[y], (const XML_Char *) namespaces[y+1]);
			y += 2;
		}
		y = 0;
	}
	
	if (parser->h_start_element == NULL) {
	 	if (parser->h_default) {

			if (prefix) {
				qualified_name = xmlStrncatNew((xmlChar *)"<", prefix, xmlStrlen(prefix));
				qualified_name = xmlStrncat(qualified_name, (xmlChar *)":", 1);
				qualified_name = xmlStrncat(qualified_name, name, xmlStrlen(name));
			} else {
				qualified_name = xmlStrncatNew((xmlChar *)"<", name, xmlStrlen(name));
			}
			
			if (namespaces) {
				int i, j;
				for (i = 0,j = 0;j < nb_namespaces;j++) {
					int ns_len;
					char *ns_string, *ns_prefix, *ns_url;
					
					ns_prefix = (char *) namespaces[i++];
					ns_url = (char *) namespaces[i++];
					
					if (ns_prefix) {
						ns_len = spprintf(&ns_string, 0, " xmlns:%s=\"%s\"", ns_prefix, ns_url);
					} else {
						ns_len = spprintf(&ns_string, 0, " xmlns=\"%s\"", ns_url);
					}
					qualified_name = xmlStrncat(qualified_name, (xmlChar *)ns_string, ns_len);
					
					efree(ns_string);
				}
			}
			
			if (attributes) {
				for (i = 0; i < nb_attributes; i += 1) {
					int att_len;
					char *att_string, *att_name, *att_value, *att_prefix, *att_valueend;

					att_name = (char *) attributes[y++];
					att_prefix = (char *)attributes[y++];
					y++;
					att_value = (char *)attributes[y++];
					att_valueend = (char *)attributes[y++];

					if (att_prefix) {
						att_len = spprintf(&att_string, 0, " %s:%s=\"", att_prefix, att_name);
					} else {
						att_len = spprintf(&att_string, 0, " %s=\"", att_name);
					}

					qualified_name = xmlStrncat(qualified_name, (xmlChar *)att_string, att_len);
					qualified_name = xmlStrncat(qualified_name, (xmlChar *)att_value, att_valueend - att_value);
					qualified_name = xmlStrncat(qualified_name, (xmlChar *)"\"", 1);
					
					efree(att_string);
				}

			}
			qualified_name = xmlStrncat(qualified_name, (xmlChar *)">", 1);
			parser->h_default(parser->user, (const XML_Char *) qualified_name, xmlStrlen(qualified_name));
			xmlFree(qualified_name);
		}
		return;
	}
	_qualify_namespace(parser, name, URI, &qualified_name);
	
	if (attributes != NULL) {
		xmlChar    *qualified_name_attr = NULL;
		attrs = safe_emalloc((nb_attributes  * 2) + 1, sizeof(int *), 0);

		for (i = 0; i < nb_attributes; i += 1) {

			if (attributes[y+1] != NULL) {
				_qualify_namespace(parser, attributes[y] , attributes[y + 2], &qualified_name_attr);
			} else {
				qualified_name_attr = xmlStrdup(attributes[y]);
			}
			attrs[z] = qualified_name_attr;
			attrs[z + 1] = xmlStrndup(attributes[y + 3] , (int) (attributes[y + 4] - attributes[y + 3]));
			z += 2;
			y += 5;
		}

		attrs[z] = NULL;
	}
	parser->h_start_element(parser->user, (const XML_Char *) qualified_name, (const XML_Char **) attrs);
	if (attrs) {
		for (i = 0; i < z; i++) {
			xmlFree(attrs[i]);
		}
		efree(attrs);
	}
	xmlFree(qualified_name);
}
Exemplo n.º 5
0
static void fill_strings(void) {
    int i, j, k;

    /*
     * That's a bit nasty but the output is fine and it doesn't take hours
     * there is a small but sufficient number of duplicates, and we have
     * ":xxx" and full QNames in the last NB_STRINGS_NS values
     */
    for (i = 0; seeds1[i] != NULL; i++) {
        strings1[i] = xmlStrdup((const xmlChar *) seeds1[i]);
	if (strings1[i] == NULL) {
	    fprintf(stderr, "Out of memory while generating strings1\n");
	    exit(1);
	}
    }
    for (j = 0, k = 0;i < NB_STRINGS_MAX - NB_STRINGS_NS;i++,j++) {
        strings1[i] = xmlStrncatNew(strings1[j], strings1[k], -1);
	if (strings1[i] == NULL) {
	    fprintf(stderr, "Out of memory while generating strings1\n");
	    exit(1);
	}
	if (j >= 50) {
	    j = 0;
	    k++;
	}
    }
    for (j = 0; (j < 50) && (i < NB_STRINGS_MAX); i++, j+=2) {
        strings1[i] = xmlStrncatNew(strings1[j], (const xmlChar *) ":", -1);
	if (strings1[i] == NULL) {
	    fprintf(stderr, "Out of memory while generating strings1\n");
	    exit(1);
	}
    }
    for (j = NB_STRINGS_MAX - NB_STRINGS_NS, k = 0;
         i < NB_STRINGS_MAX;i++,j++) {
        strings1[i] = xmlStrncatNew(strings1[j], strings1[k], -1);
	if (strings1[i] == NULL) {
	    fprintf(stderr, "Out of memory while generating strings1\n");
	    exit(1);
	}
	k += 3;
	if (k >= 50) k = 0;
    }

    /*
     * Now do the same with the second pool of strings
     */
    for (i = 0; seeds2[i] != NULL; i++) {
        strings2[i] = xmlStrdup((const xmlChar *) seeds2[i]);
	if (strings2[i] == NULL) {
	    fprintf(stderr, "Out of memory while generating strings2\n");
	    exit(1);
	}
    }
    for (j = 0, k = 0;i < NB_STRINGS_MAX - NB_STRINGS_NS;i++,j++) {
        strings2[i] = xmlStrncatNew(strings2[j], strings2[k], -1);
	if (strings2[i] == NULL) {
	    fprintf(stderr, "Out of memory while generating strings2\n");
	    exit(1);
	}
	if (j >= 50) {
	    j = 0;
	    k++;
	}
    }
    for (j = 0; (j < 50) && (i < NB_STRINGS_MAX); i++, j+=2) {
        strings2[i] = xmlStrncatNew(strings2[j], (const xmlChar *) ":", -1);
	if (strings2[i] == NULL) {
	    fprintf(stderr, "Out of memory while generating strings2\n");
	    exit(1);
	}
    }
    for (j = NB_STRINGS_MAX - NB_STRINGS_NS, k = 0;
         i < NB_STRINGS_MAX;i++,j++) {
        strings2[i] = xmlStrncatNew(strings2[j], strings2[k], -1);
	if (strings2[i] == NULL) {
	    fprintf(stderr, "Out of memory while generating strings2\n");
	    exit(1);
	}
	k += 3;
	if (k >= 50) k = 0;
    }

}