Exemple #1
0
static inline xmlChar* trim_whitespace(xmlChar* str)
{
    xmlChar* ret = str;
    int len;

    if (!str)
        return NULL;

    while (*ret && isspace(*ret))
        ++ret;
    len = xmlStrlen(ret);
    if (len)
        while (isspace(ret[len-1])) --len;

    ret = xmlStrndup(ret, len);
    xmlFree(str);
    return ret;
}
Exemple #2
0
static char * xml_cdpUTF8ToStr( xmlChar * szStr, HB_SIZE * pnLen, const char * pszCdpOut )
{

   PHB_CODEPAGE cdpIn  = hb_cdpFindExt( XML_UTF8_HB_CDP );
   PHB_CODEPAGE cdpOut = pszCdpOut ? hb_cdpFindExt( pszCdpOut ) : hb_vmCDP();

   char * szDest = NULL;

   if( cdpIn && cdpOut && szStr )
   {
      int len = xmlStrlen( szStr );
      memcpy( pnLen, &len, sizeof( len ) );

      szDest = hb_cdpnDup( ( const char * ) szStr, pnLen, cdpIn, cdpOut );
   }

   return szDest;
}
Exemple #3
0
/**
 * \brief Get the node's children node with given name.
 * @param[in] node Search in the children nodes of this node.
 * @param[in] children_name Name of the requested children node.
 * @return Pointer to the children node with requested name. It should not be
 * freed since it is children of given node.
 */
static inline xmlNodePtr get_children(xmlNodePtr node, const xmlChar* children_name)
{
	/* check validity of parameters */
	if (!node || !children_name) {
		return (NULL);
	}

	xmlNodePtr children = node->children;

	while (children) {
		if (!xmlStrncmp(children->name, children_name, xmlStrlen(children_name) + 1)) {
			return (children);
		}
		children = children->next;
	}

	return (children);
}
Exemple #4
0
static HRESULT WINAPI domcomment_substringData(
    IXMLDOMComment *iface,
    long offset, long count, BSTR *p)
{
    domcomment *This = impl_from_IXMLDOMComment( iface );
    xmlnode *pDOMNode = impl_from_IXMLDOMNode( This->node );
    xmlChar *pContent;
    long nLength = 0;
    HRESULT hr = S_FALSE;

    TRACE("%p\n", iface);

    if(!p)
        return E_INVALIDARG;

    *p = NULL;
    if(offset < 0 || count < 0)
        return E_INVALIDARG;

    if(count == 0)
        return hr;

    pContent = xmlNodeGetContent(pDOMNode->node);
    if(pContent)
    {
        nLength = xmlStrlen(pContent);

        if( offset < nLength)
        {
            BSTR sContent = bstr_from_xmlChar(pContent);
            if(offset + count > nLength)
                *p = SysAllocString(&sContent[offset]);
            else
                *p = SysAllocStringLen(&sContent[offset], count);

            SysFreeString(sContent);
            hr = S_OK;
        }

        xmlFree(pContent);
    }

    return hr;
}
Exemple #5
0
/**
 * exsltStrPaddingFunction:
 * @ctxt: an XPath parser context
 * @nargs: the number of arguments
 *
 * Creates a padding string of a certain length.
 */
