コード例 #1
0
ファイル: wbxml_buffers.c プロジェクト: sweetleon/wbxml2
WBXML_DECLARE(WB_BOOL) wbxml_buffer_append_mb_uint_32(WBXMLBuffer *buffer, WB_ULONG value)
{
    /**
     * A uintvar is defined to be up to 32 bits large
     * so it will fit in 5 octets (to handle continuation bits) 
     */
    WB_UTINY octets[5];
    WB_LONG i = 0, start = 0;

    if ((buffer == NULL) || buffer->is_static)
        return FALSE;

    /**
     * Handle last byte separately; it has no continuation bit,
     * and must be encoded even if value is 0. 
     */
    octets[4] = (WB_UTINY) (value & 0x7f);
    value >>= 7;

    for (i = 3; value > 0 && i >= 0; i--) {
        octets[i] = (WB_UTINY) (0x80 | (value & 0x7f));
        value >>= 7;
    }
    start = i + 1;

    return wbxml_buffer_append_data(buffer, octets + start, 5 - start);
}
コード例 #2
0
ファイル: wbxml_buffers.c プロジェクト: renu555/libwbxml
WBXML_DECLARE(WBXMLError) wbxml_buffer_decode_base64(WBXMLBuffer *buffer)
{
    WB_UTINY   *result = NULL;
    WB_LONG     len    = 0;
    WBXMLError  ret    = WBXML_OK;
    
    if ( (buffer == NULL) || (buffer->is_static) ) {
        return WBXML_ERROR_INTERNAL;
    }

    wbxml_buffer_no_spaces(buffer);
    
    if ((len = wbxml_base64_decode((const WB_UTINY *) wbxml_buffer_get_cstr(buffer),
                                   wbxml_buffer_len(buffer), &result)) <= 0)
    {
        return WBXML_ERROR_B64_DEC;
    }
    
    /* Reset buffer */
    wbxml_buffer_delete(buffer, 0, wbxml_buffer_len(buffer));
    
    /* Set binary data */
    if (!wbxml_buffer_append_data(buffer, result, len)) {
        ret = WBXML_ERROR_NOT_ENOUGH_MEMORY;
    }
    
    wbxml_free(result);
    
    return ret;
}
コード例 #3
0
ファイル: wbxml_buffers.c プロジェクト: sweetleon/wbxml2
WBXML_DECLARE(WB_BOOL) wbxml_buffer_append(WBXMLBuffer *dest, WBXMLBuffer *buff)
{
    if ((dest == NULL) || dest->is_static)
        return FALSE;

    if (buff == NULL)
        return TRUE;

    return wbxml_buffer_append_data(dest, wbxml_buffer_get_cstr(buff), wbxml_buffer_len(buff));
}
コード例 #4
0
ファイル: wbxml_buffers.c プロジェクト: sweetleon/wbxml2
WBXML_DECLARE(WB_BOOL) wbxml_buffer_append_cstr_real(WBXMLBuffer *buffer, const WB_UTINY *data)
{
    if ((buffer == NULL) || buffer->is_static) {
        return FALSE;
    }

    if (data == NULL)
        return TRUE;

    return wbxml_buffer_append_data(buffer, data, WBXML_STRLEN(data));
}
コード例 #5
0
void wbxml_tree_clb_xml_characters(void           *ctx,
                                   const XML_Char *ch,
                                   int             len)
{
    WBXMLTreeNode *node;
    WBXMLTreeClbCtx *tree_ctx = (WBXMLTreeClbCtx *) ctx;

    WBXML_DEBUG((WBXML_PARSER, "Expat text callback"));

    if (tree_ctx->expat_utf16) {
        /** @todo Convert from UTF-16 to UTF-8 */
    }

    /* Check for Error */
    if (tree_ctx->error != WBXML_OK)
        return;

    /* Are we skipping a whole node ? */
    if (tree_ctx->skip_lvl > 0)
        return;

#if defined ( WBXML_SUPPORT_SYNCML )
    /* Specific treatment for SyncML */
    switch (wbxml_tree_node_get_syncml_data_type(tree_ctx->current)) {
    case WBXML_SYNCML_DATA_TYPE_DIRECTORY_VCARD:
    case WBXML_SYNCML_DATA_TYPE_VCALENDAR:
    case WBXML_SYNCML_DATA_TYPE_VCARD:
    case WBXML_SYNCML_DATA_TYPE_VOBJECT:
        /* SyncML has some real design bugs
         * because the authors of the specification did not understand XML.
         *
         * There must be a hack to preserve the CRLFs of vFormat objects.
         * The only chance to do this is the detection of the vFormat itself
         * and the conversion of every LF to a CRLF.
         *
         * The line breaks are always in a single text node.
         * So a CR is appended to get a CRLF at the end.
         */

        if (len == 1 && ch[0] == '\n') /* line break - LF */
        {
            ch = "\r\n";
            len = 2;
        }

    /* Do not break here.
     * The CDATA handling is required for vFormat objects too.
     */
    case WBXML_SYNCML_DATA_TYPE_CLEAR:
        /*
         * Add a missing CDATA section node
         *
         * Example:
         * <Add>
         *   <CmdID>6</CmdID>
         *   <Meta><Type xmlns='syncml:metinf'>text/x-vcard</Type></Meta>
         *   <Item>
         *     <Source>
         *         <LocURI>pas-id-3F4B790300000000</LocURI>
         *     </Source>
         *     <Data>BEGIN:VCARD
         *  VERSION:2.1
         *  X-EVOLUTION-FILE-AS:Ximian, Inc.
         *  N:
         *  LABEL;WORK;ENCODING=QUOTED-PRINTABLE:401 Park Drive  3 West=0ABoston, MA
         *  02215=0AUSA
         *  TEL;WORK;VOICE:(617) 236-0442
         *  TEL;WORK;FAX:(617) 236-8630
         *  EMAIL;INTERNET:[EMAIL PROTECTED]
         *  URL:www.ximian.com/
         *  ORG:Ximian, Inc.
         *  NOTE:Welcome to the Ximian Addressbook.
         *  UID:pas-id-3F4B790300000000
         *  END:VCARD</Data>
         *   </Item>
         * </Add>
         *
         * The end of CDATA section is assumed to be reached when parsing the end
         * of </Data> element.
         *
         * This kind of document is erroneous, but we must handle it.
         * Normally, this should be:
         *
         *  ...
         *     <Data><!CDATA[[BEGIN:VCARD
         *  VERSION:2.1
         *  X-EVOLUTION-FILE-AS:Ximian, Inc.
         *  ...
         *  UID:pas-id-3F4B790300000000
         *  END:VCARD
         *  ]]></Data>
         *  ...
         */

        /*
         * We add a missing CDATA section if we are not already in a CDATA section.
         *
         * We don't add a CDATA section if we have already added a CDATA section. This
         * permits to correctly handle good XML documents like this:
         *
         *  ...
         *     <Data><!CDATA[[BEGIN:VCARD
         *  VERSION:2.1
         *  X-EVOLUTION-FILE-AS:Ximian, Inc.
         *  ...
         *  UID:pas-id-3F4B790300000000
         *  END:VCARD
         *  ]]>
         *     </Data>
         *  ...
         *
         * In this example, the spaces beetwen "]]>" and "</Data>" must not be added
         * to a CDATA section.
         */
        if ((tree_ctx->current != NULL) &&
                (tree_ctx->current->type != WBXML_TREE_CDATA_NODE) &&
                !((tree_ctx->current->children != NULL) &&
                  (tree_ctx->current->children->type == WBXML_TREE_CDATA_NODE)))
        {
            /* Add CDATA Node */
            tree_ctx->current = wbxml_tree_add_cdata(tree_ctx->tree, tree_ctx->current);
            if (tree_ctx->current == NULL) {
                tree_ctx->error = WBXML_ERROR_INTERNAL;
                return;
            }
        }

        /* Now we can add the Text Node */
        break;

    default:
        /* NOP */
        break;
    } /* switch */
#endif /* WBXML_SUPPORT_SYNCML */

    /* We expect that "byte array" or BLOB types are
     * encoded in Base 64 in the XML code, since they may contain binary data.
     */

    node = tree_ctx->current;
    if (node && node->type == WBXML_TREE_ELEMENT_NODE &&
            node->name->type == WBXML_VALUE_TOKEN &&
            node->name->u.token->options & WBXML_TAG_OPTION_BINARY)
    {
        WBXML_DEBUG((WBXML_PARSER, "    Binary tag: Caching base64 encoded data for later conversion."));
        if (node->content == NULL)
        {
            node->content = wbxml_buffer_create(ch, len, 1);
            if (node->content == NULL)
                tree_ctx->error = WBXML_ERROR_NOT_ENOUGH_MEMORY;
        } else {
            if (!wbxml_buffer_append_data(node->content, ch, len))
                tree_ctx->error = WBXML_ERROR_NOT_ENOUGH_MEMORY;
        }
        return;
    }

    /* Add Text Node */
    if (wbxml_tree_add_text(tree_ctx->tree,
                            tree_ctx->current,
                            (const WB_UTINY*) ch,
                            len) == NULL)
    {
        tree_ctx->error = WBXML_ERROR_INTERNAL;
    }
}