Changeset 16168

Show
Ignore:
Timestamp:
04/21/08 16:18:50 (8 months ago)
Author:
piotras
Message:

midgard_http_host_new: initialize sitegroup and language context.
Added midgard_http_host_get_request_config

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/midgard/core/midgard/src/midgard_http_host.c

    r16164 r16168  
    194194 * for given #MidgardHttpHost. You must free these objects if no longer needed. 
    195195 * 
     196 * Sitegroup and language context is set if #MidgardHttpHost is successfully initialized. 
     197 * 
    196198 * Returns: new #MidgardHttpHost or %NULL otherwise. 
    197199 * #uri can not be explicitly set to NULL. Use empty string  
     
    212214        self = g_object_new(MIDGARD_TYPE_HTTP_HOST, NULL); 
    213215 
     216        self->mgd = mgd; 
     217 
    214218        /* create list from uri */ 
    215219        __list_from_uri(self, uri);      
     
    238242         * required data much more later, which in practice means that we must  
    239243         * write the same solution per language */ 
    240         const gchar *sgname =  
     244        const gchar *pname =  
    241245                midgard_connection_get_sitegroup_from_id(mgd, host->dbpriv->sg); 
    242         midgard_connection_set_sitegroup(mgd, sgname); 
     246        midgard_connection_set_sitegroup(mgd, pname); 
     247 
     248        /* set language context */ 
     249        guint propid = 0; 
     250        pname = NULL; 
     251        g_object_get(G_OBJECT(host), "lang", &propid, NULL); 
     252        if(propid > 0) { 
     253                pname = midgard_connection_get_lang_from_id(mgd, propid); 
     254                midgard_connection_set_lang(mgd, pname); 
     255        } 
    243256 
    244257        /* set name and port */ 
     
    300313 
    301314        return self; 
     315} 
     316 
     317/** 
     318 * midgard_http_host_get_request_config: 
     319 * @self: #MidgardHttpHost instance 
     320 * 
     321 * This method initialize all request's configuration data. 
     322 * It's host, style, pages, argv, argc, etc. 
     323 * You do not have to explicitly set sitegroup or language context, as those 
     324 * are set when #MidgardHttpHost is being initialized. 
     325 * 
     326 * #MidgardRequestConfig is returned for convenience, but it's also associated  
     327 * with #MidgardConnection object for which #MidgardHttpHost has been initialized. 
     328 * 
     329 * Returns: #MidgardHttpHost object or %NULL on failure. 
     330 */  
     331MidgardRequestConfig *midgard_http_host_get_request_config(MidgardHttpHost *self) 
     332{ 
     333        g_assert(self != NULL); 
     334        g_assert(self->mgd != NULL); 
     335         
     336        if(!self->root_page) { 
     337                g_warning("Root page not set for current host"); 
     338                return NULL; 
     339        } 
     340 
     341        if(!self->host) { 
     342                g_warning("Midgard host not set"); 
     343                return NULL; 
     344        } 
     345         
     346        MidgardRequestConfig *rcfg = midgard_request_config_new(self->uri); 
     347         
     348        if(!rcfg) { 
     349                g_warning("Can not initialize midgard_request_config for http request"); 
     350                return NULL; 
     351        } 
     352 
     353        GList *list = NULL; 
     354        MidgardConnection *mgd = self->mgd; 
     355 
     356        /* Build pages array and decrease urilist */ 
     357        GList *pages = NULL, *argv_list = NULL; 
     358        pages = g_list_prepend(pages, self->root_page); 
     359         
     360        guint up_id = 0; 
     361        g_object_get(G_OBJECT(self->root_page), "id", &up_id, NULL); 
     362         
     363        MidgardQueryBuilder *builder; 
     364        GObject **objects = NULL, *last_page; 
     365        gchar *info; 
     366         
     367        last_page = G_OBJECT(self->root_page); 
     368        list = NULL; 
     369        GValue pval = {0, }; 
     370        gboolean is_arg = FALSE; 
     371 
     372        /* Uri "iterator". Keep urilist list. Do not copy its elements to improve performance. */ 
     373        list = self->urilist; 
     374        do { 
     375                builder = midgard_query_builder_new(mgd, "midgard_page"); 
     376                g_value_init(&pval, G_TYPE_UINT); 
     377                g_value_set_uint(&pval, up_id); 
     378                midgard_query_builder_add_constraint(builder, "up", "=", &pval); 
     379                g_value_unset(&pval); 
     380                 
     381                g_value_init(&pval, G_TYPE_STRING); 
     382                g_value_set_string(&pval, list->data); 
     383                midgard_query_builder_add_constraint(builder, "name", "=", &pval); 
     384                g_value_unset(&pval); 
     385                 
     386                midgard_query_builder_set_limit(builder, 1); 
     387                 
     388                objects = midgard_query_builder_execute(builder, NULL); 
     389                 
     390                g_object_unref(builder); 
     391 
     392                if(objects) { 
     393                         
     394                        if(MIDGARD_IS_OBJECT(objects[0])) { 
     395                                 
     396                                pages = g_list_prepend(pages, objects[0]); 
     397                                last_page = objects[0]; 
     398                                list = g_list_remove(list, (gconstpointer) list->data); 
     399                                g_object_get(G_OBJECT(objects[0]), "id", &up_id, NULL);  
     400                                 
     401                        } else { 
     402                                 
     403                                g_warning("Tried to get page, but it doesn't seem to be midgard object"); 
     404                        } 
     405                          
     406                        if(objects != NULL) 
     407                                g_free(objects); 
     408                         
     409                        objects = NULL; 
     410                 
     411                } else { 
     412 
     413                        break; 
     414                } 
     415 
     416        } while(list != NULL); 
     417 
     418        self->urilist = g_list_first(list); 
     419        guint listl = g_list_length(self->urilist); 
     420 
     421        if(listl == 1) { 
     422                /* TODO, try to get attachment */ 
     423        } 
     424 
     425        if(listl > 1) { 
     426                 
     427                GValueArray *array = g_value_array_new(listl); 
     428                 
     429                for(list = g_list_first(self->urilist); list != NULL; list = list->next) { 
     430                         
     431                        GValue *strval = g_new0(GValue, 1); 
     432                        g_value_init((GValue *)strval, G_TYPE_STRING); 
     433                        g_value_set_string((GValue *)strval, (gchar *)list->data); 
     434                        array = g_value_array_append(array, (const GValue *)strval); 
     435                        g_value_unset(strval); 
     436                        g_free(strval); 
     437                        g_free(list->data); 
     438                } 
     439                 
     440                midgard_request_config_set_argv(rcfg, array); 
     441        } 
     442         
     443        midgard_request_config_set_host(rcfg, G_OBJECT(self->host)); 
     444        midgard_request_config_set_page(rcfg, last_page); 
     445 
     446        mgd->rcfg = rcfg; 
     447 
     448        return rcfg; 
    302449} 
    303450 
  • trunk/midgard/core/midgard/src/midgard_http_host.h

    r16108 r16168  
    2222#include <glib-object.h> 
    2323#include "midgard_object.h" 
     24#include "midgard_request_config.h" 
    2425 
    2526G_BEGIN_DECLS 
     
    7576 
    7677extern MgdObject *midgard_http_host_get_style(MidgardHttpHost *self); 
     78extern MidgardRequestConfig *midgard_http_host_get_request_config(MidgardHttpHost *self); 
    7779 
    7880G_END_DECLS