static void
exsltStrPaddingFunction (xmlXPathParserContextPtr ctxt, int nargs) {
    int number, str_len = 0, str_size = 0;
    xmlChar *str = NULL, *ret = NULL;

    if ((nargs < 1) || (nargs > 2)) {
	xmlXPathSetArityError(ctxt);
	return;
    }

    if (nargs == 2) {
	str = xmlXPathPopString(ctxt);
	str_len = xmlUTF8Strlen(str);
	str_size = xmlStrlen(str);
    }
    if (str_len == 0) {
	if (str != NULL) xmlFree(str);
	str = xmlStrdup((const xmlChar *) " ");
	str_len = 1;
	str_size = 1;
    }

    number = (int) xmlXPathPopNumber(ctxt);

    if (number <= 0) {
	xmlXPathReturnEmptyString(ctxt);
	xmlFree(str);
	return;
    }

    while (number >= str_len) {
	ret = xmlStrncat(ret, str, str_size);
	number -= str_len;
    }
    if (number > 0) {
	str_size = xmlUTF8Strsize(str, number);
	ret = xmlStrncat(ret, str, str_size);
    }

    xmlXPathReturnString(ctxt, ret);

    if (str != NULL)
	xmlFree(str);
}
/**
 * soap_walk_tree
 * @node:       pointer to an XML subtree
 * @colonstring: node name strings that are being searched; for example, to
 *              search for nodes "a", then "b", then "c", pass "a:b:c"
 *
 * Searches an XML subtree, looking for a named node.  Very similar to
 * soap_find_node() above, but uses an entirely different algorithm, both for
 * efficiency and to make response parsing more pedantic.
 *
 * The passed colonstring is a list of tree node names separated by ':'.  At
 * each level of the tree, the corresponding name must match.  This means that
 * the whole XML tree doesn't need to be searched, and that you know you've
 * found the right node, not one that is similarly-named but is in a different
 * part of the XML tree.
 *
 * Return value: the XML node, if found, or NULL.
 **/
xmlNode         *soap_walk_tree(xmlNode *node, char *colonstring)
{
        char            *next;
        char            *c;
        int             len;            /* Length of node name string */

        if ((! node) ||
            (! colonstring) ||
            (! *colonstring) ||
            (*colonstring == ':')) {
                return(NULL);
        }

        /* Break string at ':' */
        c = strchr(colonstring, ':');
        if (c) {
                len = c - colonstring;
                next = c + 1;
        }
        else {
                len = strlen(colonstring);
                next = colonstring + len;
        }

        /* Look for this in the node tree's children */
        node = node->children;
        while (node) {
                if ((! xmlStrncmp(node->name,
                                  (const xmlChar *)colonstring,
                                  len)) &&
                    (xmlStrlen(node->name) == len)) {
                        if (*next) {
                                return(soap_walk_tree(node, next));
                        }
                        else {
                                /* Done searching */
                                return(node);
                        }
                }
                node = node->next;
        }
        return(NULL);
}
Exemple #7
0
/**
 * xmlBufAddHead:
 * @buf:  the buffer
 * @str:  the #xmlChar string
 * @len:  the number of #xmlChar to add
 *
 * Add a string range to the beginning of an XML buffer.
 * if len == -1, the length of @str is recomputed.
 *
 * Returns 0 successful, a positive error code number otherwise
 *         and -1 in case of internal or API error.
 */
