Logo Search packages:      
Sourcecode: telepathy-sofiasip version File versions

write-mgr-file.c

/*
 * write_mgr_file.c - utility to produce .manager files.
 * Copyright (C) 2006-2007 Collabora Ltd.
 * Copyright (C) 2006-2007 Nokia Corporation
 *
 * This work is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This work is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this work; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include <stdio.h>

#include <dbus/dbus-glib.h>
#include <dbus/dbus-protocol.h>

#include <telepathy-glib/enums.h>
#include "sip-connection-manager.h"

/* Cloned straight from Gabble - this might eventually go in a library */
static gchar *
mgr_file_contents (const char *busname,
                   const char *objpath,
                   const TpCMProtocolSpec protocols[],
                   GError **error)
{
  GKeyFile *f = g_key_file_new();
  const TpCMProtocolSpec *protocol;
  const TpCMParamSpec *row;

  g_key_file_set_string(f, "ConnectionManager", "BusName", busname);
  g_key_file_set_string(f, "ConnectionManager", "ObjectPath", objpath);

  for (protocol = protocols; protocol->name; protocol++)
    {
      gchar *section_name = g_strdup_printf("Protocol %s", protocol->name);

      for (row = protocol->parameters; row->name; row++)
        {
          gchar *param_name = g_strdup_printf("param-%s", row->name);
          gchar *param_value = g_strdup_printf("%s%s%s", row->dtype,
              (row->flags & TP_CONN_MGR_PARAM_FLAG_REQUIRED ? " required" : ""),
              (row->flags & TP_CONN_MGR_PARAM_FLAG_REGISTER ? " register" : ""));
          g_key_file_set_string(f, section_name, param_name, param_value);
          g_free(param_value);
          g_free(param_name);
        }

      for (row = protocol->parameters; row->name; row++)
        {
          if (row->flags & TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT)
            {
              gchar *default_name = g_strdup_printf("default-%s", row->name);

              switch (row->gtype)
                {
                case G_TYPE_STRING:
                  g_key_file_set_string(f, section_name, default_name,
                                        row->def);
                  break;
                case G_TYPE_INT:
                case G_TYPE_UINT:
                  g_key_file_set_integer(f, section_name, default_name,
                                         GPOINTER_TO_INT(row->def));
                  break;
                case G_TYPE_BOOLEAN:
                  g_key_file_set_boolean(f, section_name, default_name,
                                         GPOINTER_TO_INT(row->def) ? 1 : 0);
                }
              g_free(default_name);
            }
        }
      g_free(section_name);
    }
  return g_key_file_to_data(f, NULL, error);
}

/* defined by telepathy-glib if your version is new enough - included here
 * so telepathy-glib 0.5.4 and 0.5.5 will still work 
 */
#ifndef TP_CM_BUS_NAME_BASE
# define TP_CM_BUS_NAME_BASE    "org.freedesktop.Telepathy.ConnectionManager."
# define TP_CM_OBJECT_PATH_BASE "/org/freedesktop/Telepathy/ConnectionManager/"
#endif

int
main (void)
{
  GError *error = NULL;

  gchar *s = mgr_file_contents(TP_CM_BUS_NAME_BASE "sofiasip",
                               TP_CM_OBJECT_PATH_BASE "sofiasip",
                               tpsip_protocols, &error);
  if (!s)
    {
      fprintf(stderr, error->message);
      g_error_free(error);
      return 1;
    }
  printf("%s", s);
  g_free(s);
  return 0;
}

Generated by  Doxygen 1.6.0   Back to index