Re: [gmime-devel] Help Need parse Multipart data with help of GMIME



Hi ,

Thanks Jeffrey  for your quick reply .
I little bit found what is the problem,even though passing multipart data buffer Gmime object created is of content type is text/plain .
This I found out by
code snippet::
const GMimeContentType* gmimecontentType = g_mime_object_get_content_
type(mimeObject);
        if(gmimecontentType)
        {
            string gmimeType = gmimecontentType->type ;
            string gmimesubcontentType = gmimecontentType->subtype ;
        }
----------
here I found value are gmimeType is text and gmimesubcontentType is plain

I am creating the GmimeObject to parse this curl buffer(i.e. end with /r/n)

Data buffer ::
--abcd1234wxyz7890
Content-Type: text/vnd.wap.wml

<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<template>
<do type="prev" name="sb" label="Go Back"><prev/></do>
<do type="accept" name="PostResults" label="PostResults">
<go href=""
</template>

<card id="C1" title="Gif Image">
<h3>Gif Image in WML page</h3>

<p> verify that the image is displayed below.<br/>
<img src="" href="http://testsuite.nokia-boston.com/content/MultipartMixed/MultipartMixed_images/web1.gif" target="_blank">http://testsuite.nokia-boston.com/content/MultipartMixed/MultipartMixed_images/web1.gif" alt="Gif image"/><br/>

</p>
<p>
<anchor>
Post Results
<go href=""
</go>
</anchor>
</p>
</card>


</wml>

--abcd1234wxyz7890
Content-Type: image/gif
Content-Location: http://testsuite.nokia-boston.com/content/MultipartMixed/MultipartMixed_images/web1.gif

GIF89a

--------------------------------
- how I parse this buffer using gmime  ?

I am doing like this
code snippet::
            g_mime_init(0); //only one time
            g_mime_charset_map_init();
            g_mime_iconv_init();
//try to make GmimeObject so i can do parsing operation this
GMimeStream* stream = g_mime_stream_mem_new_with_buffer(static_cast<char*>(ptr),totalSize);

g_mime_stream_seek (stream, 0, GMIME_STREAM_SEEK_END);
g_mime_stream_write (stream, "\r\n", 1); //  as this curl buffer \r\n giving it uses line endings

g_mime_stream_reset (stream);   
GMimeParser* parser = g_mime_parser_new_with_stream(stream);
GMimeObject* mimeObject = g_mime_parser_construct_part(parser);
//checking the content type -Expected it must be mutipart/mixed(I pass above data buffer in this )
if(gmimecontentType)
        {
            string gmimeType = gmimecontentType->type ;
            string gmimesubcontentType = gmimecontentType->subtype ;
        }
//if is it mutipart
if (GMIME_IS_MULTIPART(mimeObject))
        {
        string multipartmainResourceType = g_mime_object_get_content_type_parameter(mimeObject, "type");
        }
Problem ::
1.I am following right way or any other way to make buffer of multipart data and parse this .
2.After passing mutipart buffer this must  true on
GMIME_IS_MULTIPART(..) ,but i am getting  false value .

as I am beginner in using  of gmime parser ,please suggest me if i completely on wrong way  .

Regards & thanks
vaibhav gurav


On Wed, Mar 10, 2010 at 7:49 PM, Jeffrey Stedfast <fejj novell com> wrote:
On 03/10/2010 12:03 AM, vaibhav gurav wrote:
>
> Hi ,
> I am try to parse the multipart data (which comes from N/W) on your
> any url response .
> when the response is multipart I wanted to parse this with help of
> gmime parser and send each part to browser
> Main problem ::
> how to check data coming is multipart or not
> I am doing like this -
>       //initialize the gmime
>             g_mime_init(0);
>             g_mime_charset_map_init();
>             g_mime_iconv_init();

just an FYI, but g_mime_init() calls g_mime_charset_map_init() and
g_mime_iconv_init() for you, so you don't need to call them again.

>       //checking the data coming is multipart or not (void * ptr -
> response data  )
>                GMimeStream* stream =
> g_mime_stream_mem_new_with_buffer(static_cast<char*>(ptr),dataSize);
>                GMimeParser* parser =
> g_mime_parser_new_with_stream(stream);
>                GMimeObject* mimeObject =
> g_mime_parser_construct_part(parser);
>     //checking Gmime Object and and find out content type
>                 if (mineObject && GMIME_IS_MULTIPART(mimeObject))
>                     string m_mainResourceType =
> g_mime_object_get_content_type_parameter(mimeObject, "type");
> ----------------------------------------
>
> is it correct the above code .

yes, it looks correct.

> if yes then still I am facing one problem even though response is
> multipart(i.e. multipart/mixed) the out of
> GMIME_IS_MULTIPART(mimeObject) is getting null(i.e. fail ).

From a quick glance at gmime-parser.c, it looks like the parser state is
getting set to GMIME_PARSER_STATE_ERROR (that's the only way it will
return NULL). For g_mime_parser_construct_part(), the only way for this
to get set is if there is no blank line following the headers (e.g.
unexpected end of stream). A simple solution for you would be to do the
following:

GMimeStream* stream =
g_mime_stream_mem_new_with_buffer(static_cast<char*>(ptr),dataSize);
g_mime_stream_seek (stream, 0, GMIME_STREAM_SEEK_END);
g_mime_stream_write (stream, "\n", 1); // or \r\n if the buffer you are
giving it uses CRLF line endings
g_mime_stream_reset (stream);

Then pass it off to the parser like you do in the code you pasted.

Hope that helps,

Jeff




--
Regards
Vaibhav A. Gurav
Azingo soft system Pune
'स्टोन्स वेअर थ्रोन अॅट मी, आय टर्न देम इन्टू माइलस्टोन्स', -सचिन तेंडुलकर


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]