int
xmlBufAddHead(xmlBufPtr buf, const xmlChar *str, int len) {
    unsigned int needSize;

    if ((buf == NULL) || (buf->error))
        return(-1);
    CHECK_COMPAT(buf)
    if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return -1;
    if (str == NULL) {
#ifdef DEBUG_BUFFER
        xmlGenericError(xmlGenericErrorContext,
		"xmlBufAddHead: str == NULL\n");
#endif
	return -1;
    }
    if (len < -1) {
#ifdef DEBUG_BUFFER
        xmlGenericError(xmlGenericErrorContext,
		"xmlBufAddHead: len < 0\n");
#endif
	return -1;
    }
    if (len == 0) return 0;

    if (len < 0)
        len = xmlStrlen(str);

    if (len <= 0) return -1;

    if ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL)) {
        size_t start_buf = buf->content - buf->contentIO;

	if (start_buf > (unsigned int) len) {
	    /*
	     * We can add it in the space previously shrinked
	     */
	    buf->content -= len;
            memmove(&buf->content[0], str, len);
	    buf->use += len;
	    buf->size += len;
	    UPDATE_COMPAT(buf)
	    return(0);
	}
Exemple #8
0
static DWORD dt_hash(xmlChar const* str, int len /* calculated if -1 */)
{
    DWORD hval = (len == -1)? xmlStrlen(str) : len;

    switch (hval)
    {
        default:
            hval += hash_assoc_values[str[10]];
            /*FALLTHROUGH*/
        case 10:
            hval += hash_assoc_values[str[9]];
            /*FALLTHROUGH*/
        case 9:
            hval += hash_assoc_values[str[8]];
            /*FALLTHROUGH*/
        case 8:
            hval += hash_assoc_values[str[7]];
            /*FALLTHROUGH*/
        case 7:
            hval += hash_assoc_values[str[6]];
            /*FALLTHROUGH*/
        case 6:
            hval += hash_assoc_values[str[5]];
            /*FALLTHROUGH*/
        case 5:
            hval += hash_assoc_values[str[4]];
            /*FALLTHROUGH*/
        case 4:
            hval += hash_assoc_values[str[3]];
            /*FALLTHROUGH*/
        case 3:
            hval += hash_assoc_values[str[2]];
            /*FALLTHROUGH*/
        case 2:
            hval += hash_assoc_values[str[1]];
            /*FALLTHROUGH*/
        case 1:
            hval += hash_assoc_values[str[0]];
            break;
    }
    return hval;
}
Exemple #9
0
/*
 * There are functions to get stuff out of node - such as xmlGetProp(node, xmlChar *name),
 * xmlNodeGetContent(), xmlGetNodePath(),
 */
void
walk_doc_tree(xmlNodePtr node, int level)
{
    xmlChar* empty = (xmlChar*)"";
    xmlChar* prefix = empty;
    if (node->ns) {
	size_t len = (xmlStrlen(node->ns->href) * sizeof(xmlChar)) + 3;
	prefix = xmlMalloc(len);
	snprintf((char*)prefix, len, "{%s}", node->ns->href);
    }

    if (node->type == XML_ELEMENT_NODE) {
	xmlNodePtr att = (xmlNodePtr) node->properties;	/* similar casts in e.g. xmlschemas.c */
	const xmlChar* closeMe = node->name;
	printf("<%s%s", prefix, closeMe);
	while (att != NULL) {
	    walk_doc_tree(att, level + 1);
	    att = att->next;
	}
	printf(">");

	node = node->children;
	while (node != NULL) {
	    walk_doc_tree(node, level + 1);
	    node = node->next;
	}

	if (closeMe != NULL)
	    printf("</%s%s>", prefix, closeMe);
    } else if (node->type == XML_ATTRIBUTE_NODE) {
	printf(" %s%s=\"%s\"", prefix, node->name, xmlNodeGetContent(node)); /* xmlNodeListGetString ? */
    } else if (node->type == XML_TEXT_NODE) {
	printf("%s", xmlNodeGetContent(node));
    } else
	printf("node %p type: %-20s node name: %s%-20s\n",
	       (void *)node, type_names[node->type], prefix, node->name);

    if (prefix != empty)
	xmlFree(prefix);
    if (level == 0)
	printf("\n");
}
Exemple #10
0
xmlDocPtr find_element(xmlDocPtr xml_document_pointer, char* element_name)
{
    if(NULL != xml_document_pointer &&
       NULL != element_name)
    {
        while(true)
        {
            if(NULL == xml_document_pointer)
            {
                break;
            }
            if(0 == xmlStrncmp(xml_document_pointer->name, element_name, xmlStrlen(element_name)))
            {
                return (xmlDocPtr)xml_document_pointer;
            }
            xml_document_pointer = (xmlDocPtr)xml_document_pointer->next;
        }
    }
    return NULL;
}
Exemple #11
0
const xmlChar *
xmlStrstr(const xmlChar *str, const xmlChar *val)
{
  int n;

  if (str == NULL) return(NULL);
  if (val == NULL) return(NULL);
  n = xmlStrlen(val);

  if (n == 0) return(str);
  while (*str != 0)
  { /* non input consuming */
    if (*str == *val)
    {
      if (!xmlStrncmp(str, val, n)) return((const xmlChar *) str);
    }
    str++;
  }
  return(NULL);
}
Exemple #12
0
void
web_child(int sockfd)
{
	ssize_t n;
	char tcp_recv_buff[MAXLINE];
	xmlChar * tcp_send_buff;

	memset(tcp_recv_buff,0,MAXLINE);
	if( (n=read(sockfd,tcp_recv_buff,MAXLINE))>0)
	{
		//tcp_recv_buff[n]='\0';
		//printf("pthread %d recv:\n%s\n",(int)pthread_self(),tcp_recv_buff);
		tcp_send_buff=process_request(tcp_recv_buff);
		Writen(sockfd,(char *)tcp_send_buff,xmlStrlen(tcp_send_buff));
		//printf("pthread %d send:\n%s\n",(int)pthread_self(),tcp_send_buff);
		xmlFree(tcp_send_buff);
	}
	else if(n<0)
	err_sys("read erro");
}
Exemple #13
0
const char *ermXmlGetAttributeStringBuffer(const erManifest *pCtx, const char *express, const char *attrName, int *length)
{
    *length = 0;
    xmlXPathObjectPtr xpathObj = LocateTo(express, pCtx);
    if (NULL == xpathObj)
        return NULL;

    /* read from path object */
    xmlNodeSetPtr nodes = xpathObj->nodesetval;
    if (nodes && nodes->nodeNr && nodes->nodeTab[0])
    {
        xmlChar *pSrc = xmlGetProp(nodes->nodeTab[0], attrName);
        xmlXPathFreeObject(xpathObj);
        *length = xmlStrlen(pSrc);
        return pSrc;
    }

    xmlXPathFreeObject(xpathObj);
    return NULL;
}
Exemple #14
0
xmlChar *
xmlStrncat(xmlChar *cur, const xmlChar *add, int len) {
    int size;
    xmlChar *ret;

    if ((add == NULL) || (len == 0))
        return(cur);
    if (cur == NULL)
        return(xmlStrndup(add, len));

    size = xmlStrlen(cur);
    ret = (xmlChar *) xmlRealloc(cur, (size + len + 1) * sizeof(xmlChar));
    if (ret == NULL) {
        xmlErrMemory(NULL, NULL);
        return(cur);
    }
    memcpy(&ret[size], add, len * sizeof(xmlChar));
    ret[size + len] = 0;
    return(ret);
}
Exemple #15
0
static void
parseEpigraph (xmlDocPtr doc, xmlNodePtr cur, FB2Content *fb)
{
  xmlChar *content;

  cur = cur->children;
  while (cur != NULL) {

    if (xmlNodeIsText(cur)) {
      /*
      content = xmlNodeGetContent(cur);
      bufferAppend(content, xmlStrlen(content), fb);
      xmlFree(content);
      */
    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"cite")) {
      parseCite(doc, cur, fb);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"poem")) {
      parsePoem(doc, cur, fb);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"p")) {
      parseP(doc, cur, 1, fb);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"empty-line")) {
      bufferAppend("\n", 1, fb);

    } else if (!xmlStrcmp(cur->name, (const xmlChar *)"text-author")) {

      content = xmlNodeGetContent(cur->children);
      if (content) {
	bufferAppend("\t", 1, fb);
	bufferAppend(content, xmlStrlen(content), fb);
	bufferAppend("\n", 1, fb);
      }
      xmlFree(content);

    }
    cur = cur->next;
  }
  return;
}
Exemple #16
0
static void
extBitToHex (xmlXPathParserContextPtr ctxt, int nargs)
{
    xmlChar *res;
    xmlXPathObjectPtr xop;
    unsigned long long val;
    int i, len1, len2;

    if (nargs != 1) {
	xmlXPathSetArityError(ctxt);
	return;
    }

    /* Pop args in reverse order */
    xop = valuePop(ctxt);
    if (xop == NULL || xmlXPathCheckError(ctxt))
	return;
    res = extBitStringVal(ctxt, xop);
    if (res == NULL)
	return;

    for (i = 0, val = 0; i <= 64 && res[i]; i++) {
	val <<= 1;
	if (res[i] == '1')
	    val += 1;
    }

    if (i > 64)
	xmlXPathReturnNumber(ctxt, (double) -1);
    else {
	len1 = xmlStrlen(res);
	len2 = snprintf((char *) res, len1 + 1, "0x%qx", val);
	if (len2 > len1) {
	    res = xmlRealloc(res, len2 + 1);
	    if (res)
		snprintf((char *) res, len2 + 1, "0x%qx", val);
	}

	xmlXPathReturnString(ctxt, res);
    }
}
Exemple #17
0
static void
walkTree(xmlDocPtr doc, xmlNodePtr cur, char *text)
{
	xmlAttr *cur_attr = NULL;
	xmlChar *content;
	
	while (cur != NULL) {
		/* text */
		if (!xmlStrcmp(cur->name, (const xmlChar *)"text")) {
			content = xmlNodeListGetString(doc, cur, 1);
			memcpy(text, content, xmlStrlen(content));
			xmlFree(content);
			return;
		}
		
		walkTree(doc, cur->xmlChildrenNode, text);
		cur = cur->next;
	}

	return;
}
Exemple #18
0
/**
 * xmlStrncatNew:
 * @str1:  first xmlChar string
 * @str2:  second xmlChar string
 * @len:  the len of @str2
 *
 * same as xmlStrncat, but creates a new string.  The original
 * two strings are not freed.
 *
 * Returns a new xmlChar * or NULL
 */
