telepathygabble/src/write-mgr-file.c
changeset 10 59927b2d3b75
parent 0 d0f3a028347a
equal deleted inserted replaced
0:d0f3a028347a 10:59927b2d3b75
     1 /*
       
     2  * write_mgr_file.c - utility to produce gabble.manager. Part of Gabble.
       
     3  * Copyright (C) 2006 Collabora Ltd.
       
     4  * 
       
     5  *
       
     6  * This library is free software; you can redistribute it and/or
       
     7  * modify it under the terms of the GNU Lesser General Public
       
     8  * License as published by the Free Software Foundation; either
       
     9  * version 2.1 of the License, or (at your option) any later version.
       
    10  *
       
    11  * This library is distributed in the hope that it will be useful,
       
    12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    14  * Lesser General Public License for more details.
       
    15  *
       
    16  * You should have received a copy of the GNU Lesser General Public
       
    17  * License along with this library; if not, write to the Free Software
       
    18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
       
    19  */
       
    20 
       
    21 #include <stdio.h>
       
    22 
       
    23 #include <dbus/dbus-glib.h>
       
    24 #include <dbus/dbus-protocol.h>
       
    25 
       
    26 #include "telepathy-constants.h"
       
    27 #include "gabble-connection-manager.h"
       
    28 
       
    29 static gchar *
       
    30 mgr_file_contents (const char *busname,
       
    31                    const char *objpath,
       
    32                    const GabbleProtocolSpec *protocols,
       
    33                    GError **error)
       
    34 {
       
    35   GKeyFile *f = g_key_file_new();
       
    36   const GabbleProtocolSpec *protocol;
       
    37   const GabbleParamSpec *row;
       
    38 
       
    39   g_key_file_set_string(f, "ConnectionManager", "BusName", busname);
       
    40   g_key_file_set_string(f, "ConnectionManager", "ObjectPath", objpath);
       
    41 
       
    42   for (protocol = protocols; protocol->name; protocol++)
       
    43     {
       
    44       gchar *section_name = g_strdup_printf("Protocol %s", protocol->name);
       
    45 
       
    46       for (row = protocol->parameters; row->name; row++)
       
    47         {
       
    48           gchar *param_name = g_strdup_printf("param-%s", row->name);
       
    49           gchar *param_value = g_strdup_printf("%s%s%s", row->dtype,
       
    50               (row->flags & TP_CONN_MGR_PARAM_FLAG_REQUIRED ? " required" : ""),
       
    51               (row->flags & TP_CONN_MGR_PARAM_FLAG_REGISTER ? " register" : ""));
       
    52           g_key_file_set_string(f, section_name, param_name, param_value);
       
    53           g_free(param_value);
       
    54           g_free(param_name);
       
    55         }
       
    56 
       
    57       for (row = protocol->parameters; row->name; row++)
       
    58         {
       
    59           if (row->flags & TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT)
       
    60             {
       
    61               gchar *default_name = g_strdup_printf("default-%s", row->name);
       
    62 
       
    63               switch (row->gtype)
       
    64                 {
       
    65                 case G_TYPE_STRING:
       
    66                   g_key_file_set_string(f, section_name, default_name,
       
    67                                         row->def);
       
    68                   break;
       
    69                 case G_TYPE_INT:
       
    70                 case G_TYPE_UINT:
       
    71                   g_key_file_set_integer(f, section_name, default_name,
       
    72                                          GPOINTER_TO_INT(row->def));
       
    73                   break;
       
    74                 case G_TYPE_BOOLEAN:
       
    75                   g_key_file_set_boolean(f, section_name, default_name,
       
    76                                          GPOINTER_TO_INT(row->def) ? 1 : 0);
       
    77                 }
       
    78               g_free(default_name);
       
    79             }
       
    80         }
       
    81       g_free(section_name);
       
    82     }
       
    83   return g_key_file_to_data(f, NULL, error);
       
    84 }
       
    85 
       
    86 int
       
    87 main (void)
       
    88 {
       
    89   GError *error = NULL;
       
    90 	
       
    91   gchar *s = mgr_file_contents(GABBLE_CONN_MGR_BUS_NAME,
       
    92                                GABBLE_CONN_MGR_OBJECT_PATH,
       
    93                                gabble_protocols, &error);
       
    94   if (!s)
       
    95     {
       
    96       fprintf(stderr, error->message);
       
    97       g_error_free(error);
       
    98       return 1;
       
    99     }
       
   100   g_message("%s", s);
       
   101   getchar(); //vinod
       
   102   g_free(s);
       
   103   return 0;
       
   104 }