Hi Marcel
> Hi Mohamed,
> 
> > Add new API to support http download.
> > ---
> >  gweb/gweb.h |   12 ++++++++++++
> >  1 files changed, 12 insertions(+), 0 deletions(-)
> > 
> > diff --git a/gweb/gweb.h b/gweb/gweb.h
> > index 1ab2a9f..61e488c 100644
> > --- a/gweb/gweb.h
> > +++ b/gweb/gweb.h
> > @@ -38,10 +38,19 @@ typedef enum {
> >     G_WEB_METHOD_GET,
> >  } GWebMethod;
> >  
> > +typedef enum {
> > +   G_WEB_DATA_HEADER,
> > +   G_WEB_DATA_BODY,
> > +} GWebDataType;
> > +
> >  typedef void (*GWebResultFunc)(uint16_t status, gpointer user_data);
> >  
> >  typedef void (*GWebDebugFunc)(const char *str, gpointer user_data);
> >  
> > +typedef gboolean (*GWebReceivedFunc)(const guint8 *str, int len,
> > +                                           GWebDataType data_type,
> > +                                           gpointer user_data);
> > +
> 
> so I am thinking this becomes a little bit too complicated and we are
> overloading this. Here is my idea on how to make this simpler.
> 
> struct _GWebResult;
> 
> typedef struct _GWebResult GWebResult;
> 
> 
> typedef gboolean (*GWebResultFunc) (guint16 status, GWebResult *result,
>                                               gpointer user_data);
> 
> guint g_web_request(GWeb, GWebMethod method, const char *url,
>                               GWebResultFunc, gpointer user_data);
> 
> So essentially we are creating a new GWebResult object that represents
> our transaction/request.
> 
> Then we can have these functions to be used inside the result callback.
> 
> gboolean g_web_result_get_header(GWebResult *result,
>                               const char *header, const char **value);
> 
> gboolean g_web_result_get_fragment(GWebResult *result,
>                               const guint8 **fragment, gsize *length);
> 
> The get_header function will be always valid since we keep all headers
> in the GWebResult object for the time of the transaction. And the
> get_fragment returns the current buffer value.
> 
> And of course the result function has a return value. If returning FALSE
> then we just stop the transaction right away. So after we received the
> headers we can call this once with empty fragment buffer and when we
> have all details we just stop it. If we return TRUE then the transaction
> continues until we have received the full body.
> 
> Also the status will indicate if we are done or not. A status of 100
> indicates that there is more to come. And every other status is either
> 200 for success or an error code. Of course the return value only
> matters if the status is 100 since otherwise the transaction is over
> anyway.
> 
> What do you think?
> 
> Regards
> 
> Marcel
> 

So now we have one notification function which will be used by GWeb to
notify the user. So I guess GWeb will call GWebResultFunc evey time we
receive a payload right?
This new API will be more flixible to user since they can get the
payload on chunk or wait and get the whole payload at once but it will
be more work in GWeb since we have to buffer until user ask for data.

One more question in gboolean g_web_result_get_fragment(GWebResult
*result, const guint8 **fragment, gsize *length);
I assume the user will responsible to release the memory here right?

I will start on adding this change and please let me know if any of my
assumption are wrong so I dont have to redo.
Thanks
Mohamed

_______________________________________________
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman

Reply via email to