xmlChar *
xmlStrncatNew(const xmlChar *str1, const xmlChar *str2, int len) {
    int size;
    xmlChar *ret;

    if ((str2 == NULL) || (len == 0))
        return(xmlStrdup(str1));
    if (str1 == NULL)
        return(xmlStrndup(str2, len));

    size = xmlStrlen(str1);
    ret = (xmlChar *) xmlMalloc((size + len + 1) * sizeof(xmlChar));
    if (ret == NULL) {
        xmlErrMemory(NULL, NULL);
        return(xmlStrndup(str1, size));
    }
    memcpy(ret, str1, size * sizeof(xmlChar));
    memcpy(&ret[size], str2, len * sizeof(xmlChar));
    ret[size + len] = 0;
    return(ret);
}
Exemple #19
0
static char *nmem_dup_xml_content(NMEM n, xmlNodePtr ptr)
{
    unsigned char *cp;
    xmlNodePtr p;
    int len = 1;  /* start with 1, because of trailing 0 */
    unsigned char *str;
    int first = 1; /* whitespace lead flag .. */
    /* determine length */
    for (p = ptr; p; p = p->next)
    {
        if (p->type == XML_TEXT_NODE)
            len += xmlStrlen(p->content);
    }
    /* now allocate for the string */
    str = (unsigned char *) nmem_malloc(n, len);
    *str = '\0'; /* so we can use strcat */
    for (p = ptr; p; p = p->next)
    {
        if (p->type == XML_TEXT_NODE)
        {
            cp = p->content;
            if (first)
            {
                while(*cp && isspace(*cp))
                    cp++;
                if (*cp)
                    first = 0;  /* reset if we got non-whitespace out */
            }
            strcat((char *)str, (const char *)cp); /* append */
        }
    }
    /* remove trailing whitespace */
    cp = strlen((const char *)str) + str;
    while (cp != str && isspace(cp[-1]))
        cp--;
    *cp = '\0';
    /* return resulting string */
    return (char *) str;
}
Exemple #20
0
static void
process_video_search_result (const gchar *xml_result, gpointer user_data)
{
  xmlDocPtr doc;
  xmlNodePtr node;
  GList *video_list = NULL;
  GVimeoVideoSearchData *data = (GVimeoVideoSearchData *) user_data;

  doc = xmlReadMemory (xml_result,
		       xmlStrlen ((xmlChar *) xml_result),
		       NULL,
		       NULL,
		       XML_PARSE_RECOVER | XML_PARSE_NOBLANKS);
  node = xmlDocGetRootElement (doc);

  /* Check result is ok */
  if (!node || !result_is_correct (node))
  {
    data->search_cb (data->vimeo, NULL, data->user_data);
  }
  else
  {
    node = node->xmlChildrenNode;

    /* Now we're at "video pages" node */
    node = node->xmlChildrenNode;
    while (node)
    {
      video_list = g_list_prepend (video_list, get_video (node));
      node = node->next;
    }

    video_list = g_list_reverse (video_list);
    data->search_cb (data->vimeo, video_list, data->user_data);
    g_list_free_full (video_list, (GDestroyNotify) g_hash_table_unref);
  }
  g_slice_free (GVimeoVideoSearchData, data);
  xmlFreeDoc (doc);
}
Exemple #21
0
static void decode_string(char* dst, const xmlChar* src) {

	char* output = dst;
	char* input = (char*)src;
	size_t inputlen = strlen(input);

	size_t inputleft = inputlen;
	size_t outputleft = xmlStrlen(src);

	iconv_t* cd = iconv_open("ASCII", "UTF-8");
	if(cd < 0) { // returns -1 on error
		// It is very improbable
		error(2, errno, "iconv does not support UTF-8 or ASCII");
	}
	size_t converted = iconv(cd, &input, &inputleft, &output, &outputleft);
	if(converted < 0) {
		error(2, errno, "error converting string");
	}

	iconv_close(cd);

}
Exemple #22
0
/* {{{ php_xsl_xslt_string_to_xpathexpr()
   Translates a string to a XPath Expression */
