annotate src/gaim-client.c @ 14035:8bda65b88e49

[gaim-migrate @ 16638] A bunch of small changes. Mostly remove "if not null" checks before calling g_free, g_list_free, g_slist_free and g_strdup. Also use g_list_foreach() to call g_free to free strings in an array. And some whitespace changes here and there. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sat, 05 Aug 2006 08:27:39 +0000
parents 421a8523ad04
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11241
66f872f30e40 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj>
parents:
diff changeset
1 #define DBUS_API_SUBJECT_TO_CHANGE
66f872f30e40 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj>
parents:
diff changeset
2
66f872f30e40 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj>
parents:
diff changeset
3 #include <dbus/dbus-glib.h>
66f872f30e40 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj>
parents:
diff changeset
4 #include <stdio.h>
66f872f30e40 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj>
parents:
diff changeset
5 #include <stdlib.h>
66f872f30e40 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj>
parents:
diff changeset
6
66f872f30e40 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj>
parents:
diff changeset
7 #include "dbus-gaim.h"
66f872f30e40 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj>
parents:
diff changeset
8 #include "gaim-client-bindings.h"
66f872f30e40 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj>
parents:
diff changeset
9
66f872f30e40 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj>
parents:
diff changeset
10 static DBusGConnection *bus;
66f872f30e40 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj>
parents:
diff changeset
11 static DBusGProxy *gaim_proxy;
66f872f30e40 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj>
parents:
diff changeset
12
14035
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
13 static GList *garray_int_to_glist(GArray *array)
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
14 {
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
15 GList *list = NULL;
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
16 int i;
11277
421a8523ad04 [gaim-migrate @ 13467]
Piotr Zielinski <zielaj>
parents: 11241
diff changeset
17
14035
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
18 for (i = 0; i < array->len; i++)
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
19 list = g_list_append(list, GINT_TO_POINTER(g_array_index(array,gint,i)));
11277
421a8523ad04 [gaim-migrate @ 13467]
Piotr Zielinski <zielaj>
parents: 11241
diff changeset
20
14035
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
21 g_array_free(array, TRUE);
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
22 return list;
11277
421a8523ad04 [gaim-migrate @ 13467]
Piotr Zielinski <zielaj>
parents: 11241
diff changeset
23 }
421a8523ad04 [gaim-migrate @ 13467]
Piotr Zielinski <zielaj>
parents: 11241
diff changeset
24
14035
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
25 static GSList *garray_int_to_gslist(GArray *array)
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
26 {
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
27 GSList *list = NULL;
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
28 int i;
11277
421a8523ad04 [gaim-migrate @ 13467]
Piotr Zielinski <zielaj>
parents: 11241
diff changeset
29
14035
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
30 for (i = 0; i < array->len; i++)
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
31 list = g_slist_append(list, GINT_TO_POINTER(g_array_index(array,gint,i)));
11277
421a8523ad04 [gaim-migrate @ 13467]
Piotr Zielinski <zielaj>
parents: 11241
diff changeset
32
14035
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
33 g_array_free(array, TRUE);
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
34 return list;
11277
421a8523ad04 [gaim-migrate @ 13467]
Piotr Zielinski <zielaj>
parents: 11241
diff changeset
35 }
421a8523ad04 [gaim-migrate @ 13467]
Piotr Zielinski <zielaj>
parents: 11241
diff changeset
36
11241
66f872f30e40 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj>
parents:
diff changeset
37 #include "gaim-client-bindings.c"
66f872f30e40 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj>
parents:
diff changeset
38
14035
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
39 static void lose(const char *fmt, ...) G_GNUC_NORETURN G_GNUC_PRINTF (1, 2);
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
40 static void lose_gerror(const char *prefix, GError *error) G_GNUC_NORETURN;
11241
66f872f30e40 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj>
parents:
diff changeset
41
66f872f30e40 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj>
parents:
diff changeset
42 static void
14035
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
43 lose(const char *str, ...)
11241
66f872f30e40 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj>
parents:
diff changeset
44 {
14035
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
45 va_list args;
11241
66f872f30e40 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj>
parents:
diff changeset
46
14035
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
47 va_start(args, str);
11241
66f872f30e40 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj>
parents:
diff changeset
48
14035
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
49 vfprintf(stderr, str, args);
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
50 fputc('\n', stderr);
11241
66f872f30e40 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj>
parents:
diff changeset
51
14035
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
52 va_end(args);
11241
66f872f30e40 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj>
parents:
diff changeset
53
14035
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
54 exit(1);
11241
66f872f30e40 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj>
parents:
diff changeset
55 }
66f872f30e40 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj>
parents:
diff changeset
56
66f872f30e40 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj>
parents:
diff changeset
57 static void
14035
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
58 lose_gerror(const char *prefix, GError *error)
11241
66f872f30e40 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj>
parents:
diff changeset
59 {
14035
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
60 lose("%s: %s", prefix, error->message);
11241
66f872f30e40 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj>
parents:
diff changeset
61 }
66f872f30e40 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj>
parents:
diff changeset
62
14035
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
63 void gaim_init(void)
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
64 {
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
65 GError *error = NULL;
11241
66f872f30e40 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj>
parents:
diff changeset
66
14035
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
67 g_type_init ();
11241
66f872f30e40 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj>
parents:
diff changeset
68
14035
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
69 bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
70 if (!bus)
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
71 lose_gerror ("Couldn't connect to session bus", error);
11241
66f872f30e40 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj>
parents:
diff changeset
72
14035
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
73 gaim_proxy = dbus_g_proxy_new_for_name (bus,
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
74 DBUS_SERVICE_GAIM,
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
75 DBUS_PATH_GAIM,
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
76 DBUS_INTERFACE_GAIM);
11241
66f872f30e40 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj>
parents:
diff changeset
77
14035
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
78 if (!gaim_proxy)
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 11277
diff changeset
79 lose_gerror ("Couldn't connect to the Gaim Service", error);
11241
66f872f30e40 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj>
parents:
diff changeset
80 }
66f872f30e40 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj>
parents:
diff changeset
81