Changeset 28

Show
Ignore:
Timestamp:
02/27/07 13:32:08 (2 years ago)
Author:
inz
Message:

Add error reporting to blog plugin API.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • maemo-blog/trunk/Makefile

    r26 r28  
    11# Makefile for maemo-blog 
     2 
     3CLEAN = $(subst /,_,$(subst -,_,$(subst .,_,$(1)))) 
    24 
    35VERSION := $(shell head -n1 debian/changelog | sed -e 's/^.*(\([^-]*\)\(-.*\)*).*$$/\1/') 
     
    2527 
    2628PACKAGE=maemo-blog 
    27 TARGETS=maemo_blog libmetaweblog.la libblogger.la 
     29TARGETS=maemo-blog libmetaweblog.la libblogger.la 
    2830 
    2931WARNINGS += -Werror 
     
    5355maemo_blog_LDFLAGS += `pkg-config gconf-2.0 gtk+-2.0 --libs` -export-dynamic 
    5456 
    55 maemo_blog_SOURCES := main.c plugin-loader.c accounts.c login.c gui.c 
    56 maemo_blog_HEADERS := blog.h blog-plugin.h plugin-loader.h accounts.h login.h gui.h 
     57maemo_blog_SOURCES := main.c plugin-loader.c accounts.c login.c gui.c blog.c 
     58maemo_blog_HEADERS := blog.h blog-plugin.h plugin-loader.h accounts.h login.h gui.h mb-mainview.h mb-view.h mb-textview.h 
    5759maemo_blog_DESKTOP := maemo-blog.desktop 
    5860maemo_blog_PIXMAPS := maemo-blog.png 
     
    6062libmetaweblog_la_CFLAGS += $(CFLAGS) `pkg-config glib-2.0 libsoup-2.2 --cflags` 
    6163libmetaweblog_la_LDFLAGS = `pkg-config glib-2.0 libsoup-2.2 --libs` -module -shared -rpath $(LIBDIR) -avoid-version 
    62 libmetaweblog_la_SOURCES := blog-metaweblog.c 
    63 libmetaweblog_la_HEADERS := blog-plugin.h 
     64libmetaweblog_la_SOURCES := blog-metaweblog.c blog.c 
     65libmetaweblog_la_HEADERS := blog-plugin.h blog.h 
    6466libmetaweblog_la_DIR := $(PLUGINDIR) 
    6567 
    6668libblogger_la_CFLAGS += $(CFLAGS) `pkg-config glib-2.0 libsoup-2.2 --cflags` 
    6769libblogger_la_LDFLAGS = `pkg-config glib-2.0 libsoup-2.2 --libs` -module -shared -rpath $(LIBDIR) -avoid-version 
    68 libblogger_la_SOURCES := blog-blogger.c 
    69 libblogger_la_HEADERS := blog-plugin.h 
     70libblogger_la_SOURCES := blog-blogger.c blog.c 
     71libblogger_la_HEADERS := blog-plugin.h blog.h 
    7072libblogger_la_DIR := $(PLUGINDIR) 
    7173 
     
    7779all: $(patsubst %, %.build, ${TARGETS}) 
    7880 
    79 $(PART): $(patsubst %.c, %.lo, ${$(subst .,_,${PART})_SOURCES}) ${$(subst .,_,${PART})_PC} 
     81$(PART): $(patsubst %.c, %.lo, ${$(call CLEAN,${PART})_SOURCES}) ${$(call CLEAN,${PART})_PC} 
    8082        @echo -n "  Linking..." 
    81         @$(LIBTOOL) --quiet --mode=link $(CC) $(patsubst %.c, %.lo, ${$(subst .,_,${PART})_SOURCES}) -o $@ ${$(subst .,_,${PART})_LDFLAGS} 
     83        @$(LIBTOOL) --quiet --mode=link $(CC) $(patsubst %.c, %.lo, ${$(call CLEAN,${PART})_SOURCES}) -o $@ ${$(call CLEAN,${PART})_LDFLAGS} 
    8284        @echo "done." 
    8385 
     
    8688        @$(MAKE) LIBDIR="$(LIBDIR)" PLUGINDIR="$(PLUGINDIR)" -s PART="$(patsubst %.build,%,$@)" $(patsubst %.build,%,$@) 
    8789 
    88 %.lo: %.c $($(subst .,_,${PART})_HEADERS) 
     90%.lo: %.c $($(call CLEAN,${PART})_HEADERS) 
    8991        @echo -n "  Building $@..." 
    90         @$(LIBTOOL) --quiet --mode=compile $(CC) $(CFLAGS) $($(subst .,_,${PART})_CFLAGS) -c $< -o $@ 
     92        @$(LIBTOOL) --quiet --mode=compile $(CC) $(CFLAGS) $($(call CLEAN,${PART})_CFLAGS) -c $< -o $@ 
    9193 
    9294        @echo "done." 
     
    103105 
    104106%.clean: 
    105         @libtool --quiet --mode=clean rm -f $(patsubst %.c, %.lo, ${$(subst .,_,$(patsubst %.clean,%,$@))_SOURCES}) 
     107        @libtool --quiet --mode=clean rm -f $(patsubst %.c, %.lo, ${$(call CLEAN,$(patsubst %.clean,%,$@))_SOURCES}) 
    106108 
    107109.PHONY: distclean 
     
    114116 
    115117%.install: %.build 
    116         @$(INSTALL_DIR) ${$(subst .,_,$(patsubst %.install,%,$@))_DIR} 
    117         @libtool --quiet --mode=install $(INSTALL) $(patsubst %.install,%,$@) ${$(subst .,_,$(patsubst %.install,%,$@))_DIR} 
    118         @if [ x != "x${$(subst .,_,$(patsubst %.install,%,$@))_PC}" ]; then $(INSTALL_DIR) ${$(subst .,_,$(patsubst %.install,%,$@))_PCDIR}; $(INSTALL_DATA) ${$(subst .,_,$(patsubst %.install,%,$@))_PC} ${$(subst .,_,$(patsubst %.install,%,$@))_PCDIR}; fi 
    119         @if [ x != "x${$(subst .,_,$(patsubst %.install,%,$@))_DESKTOP}" ]; then $(INSTALL_DIR) ${$(subst .,_,$(patsubst %.install,%,$@))_DESKTOPDIR}; $(INSTALL_DATA) ${$(subst .,_,$(patsubst %.install,%,$@))_DESKTOP} ${$(subst .,_,$(patsubst %.install,%,$@))_DESKTOPDIR}; fi 
    120         @if [ x != "x${$(subst .,_,$(patsubst %.install,%,$@))_PIXMAPS}" ]; then $(INSTALL_DIR) ${$(subst .,_,$(patsubst %.install,%,$@))_PIXMAPDIR}; $(INSTALL_DATA) ${$(subst .,_,$(patsubst %.install,%,$@))_PIXMAPS} ${$(subst .,_,$(patsubst %.install,%,$@))_PIXMAPDIR}; fi 
    121         @if [ x != "x${$(subst .,_,$(patsubst %.install,%,$@))_INCLUDES}" ]; then $(INSTALL_DIR) ${$(subst .,_,$(patsubst %.install,%,$@))_INCLUDEDIR}; $(INSTALL_DATA) ${$(subst .,_,$(patsubst %.install,%,$@))_INCLUDES} ${$(subst .,_,$(patsubst %.install,%,$@))_INCLUDEDIR}; fi 
     118        @$(INSTALL_DIR) ${$(call CLEAN,$(patsubst %.install,%,$@))_DIR} 
     119        @libtool --quiet --mode=install $(INSTALL) $(patsubst %.install,%,$@) ${$(call CLEAN,$(patsubst %.install,%,$@))_DIR} 
     120        @if [ x != "x${$(call CLEAN,$(patsubst %.install,%,$@))_PC}" ]; then $(INSTALL_DIR) ${$(call CLEAN,$(patsubst %.install,%,$@))_PCDIR}; $(INSTALL_DATA) ${$(call CLEAN,$(patsubst %.install,%,$@))_PC} ${$(call CLEAN,$(patsubst %.install,%,$@))_PCDIR}; fi 
     121        @if [ x != "x${$(call CLEAN,$(patsubst %.install,%,$@))_DESKTOP}" ]; then $(INSTALL_DIR) ${$(call CLEAN,$(patsubst %.install,%,$@))_DESKTOPDIR}; $(INSTALL_DATA) ${$(call CLEAN,$(patsubst %.install,%,$@))_DESKTOP} ${$(call CLEAN,$(patsubst %.install,%,$@))_DESKTOPDIR}; fi 
     122        @if [ x != "x${$(call CLEAN,$(patsubst %.install,%,$@))_PIXMAPS}" ]; then $(INSTALL_DIR) ${$(call CLEAN,$(patsubst %.install,%,$@))_PIXMAPDIR}; $(INSTALL_DATA) ${$(call CLEAN,$(patsubst %.install,%,$@))_PIXMAPS} ${$(call CLEAN,$(patsubst %.install,%,$@))_PIXMAPDIR}; fi 
     123        @if [ x != "x${$(call CLEAN,$(patsubst %.install,%,$@))_INCLUDES}" ]; then $(INSTALL_DIR) ${$(call CLEAN,$(patsubst %.install,%,$@))_INCLUDEDIR}; $(INSTALL_DATA) ${$(call CLEAN,$(patsubst %.install,%,$@))_INCLUDES} ${$(call CLEAN,$(patsubst %.install,%,$@))_INCLUDEDIR}; fi 
    122124 
    123125%: %.in Makefile debian/changelog 
  • maemo-blog/trunk/blog-blogger.c

    r26 r28  
    102102        if (soup_xmlrpc_value_array_get_iterator(value, &iter)) { 
    103103                while (iter) { 
    104                         Blog *blog = g_new0(Blog, 1); 
     104                        Blog *blog = blog_new(); 
    105105                        GHashTable *hash; 
    106106                        SoupXmlrpcValue *val; 
     
    128128                } 
    129129        } else { 
    130                         Blog *blog = g_new0(Blog, 1); 
     130                        Blog *blog = blog_new(); 
    131131                        GHashTable *hash; 
    132132                        SoupXmlrpcValue *val; 
     
    155155        } 
    156156 
    157         clo->cb(retval, clo->user_data); 
     157        clo->cb(retval, NULL, clo->user_data); 
    158158        g_free(clo->uri); 
    159159        g_free(clo->user); 
     
    238238                soup_xmlrpc_value_get_boolean(value, &status); 
    239239        } 
    240         clo->cb(clo->blog, clo->post, status, clo->user_data); 
     240        clo->cb(clo->blog, clo->post, status, NULL, clo->user_data); 
    241241        g_free(clo); 
    242242} 
     
    355355        struct BlogBloggerFetchedClosure *clo = user_data; 
    356356 
    357         clo->cb(clo->blog, clo->user_data); 
     357        clo->cb(clo->blog, NULL, clo->user_data); 
    358358 
    359359        return FALSE; 
     
    423423        } 
    424424 
    425         clo->cb(clo->blog, clo->user_data); 
     425        clo->cb(clo->blog, NULL, clo->user_data); 
    426426        g_free(clo); 
    427427} 
  • maemo-blog/trunk/blog-metaweblog.c

    r26 r28  
    1313        SoupSession *session; 
    1414}; 
     15 
     16static gint _field_compare(gconstpointer a, gconstpointer b) 
     17{ 
     18        const BlogParameter *pa = a; 
     19        const BlogParameter *pb = b; 
     20 
     21        return strcmp(pa->name, pb->name); 
     22} 
    1523 
    1624static BlogCategory *category_lookup(Blog *blog, const gchar *name) 
     
    130138        SoupXmlrpcValueArrayIterator *iter; 
    131139 
     140        if (soup_xmlrpc_response_is_fault(response)) { 
     141                BlogPluginError error = { 0, NULL }; 
     142                error.error_string = "Unknown error"; 
     143                error.error_code = 404; 
     144                clo->cb(retval, &error, clo->user_data); 
     145                g_free(clo->uri); 
     146                g_free(clo->user); 
     147                g_free(clo->pass); 
     148                g_free(clo); 
     149                return; 
     150        } 
     151 
    132152        soup_xmlrpc_value_array_get_iterator(value, &iter); 
    133153 
    134154        while (iter) { 
    135                 Blog *blog = g_new0(Blog, 1); 
     155                Blog *blog = blog_new(); 
    136156                GHashTable *hash; 
    137157                SoupXmlrpcValue *val; 
     
    165185        } 
    166186 
    167         clo->cb(retval, clo->user_data); 
     187        clo->cb(retval, NULL, clo->user_data); 
    168188        g_free(clo->uri); 
    169189        g_free(clo->user); 
     
    248268                soup_xmlrpc_value_get_boolean(value, &status); 
    249269        } 
    250         clo->cb(clo->blog, clo->post, status, clo->user_data); 
     270        clo->cb(clo->blog, clo->post, status, NULL, clo->user_data); 
    251271        g_free(clo); 
    252272} 
     
    259279        struct MetaweblogPluginData *data = blog->plugin->plugin_data; 
    260280        SoupXmlrpcMessage *msg; 
     281        GSList *param_copy = NULL; 
     282        GSList *struct_stack = g_slist_prepend(NULL, g_strdup("")); 
     283        guint top_len = 0; 
    261284 
    262285        if (!post || !post->content) { 
     
    314337        soup_xmlrpc_message_end_array(msg); 
    315338        soup_xmlrpc_message_end_member(msg); 
    316         for (iter = post->extra_fields; iter; iter = iter->next) { 
     339        param_copy = g_slist_sort(g_slist_copy(post->extra_fields), 
     340                        _field_compare); 
     341        for (iter = param_copy; iter; iter = iter->next) { 
    317342                BlogParameter *parm = iter->data; 
    318                 soup_xmlrpc_message_start_member(msg, parm->name); 
     343                gchar *temp = parm->name; 
     344                while (strncmp(struct_stack->data, parm->name, 
     345                                        top_len)) { 
     346                        soup_xmlrpc_message_end_struct(msg); 
     347                        soup_xmlrpc_message_end_member(msg); 
     348                        g_free(struct_stack->data); 
     349                        struct_stack = g_slist_delete_link(struct_stack, 
     350                                        struct_stack); 
     351                } 
     352                while ((temp = strchr(parm->name + top_len, 
     353                                                ':'))) { 
     354                        gchar *struct_name = 
     355                                g_strndup(parm->name + 
     356                                                top_len, 
     357                                                temp - parm->name - 
     358                                                top_len); 
     359                        soup_xmlrpc_message_start_member(msg, struct_name); 
     360                        g_free(struct_name); 
     361                        top_len = temp - parm->name + 1; 
     362                        struct_name = g_strndup(parm->name, top_len); 
     363                        soup_xmlrpc_message_start_struct(msg); 
     364                        struct_stack = g_slist_prepend(struct_stack, 
     365                                        struct_name); 
     366                } 
     367                soup_xmlrpc_message_start_member(msg, parm->name + strlen(struct_stack->data)); 
    319368                switch (G_VALUE_TYPE(&parm->value)) { 
    320369                        case G_TYPE_STRING: 
     
    343392                soup_xmlrpc_message_end_member(msg); 
    344393        } 
    345         soup_xmlrpc_message_end_struct(msg); 
     394        while (struct_stack) { 
     395                soup_xmlrpc_message_end_struct(msg); 
     396                g_free(struct_stack->data); 
     397                struct_stack = g_slist_delete_link(struct_stack, struct_stack); 
     398        } 
    346399        soup_xmlrpc_message_end_param(msg); 
    347400        soup_xmlrpc_message_start_param(msg); 
     
    536589        } 
    537590 
    538         clo->cb(clo->blog, clo->user_data); 
     591        clo->cb(clo->blog, NULL, clo->user_data); 
    539592        g_free(clo); 
    540593} 
     
    636689        } 
    637690 
    638         clo->cb(clo->blog, clo->user_data); 
     691        clo->cb(clo->blog, NULL, clo->user_data); 
    639692        g_free(clo); 
    640693} 
     
    694747        soup_xmlrpc_value_get_string(value, &url); 
    695748 
    696         clo->cb(clo->blog, clo->image_name, url, clo->user_data); 
     749        clo->cb(clo->blog, clo->image_name, url, NULL, clo->user_data); 
    697750        g_free(url); 
    698751        g_free(clo->image_name); 
  • maemo-blog/trunk/blog-plugin.h

    r2 r28  
    88#include "blog.h" 
    99 
    10 typedef void (*BlogConnectedCb)(Blog **blogs, gpointer user_data); 
    11 typedef void (*BlogFetchCb)(Blog *blog, gpointer user_data); 
    12 typedef void (*BlogPostCb)(Blog *blog, BlogPost *post, gboolean status, gpointer user_data); 
    13 typedef void (*BlogUploadCb)(Blog *blog, const gchar *image_name, const gchar *image_path, gpointer user_data); 
     10typedef struct _BlogPluginError BlogPluginError; 
     11struct _BlogPluginError { 
     12        gint error_code; 
     13        const gchar *error_string; 
     14}; 
     15 
     16typedef void (*BlogConnectedCb)(Blog **blogs, const BlogPluginError *error, gpointer user_data); 
     17typedef void (*BlogFetchCb)(Blog *blog, const BlogPluginError *error, gpointer user_data); 
     18typedef void (*BlogPostCb)(Blog *blog, BlogPost *post, gboolean status, const BlogPluginError *error, gpointer user_data); 
     19typedef void (*BlogUploadCb)(Blog *blog, const gchar *image_name, const gchar *image_path, const BlogPluginError *error, gpointer user_data); 
    1420 
    1521struct _BlogPlugin { 
  • maemo-blog/trunk/blog.c

    r12 r28  
    11#include "blog.h" 
     2 
     3static void blog_free(Blog *blog); 
    24 
    35void blog_parameter_free(BlogParameter *param) 
     
    2426} 
    2527 
    26 void blog_free(Blog *blog) 
     28Blog *blog_new() { 
     29        Blog *retval = g_new0(Blog, 1); 
     30        retval->refcount = 1; 
     31        return retval; 
     32
     33 
     34void blog_ref(Blog *blog) { 
     35        blog->refcount++; 
     36
     37 
     38void blog_unref(Blog *blog) 
     39
     40        if (!(--blog->refcount)) { 
     41                blog_free(blog); 
     42        } 
     43
     44 
     45static void blog_free(Blog *blog) 
    2746{ 
    2847        g_free(blog->url); 
  • maemo-blog/trunk/blog.h

    r12 r28  
    2121        GSList *categories; 
    2222        GSList *posts; 
     23        gint refcount; 
    2324}; 
    2425 
     
    4445void blog_post_free(BlogPost *post); 
    4546void blog_category_free(BlogCategory *category); 
    46 void blog_free(Blog *blog); 
     47Blog *blog_new(void); 
     48void blog_ref(Blog *blog); 
     49void blog_unref(Blog *blog); 
    4750 
    4851#endif /* _BLOG_H_ */ 
  • maemo-blog/trunk/debian/changelog

    r26 r28  
     1maemo-blog (0.1.8) mistral; urgency=low 
     2 
     3  * Add error reporting to blog plugin API. 
     4 
     5 -- Santtu Lakkala <inz@inz.fi>  Tue, 27 Feb 2007 13:31:34 +0200 
     6 
    17maemo-blog (0.1.7) mistral; urgency=low 
    28 
  • maemo-blog/trunk/gui.c

    r12 r28  
    3434} 
    3535 
    36 static void _uploaded(Blog *blog, const gchar *image_name, const gchar *image_path, gpointer user_data) 
     36static void _uploaded(Blog *blog, const gchar *image_name, const gchar *image_path, const BlogPluginError *error, gpointer user_data) 
    3737{ 
    3838        struct UploadClosure *closure = user_data; 
    3939        (void)blog; 
     40        (void)error; 
    4041        (void)image_name; 
    4142        closure->name = g_strdup(image_path); 
     
    7374}; 
    7475 
    75 static void _posted(Blog *blog, BlogPost *post, gboolean status, gpointer user_data) 
     76static void _posted(Blog *blog, BlogPost *post, gboolean status, const BlogPluginError *error, gpointer user_data) 
    7677{ 
    7778        struct PostClosure *closure = user_data; 
    7879        (void)blog; 
    7980        (void)post; 
     81        (void)error; 
    8082 
    8183        closure->status = status; 
  • maemo-blog/trunk/maemo-blog.desktop

    r15 r28  
    22Encoding=UTF-8 
    33Categories=Application;Network; 
    4 Exec=/usr/bin/maemo_blog 
     4Exec=/usr/bin/maemo-blog 
    55Type=Application 
    66X-Osso-Type=application/x-executable 
  • maemo-blog/trunk/main.c

    r2 r28  
    3737} */ 
    3838 
    39 static void gotrec(Blog *blog, gpointer user_data) 
     39static void gotrec(Blog *blog, const BlogPluginError *error, gpointer user_data) 
    4040{ 
    4141        (void)blog; 
     42        (void)error; 
    4243        struct Foo *foo = user_data; 
    4344        gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(foo->pbar), 1.00); 
     
    4647} 
    4748 
    48 static void gotcat(Blog *blog, gpointer user_data) 
     49static void gotcat(Blog *blog, const BlogPluginError *error, gpointer user_data) 
    4950{ 
    5051        struct Foo *foo = user_data; 
     52        (void)error; 
    5153 
    5254        gtk_progress_bar_set_text(GTK_PROGRESS_BAR(foo->pbar), "Getting recent posts..."); 
     
    5557} 
    5658 
    57 static void connected(Blog **blogs, gpointer user_data) 
     59static void connected(Blog **blogs, const BlogPluginError *error, gpointer user_data) 
    5860{ 
    5961        struct Foo *foo = user_data; 
    6062        guint i; 
    61         (void)blogs
     63        (void)error
    6264 
    6365        *foo->blogs = blogs;