static char *php_xsl_xslt_string_to_xpathexpr(const char *str)
{
	const xmlChar *string = (const xmlChar *)str;

	xmlChar *value;
	int str_len;

	str_len = xmlStrlen(string) + 3;

	if (xmlStrchr(string, '"')) {
		if (xmlStrchr(string, '\'')) {
			php_error_docref(NULL, E_WARNING, "Cannot create XPath expression (string contains both quote and double-quotes)");
			return NULL;
		}
		value = (xmlChar*) safe_emalloc (str_len, sizeof(xmlChar), 0);
		snprintf((char*)value, str_len, "'%s'", string);
	} else {
		value = (xmlChar*) safe_emalloc (str_len, sizeof(xmlChar), 0);
		snprintf((char *)value, str_len, "\"%s\"", string);
	}
	return (char *) value;
}
Exemple #23
0
const char *ermXmlGetStringBuffer(const erManifest *pCtx, const char *express, int *length)
{
    *length = 0;
    xmlXPathObjectPtr xpathObj = LocateTo(express, pCtx);
    if (NULL == xpathObj)
        return NULL;

    /* read from path object */
    xmlNodeSetPtr nodes = xpathObj->nodesetval;

    if (nodes && nodes->nodeNr > 0 && nodes->nodeTab[0] && nodes->nodeTab[0]->children)
    {
        xmlChar *content = xmlNodeGetContent(&nodes->nodeTab[0]->children[0]);
        *length = xmlStrlen(content);
        xmlXPathFreeObject(xpathObj);
        return (const char *)content;
    }

    TRACE("No nodes found!\n");
    xmlXPathFreeObject(xpathObj);
    return NULL;
}
Exemple #24
0
/**
 * processNode:
 * @reader: the xmlReader
 *
 * Dump information about the current node
 */
