1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
|
void
my_com_netsplit_Nih_Test_get_all_notify (DBusPendingCall * pending_call,
NihDBusPendingData *pending_data)
{
DBusMessage * reply;
DBusMessageIter iter;
DBusMessageIter arrayiter;
DBusMessageIter dictiter;
DBusMessageIter variter;
NihDBusMessage *message;
DBusError error;
const char * property;
MyProperties * properties;
size_t property_count;
char * name;
const char * name_dbus;
uint32_t size;
nih_assert (pending_call != NULL);
nih_assert (pending_data != NULL);
nih_assert (dbus_pending_call_get_completed (pending_call));
/* Steal the reply from the pending call. */
reply = dbus_pending_call_steal_reply (pending_call);
nih_assert (reply != NULL);
/* Handle error replies */
if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) {
message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply));
dbus_error_init (&error);
dbus_set_error_from_message (&error, message->message);
nih_error_push_context ();
nih_dbus_error_raise (error.name, error.message);
pending_data->error_handler (pending_data->data, message);
nih_error_pop_context ();
dbus_error_free (&error);
nih_free (message);
dbus_message_unref (reply);
return;
}
nih_assert (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN);
/* Create a message context for the reply, and iterate
* over and recurse into the arguments.
*/
message = NIH_MUST (nih_dbus_message_new (pending_data, pending_data->connection, reply));
/* Iterate the method arguments, recursing into the array */
dbus_message_iter_init (reply, &iter);
if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY) {
nih_error_push_context ();
nih_error_raise (NIH_DBUS_INVALID_ARGS,
_(NIH_DBUS_INVALID_ARGS_STR));
pending_data->error_handler (pending_data->data, message);
nih_error_pop_context ();
nih_free (message);
dbus_message_unref (reply);
return;
}
properties = NIH_MUST (nih_new (message, MyProperties));
property_count = 0;
dbus_message_iter_recurse (&iter, &arrayiter);
while (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_INVALID) {
__label__ enomem;
if (dbus_message_iter_get_arg_type (&arrayiter) != DBUS_TYPE_DICT_ENTRY) {
nih_error_push_context ();
nih_error_raise (NIH_DBUS_INVALID_ARGS,
_(NIH_DBUS_INVALID_ARGS_STR));
pending_data->error_handler (pending_data->data, message);
nih_error_pop_context ();
nih_free (message);
dbus_message_unref (reply);
return;
}
dbus_message_iter_recurse (&arrayiter, &dictiter);
if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_STRING) {
nih_error_push_context ();
nih_error_raise (NIH_DBUS_INVALID_ARGS,
_(NIH_DBUS_INVALID_ARGS_STR));
pending_data->error_handler (pending_data->data, message);
nih_error_pop_context ();
nih_free (message);
dbus_message_unref (reply);
return;
}
dbus_message_iter_get_basic (&dictiter, &property);
dbus_message_iter_next (&dictiter);
if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_VARIANT) {
nih_error_push_context ();
nih_error_raise (NIH_DBUS_INVALID_ARGS,
_(NIH_DBUS_INVALID_ARGS_STR));
pending_data->error_handler (pending_data->data, message);
nih_error_pop_context ();
nih_free (message);
dbus_message_unref (reply);
return;
}
dbus_message_iter_recurse (&dictiter, &variter);
if (! strcmp (property, "name")) {
/* Demarshal a char * from the message */
if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_STRING) {
nih_error_push_context ();
nih_error_raise (NIH_DBUS_INVALID_ARGS,
_(NIH_DBUS_INVALID_ARGS_STR));
pending_data->error_handler (pending_data->data, message);
nih_error_pop_context ();
nih_free (message);
dbus_message_unref (reply);
return;
}
dbus_message_iter_get_basic (&variter, &name_dbus);
name = nih_strdup (properties, name_dbus);
if (! name) {
goto enomem;
}
dbus_message_iter_next (&variter);
properties->name = name;
nih_assert (++property_count);
}
if (! strcmp (property, "size")) {
/* Demarshal a uint32_t from the message */
if (dbus_message_iter_get_arg_type (&variter) != DBUS_TYPE_UINT32) {
nih_error_push_context ();
nih_error_raise (NIH_DBUS_INVALID_ARGS,
_(NIH_DBUS_INVALID_ARGS_STR));
pending_data->error_handler (pending_data->data, message);
nih_error_pop_context ();
nih_free (message);
dbus_message_unref (reply);
return;
}
dbus_message_iter_get_basic (&variter, &size);
dbus_message_iter_next (&variter);
properties->size = size;
nih_assert (++property_count);
}
dbus_message_iter_next (&dictiter);
if (dbus_message_iter_get_arg_type (&dictiter) != DBUS_TYPE_INVALID) {
nih_error_push_context ();
nih_error_raise (NIH_DBUS_INVALID_ARGS,
_(NIH_DBUS_INVALID_ARGS_STR));
pending_data->error_handler (pending_data->data, message);
nih_error_pop_context ();
nih_free (message);
dbus_message_unref (reply);
return;
}
dbus_message_iter_next (&arrayiter);
enomem: __attribute__ ((unused));
}
dbus_message_iter_next (&iter);
if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) {
nih_error_push_context ();
nih_error_raise (NIH_DBUS_INVALID_ARGS,
_(NIH_DBUS_INVALID_ARGS_STR));
pending_data->error_handler (pending_data->data, message);
nih_error_pop_context ();
nih_free (message);
dbus_message_unref (reply);
return;
}
if (property_count < 2) {
nih_error_push_context ();
nih_error_raise (NIH_DBUS_INVALID_ARGS,
_(NIH_DBUS_INVALID_ARGS_STR));
pending_data->error_handler (pending_data->data, message);
nih_error_pop_context ();
nih_free (message);
dbus_message_unref (reply);
return;
}
/* Call the handler function */
nih_error_push_context ();
((MyGetAllReply)pending_data->handler) (pending_data->data, message, properties);
nih_error_pop_context ();
nih_free (message);
dbus_message_unref (reply);
}
|