~jamesodhunt/ubuntu/raring/upstart/1.6

« back to all changes in this revision

Viewing changes to nih-dbus-tool/tests/expected/test_method_proxy_sync_function_standard.c

  • Committer: Scott James Remnant
  • Date: 2010-02-04 23:39:59 UTC
  • mfrom: (1182.1.45 upstart)
  • mto: This revision was merged to the branch mainline in revision 1250.
  • Revision ID: scott@netsplit.com-20100204233959-7kajqjnaoh7208ob
Tags: upstream-0.6.5
ImportĀ upstreamĀ versionĀ 0.6.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
int
2
 
my_method_sync (const void *  parent,
3
 
                NihDBusProxy *proxy,
4
 
                const char *  str,
5
 
                int32_t       flags,
6
 
                char ***      output,
7
 
                int32_t *     length)
8
 
{
9
 
        DBusMessage *   method_call;
10
 
        DBusMessageIter iter;
11
 
        DBusError       error;
12
 
        DBusMessage *   reply;
13
 
        char **         output_local;
14
 
        DBusMessageIter output_local_iter;
15
 
        size_t          output_local_size;
16
 
        int32_t         length_local;
17
 
 
18
 
        nih_assert (proxy != NULL);
19
 
        nih_assert (str != NULL);
20
 
        nih_assert (output != NULL);
21
 
        nih_assert (length != NULL);
22
 
 
23
 
        /* Construct the method call message. */
24
 
        method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "Method");
25
 
        if (! method_call)
26
 
                nih_return_no_memory_error (-1);
27
 
 
28
 
        dbus_message_set_auto_start (method_call, proxy->auto_start);
29
 
 
30
 
        dbus_message_iter_init_append (method_call, &iter);
31
 
 
32
 
        /* Marshal a char * onto the message */
33
 
        if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str)) {
34
 
                dbus_message_unref (method_call);
35
 
                nih_return_no_memory_error (-1);
36
 
        }
37
 
 
38
 
        /* Marshal a int32_t onto the message */
39
 
        if (! dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &flags)) {
40
 
                dbus_message_unref (method_call);
41
 
                nih_return_no_memory_error (-1);
42
 
        }
43
 
 
44
 
        /* Send the message, and wait for the reply. */
45
 
        dbus_error_init (&error);
46
 
 
47
 
        reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error);
48
 
        if (! reply) {
49
 
                dbus_message_unref (method_call);
50
 
 
51
 
                if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) {
52
 
                        nih_error_raise_no_memory ();
53
 
                } else {
54
 
                        nih_dbus_error_raise (error.name, error.message);
55
 
                }
56
 
 
57
 
                dbus_error_free (&error);
58
 
                return -1;
59
 
        }
60
 
 
61
 
        dbus_message_unref (method_call);
62
 
 
63
 
        /* Iterate the arguments of the reply */
64
 
        dbus_message_iter_init (reply, &iter);
65
 
 
66
 
        do {
67
 
                __label__ enomem;
68
 
 
69
 
                /* Demarshal an array from the message */
70
 
                if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY) {
71
 
                        dbus_message_unref (reply);
72
 
                        nih_return_error (-1, NIH_DBUS_INVALID_ARGS,
73
 
                                          _(NIH_DBUS_INVALID_ARGS_STR));
74
 
                }
75
 
 
76
 
                dbus_message_iter_recurse (&iter, &output_local_iter);
77
 
 
78
 
                output_local_size = 0;
79
 
                output_local = NULL;
80
 
 
81
 
                output_local = nih_alloc (parent, sizeof (char *));
82
 
                if (! output_local) {
83
 
                        *output = NULL;
84
 
                        goto enomem;
85
 
                }
86
 
 
87
 
                output_local[output_local_size] = NULL;
88
 
 
89
 
                while (dbus_message_iter_get_arg_type (&output_local_iter) != DBUS_TYPE_INVALID) {
90
 
                        const char *output_local_element_dbus;
91
 
                        char **     output_local_tmp;
92
 
                        char *      output_local_element;
93
 
 
94
 
                        /* Demarshal a char * from the message */
95
 
                        if (dbus_message_iter_get_arg_type (&output_local_iter) != DBUS_TYPE_STRING) {
96
 
                                if (output_local)
97
 
                                        nih_free (output_local);
98
 
                                dbus_message_unref (reply);
99
 
                                nih_return_error (-1, NIH_DBUS_INVALID_ARGS,
100
 
                                                  _(NIH_DBUS_INVALID_ARGS_STR));
101
 
                        }
102
 
 
103
 
                        dbus_message_iter_get_basic (&output_local_iter, &output_local_element_dbus);
104
 
 
105
 
                        output_local_element = nih_strdup (output_local, output_local_element_dbus);
106
 
                        if (! output_local_element) {
107
 
                                if (output_local)
108
 
                                        nih_free (output_local);
109
 
                                *output = NULL;
110
 
                                goto enomem;
111
 
                        }
112
 
 
113
 
                        dbus_message_iter_next (&output_local_iter);
114
 
 
115
 
                        if (output_local_size + 2 > SIZE_MAX / sizeof (char *)) {
116
 
                                if (output_local)
117
 
                                        nih_free (output_local);
118
 
                                dbus_message_unref (reply);
119
 
                                nih_return_error (-1, NIH_DBUS_INVALID_ARGS,
120
 
                                                  _(NIH_DBUS_INVALID_ARGS_STR));
121
 
                        }
122
 
 
123
 
                        output_local_tmp = nih_realloc (output_local, parent, sizeof (char *) * (output_local_size + 2));
124
 
                        if (! output_local_tmp) {
125
 
                                if (output_local)
126
 
                                        nih_free (output_local);
127
 
                                *output = NULL;
128
 
                                goto enomem;
129
 
                        }
130
 
 
131
 
                        output_local = output_local_tmp;
132
 
                        output_local[output_local_size] = output_local_element;
133
 
                        output_local[output_local_size + 1] = NULL;
134
 
 
135
 
                        output_local_size++;
136
 
                }
137
 
 
138
 
                dbus_message_iter_next (&iter);
139
 
 
140
 
                *output = output_local;
141
 
        enomem: __attribute__ ((unused));
142
 
        } while (! *output);
143
 
 
144
 
        do {
145
 
                __label__ enomem;
146
 
 
147
 
                /* Demarshal a int32_t from the message */
148
 
                if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INT32) {
149
 
                        nih_free (output_local);
150
 
                        *output = NULL;
151
 
                        dbus_message_unref (reply);
152
 
                        nih_return_error (-1, NIH_DBUS_INVALID_ARGS,
153
 
                                          _(NIH_DBUS_INVALID_ARGS_STR));
154
 
                }
155
 
 
156
 
                dbus_message_iter_get_basic (&iter, &length_local);
157
 
 
158
 
                dbus_message_iter_next (&iter);
159
 
 
160
 
                *length = length_local;
161
 
        enomem: __attribute__ ((unused));
162
 
        } while (! *length);
163
 
 
164
 
        if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) {
165
 
                nih_free (output_local);
166
 
                *output = NULL;
167
 
                dbus_message_unref (reply);
168
 
                nih_return_error (-1, NIH_DBUS_INVALID_ARGS,
169
 
                                  _(NIH_DBUS_INVALID_ARGS_STR));
170
 
        }
171
 
 
172
 
        dbus_message_unref (reply);
173
 
 
174
 
        return 0;
175
 
}