static void processNode (xmlTextReaderPtr reader) {
	const xmlChar *name, *value;

	name = xmlTextReaderConstName (reader);
	if (name == NULL)
		name = BAD_CAST "--";

	value = xmlTextReaderConstValue (reader);

	printf ("%d %d %s %d %d", xmlTextReaderDepth (reader),
	                xmlTextReaderNodeType (reader), name,
	                xmlTextReaderIsEmptyElement (reader),
	                xmlTextReaderHasValue (reader));
	if (value == NULL)
		printf ("\n");
	else {
		if (xmlStrlen (value) > 40)
			printf (" %.40s...\n", value);
		else
			printf (" %s\n", value);
	}
}
Exemple #25
0
/* {{{ proto string SimpleXMLIterator::key()
 Get name of current child element */
PHP_METHOD(ce_SimpleXMLIterator, key)
{
	xmlNodePtr curnode;
	php_sxe_object *intern;
	php_sxe_object *sxe = php_sxe_fetch_object(getThis() TSRMLS_CC);
	
	if (zend_parse_parameters_none() == FAILURE) {
		return;
	}

	if (!sxe->iter.data) {
		RETURN_FALSE;
	}

	intern = (php_sxe_object *)zend_object_store_get_object(sxe->iter.data TSRMLS_CC);
	if (intern != NULL && intern->node != NULL) {
		curnode = (xmlNodePtr)((php_libxml_node_ptr *)intern->node)->node;
		RETURN_STRINGL((char*)curnode->name, xmlStrlen(curnode->name), 1);
	}
    
	RETURN_FALSE;
}
Exemple #26
0
/**
 * xmlStrncat:
 * @param cur the original xmlChar* array
 * @param add the xmlChar* array added
 * @param len the length of add
 *
 * a strncat for array of xmlChar's, it will extend cur with the len
 * first bytes of add.
 *
 * Returns a new xmlChar*, the original cur is reallocated if needed
 * and should not be freed
 *
 * OOM: possible --> OOM flag is set  
 */
XMLPUBFUNEXPORT xmlChar*
xmlStrncat(xmlChar* cur, const xmlChar* add, int len)
{
    int size;
    xmlChar* ret;

    if ((add == NULL) || (len == 0))
        return(cur);
    if (cur == NULL)
        return(xmlStrndup(add, len));

    size = xmlStrlen(cur);
    // DONE: Fix xmlRealloc: Nothing to fix!
    ret = (xmlChar*) xmlRealloc(cur, (size + len + 1) * sizeof(xmlChar));
    if (!ret) {
        xmlErrMemory(NULL, NULL);
        return(cur);
    }
    memcpy(&ret[size], add, len * sizeof(xmlChar));
    ret[size + len] = 0;
    return(ret);
}
Exemple #27
0
/* {{{ proto string SimpleXMLIterator::key()
 Get name of current child element */
PHP_METHOD(ce_SimpleXMLIterator, key)
{
	xmlNodePtr curnode;
	php_sxe_object *intern;
	php_sxe_object *sxe = Z_SXEOBJ_P(getThis());

	if (zend_parse_parameters_none() == FAILURE) {
		return;
	}

	if (Z_ISUNDEF(sxe->iter.data)) {
		RETURN_FALSE;
	}

	intern = Z_SXEOBJ_P(&sxe->iter.data);
	if (intern != NULL && intern->node != NULL) {
		curnode = (xmlNodePtr)((php_libxml_node_ptr *)intern->node)->node;
		RETURN_STRINGL((char*)curnode->name, xmlStrlen(curnode->name));
	}

	RETURN_FALSE;
}
Exemple #28
0
static void
extBitFromInt (xmlXPathParserContextPtr ctxt, int nargs)
{
    xmlChar *res;
    xmlXPathObjectPtr xop;
    int width = 0, len;

    if (nargs != 1 && nargs != 2) {
	xmlXPathSetArityError(ctxt);
	return;
    }

    /* Pop args in reverse order */
    if (nargs == 2) {
	width = xmlXPathPopNumber(ctxt);
	if (width < 0 || xmlXPathCheckError(ctxt))
	    return;
    }

    xop = valuePop(ctxt);
    if (xop == NULL || xmlXPathCheckError(ctxt))
	return;
    res = extBitStringVal(ctxt, xop);
    if (res == NULL)
	return;

    len = xmlStrlen(res);
    if (width > len) {
	res = xmlRealloc(res, width + 1);
	if (res) {
	    int count = width - len;
	    memmove(res + count, res, len + 1);
	    memset(res, '0', count);
	}
    }

    xmlXPathReturnString(ctxt, res);
}
Exemple #29
0
/**
 * xmlBufAdd:
 * @buf:  the buffer to dump
 * @str:  the #xmlChar string
 * @len:  the number of #xmlChar to add
 *
 * Add a string range to an XML buffer. if len == -1, the length of
 * str is recomputed.
 *
 * Returns 0 successful, a positive error code number otherwise
 *         and -1 in case of internal or API error.
 */
int
xmlBufAdd(xmlBufPtr buf, const xmlChar *str, int len) {
    unsigned int needSize;

    if ((str == NULL) || (buf == NULL) || (buf->error))
	return -1;
    CHECK_COMPAT(buf)

    if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return -1;
    if (len < -1) {
#ifdef DEBUG_BUFFER
        xmlGenericError(xmlGenericErrorContext,
		"xmlBufAdd: len < 0\n");
#endif
	return -1;
    }
    if (len == 0) return 0;

    if (len < 0)
        len = xmlStrlen(str);

    if (len < 0) return -1;
    if (len == 0) return 0;

    needSize = buf->use + len + 2;
    if (needSize > buf->size){
        if (!xmlBufResize(buf, needSize)){
	    xmlBufMemoryError(buf, "growing buffer");
            return XML_ERR_NO_MEMORY;
        }
    }

    memmove(&buf->content[buf->use], str, len*sizeof(xmlChar));
    buf->use += len;
    buf->content[buf->use] = 0;
    UPDATE_COMPAT(buf)
    return 0;
}
Exemple #30
0
/**
 * xslDbgShellDelParam:
 * @arg: A single white space trimmed parameter number to look for
 * 
 * Delet a libxslt parameter to be sent to libxslt later on
 *
 * Returns 1 if able to delete parameter @name,
 *         0 otherwise
 */
int
xslDbgShellDelParam(xmlChar * arg)
{
    int result = 0;
    static const char *errorPrompt = I18N_NOOP("Failed to delete parameter");
    long paramId;
    xmlChar *opts[2];

    if (!arg) {
	xsldbgGenericErrorFunc(i18n("Error: Invalid arguments for the command %1.\n").arg("delparam"));
    }else{
	if (xmlStrLen(arg) > 0) {
	    if (splitString(arg, 1, opts) == 1) {
		if ((xmlStrlen(opts[0]) == 0) ||
			!sscanf((char *) opts[0], "%ld", &paramId)) {
		    xsldbgGenericErrorFunc(i18n("Error: Unable to parse %1 as a line number.\n").arg(xsldbgText(opts[0])));
		} else {
		    result =
			arrayListDelete(optionsGetParamItemList(), paramId);
		    if (!result)
			xsldbgGenericErrorFunc(i18n("Error: Unable to find parameter %1.\n").arg(paramId));
		}
	    } else {
		xsldbgGenericErrorFunc(i18n("Error: Invalid arguments for the command %1.\n").arg("delparam"));
	    }
	} else {
	    /* Delete all parameters */
	    arrayListEmpty(optionsGetParamItemList());
	    result = 1;
	}
    }
    if (!result)
        xsldbgGenericErrorFunc(QString("Error: %1\n").arg(i18n(errorPrompt)));
    else
         xsldbgGenericErrorFunc("\n");

    return result;
}