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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
|
<template name="file-header">
/*
Generated by sbus code generator
Copyright (C) 2017 Red Hat
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <errno.h>
#include <talloc.h>
#include <tevent.h>
#include <dbus/dbus.h>
#include "${sbus-path}/sbus_private.h"
#include "${sbus-path}/interface/sbus_iterator_readers.h"
#include "${sbus-path}/interface_dbus/sbus_dbus_client_async.h"
#include "${header:arguments}"
#include "${header:keygens}"
#include "${header:client_properties}"
</template>
<template name="method-invoker">
struct sbus_method_in_${input-signature}_out_${output-signature}_state {
<toggle name="if-input-arguments">
struct _sbus_invoker_args_${input-signature} in;
</toggle>
<toggle name="if-output-arguments">
struct _sbus_invoker_args_${output-signature} *out;
</toggle>
<toggle name="if-raw-output">
DBusMessage *reply;
</toggle>
<toggle name="if-show-dummy">
int dummy;
</toggle>
};
static void sbus_method_in_${input-signature}_out_${output-signature}_done(struct tevent_req *subreq);
static struct tevent_req *
sbus_method_in_${input-signature}_out_${output-signature}_send
(TALLOC_CTX *mem_ctx,
struct sbus_connection *conn,
<toggle name="if-raw-input">
DBusMessage *raw_message)
<or>
sbus_invoker_keygen keygen,
const char *bus,
const char *path,
const char *iface,
const char *method<loop name="in">,
${type} arg${index}</loop>)
</toggle>
{
struct sbus_method_in_${input-signature}_out_${output-signature}_state *state;
struct tevent_req *subreq;
struct tevent_req *req;
errno_t ret;
req = tevent_req_create(mem_ctx, &state, struct sbus_method_in_${input-signature}_out_${output-signature}_state);
if (req == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create tevent request!\n");
return NULL;
}
<toggle name="if-output-arguments">
state->out = talloc_zero(state, struct _sbus_invoker_args_${output-signature});
if (state->out == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE,
"Unable to allocate space for output parameters!\n");
ret = ENOMEM;
goto done;
}
</toggle>
<loop name="in">
state->in.arg${index} = arg${index};
</loop>
<toggle name="if-raw-input">
subreq = sbus_call_method_send(state, conn, raw_message, NULL, NULL, NULL,
dbus_message_get_path(raw_message),
dbus_message_get_interface(raw_message),
dbus_message_get_member(raw_message), NULL);
</toggle>
<toggle name="if-input-arguments">
subreq = sbus_call_method_send(state, conn, NULL, keygen,
(sbus_invoker_writer_fn)_sbus_invoker_write_${input-signature},
bus, path, iface, method, &state->in);
</toggle>
<toggle name="if-empty-input">
subreq = sbus_call_method_send(state, conn, NULL, keygen, NULL,
bus, path, iface, method, NULL);
</toggle>
if (subreq == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create subrequest!\n");
ret = ENOMEM;
goto done;
}
tevent_req_set_callback(subreq, sbus_method_in_${input-signature}_out_${output-signature}_done, req);
ret = EAGAIN;
done:
if (ret != EAGAIN) {
tevent_req_error(req, ret);
tevent_req_post(req, conn->ev);
}
return req;
}
static void sbus_method_in_${input-signature}_out_${output-signature}_done(struct tevent_req *subreq)
{
struct sbus_method_in_${input-signature}_out_${output-signature}_state *state;
struct tevent_req *req;
DBusMessage *reply;
errno_t ret;
req = tevent_req_callback_data(subreq, struct tevent_req);
state = tevent_req_data(req, struct sbus_method_in_${input-signature}_out_${output-signature}_state);
ret = sbus_call_method_recv(state, subreq, &reply);
talloc_zfree(subreq);
if (ret != EOK) {
tevent_req_error(req, ret);
return;
}
<toggle name="if-raw-output">
state->reply = reply;
</toggle>
<toggle name="if-output-arguments">
ret = sbus_read_output(state->out, reply, (sbus_invoker_reader_fn)_sbus_invoker_read_${output-signature}, state->out);
if (ret != EOK) {
tevent_req_error(req, ret);
return;
}
</toggle>
tevent_req_done(req);
return;
}
static errno_t
sbus_method_in_${input-signature}_out_${output-signature}_recv
(<toggle name="if-use-talloc">TALLOC_CTX *mem_ctx,
struct tevent_req *req<or>struct tevent_req *req</toggle><toggle name="if-raw-output">,
DBusMessage **_reply)
<or><loop name="out">,
${type} _arg${index}</loop>)
</toggle>
{
<toggle name="if-raw-output">
errno_t ret;
</toggle>
<toggle name="if-has-output">
struct sbus_method_in_${input-signature}_out_${output-signature}_state *state;
state = tevent_req_data(req, struct sbus_method_in_${input-signature}_out_${output-signature}_state);
</toggle>
TEVENT_REQ_RETURN_ON_ERROR(req);
<toggle name="if-output-arguments">
<loop name="out-static">
*_arg${index} = state->out->arg${index};
</loop>
<loop name="out-talloc">
*_arg${index} = talloc_steal(mem_ctx, state->out->arg${index});
</loop>
</toggle>
<toggle name="if-raw-output">
/* Bounded reference cannot be unreferenced with dbus_message_unref.
* For that reason we do not allow NULL memory context as it would
* result in leaking the message memory. */
if (mem_ctx == NULL) {
return EINVAL;
}
ret = sbus_message_bound_steal(mem_ctx, state->reply);
if (ret != EOK) {
DEBUG(SSSDBG_CRIT_FAILURE, "Unable to steal message [%d]: %s\n",
ret, sss_strerror(ret));
return ret;
}
*_reply = state->reply;
</toggle>
return EOK;
}
</template>
<template name="method-caller">
struct tevent_req *
sbus_call_${token}_send
(TALLOC_CTX *mem_ctx,
struct sbus_connection *conn,
<toggle name="if-raw-input">
DBusMessage *raw_message)
<or>
const char *busname,
const char *object_path<loop name="in">,
${type} arg_${name}</loop>)
</toggle>
{
<toggle name="if-raw-input">
return sbus_method_in_${input-signature}_out_${output-signature}_send(mem_ctx, conn, raw_message);
<or>
return sbus_method_in_${input-signature}_out_${output-signature}_send(mem_ctx, conn, ${keygen},
busname, object_path, "${iface}", "${method}"<loop name="in">, arg_${name}</loop>);
</toggle>
}
errno_t
sbus_call_${token}_recv
(<toggle name="if-use-talloc">TALLOC_CTX *mem_ctx,
struct tevent_req *req<or>struct tevent_req *req</toggle><toggle name="if-raw-output">,
DBusMessage **_reply)
<or><loop name="out">,
${type} _${name}</loop>)
</toggle>
{
return sbus_method_in_${input-signature}_out_${output-signature}_recv(<toggle name="if-use-talloc">mem_ctx, </toggle>req<toggle line name="if-raw-output">, _reply<or><loop name="out">, _${name}</loop></toggle>);
}
</template>
<template name="signal-invoker">
static void
sbus_emit_signal_${input-signature}
(struct sbus_connection *conn,
<toggle name="if-raw-input">
DBusMessage *raw_message)
<or>
const char *path,
const char *iface,
const char *signal_name<loop name="in">,
${type} arg${index}</loop>)
</toggle>
{
<toggle name="if-input-arguments">
struct _sbus_invoker_args_${input-signature} args;
<loop name="in">
args.arg${index} = arg${index};
</loop>
</toggle>
<toggle name="if-raw-input">
sbus_call_signal_send(conn, raw_message, NULL,
dbus_message_get_path(raw_message),
dbus_message_get_interface(raw_message),
dbus_message_get_member(raw_message), NULL);
</toggle>
<toggle name="if-input-arguments">
sbus_call_signal_send(conn, NULL, (sbus_invoker_writer_fn)_sbus_invoker_write_${input-signature},
path, iface, signal_name, &args);
</toggle>
<toggle name="if-empty-input">
sbus_call_signal_send(conn, NULL, NULL, path, iface, signal_name, NULL);
</toggle>
}
</template>
<template name="signal-caller">
void
sbus_emit_${token}
(struct sbus_connection *conn,
<toggle name="if-raw-input">
DBusMessage *raw_message)
<or>
const char *object_path<loop name="in">,
${type} arg_${name}</loop>)
</toggle>
{
<toggle name="if-raw-input">
sbus_emit_signal_${input-signature}(conn, raw_message);
<or>
sbus_emit_signal_${input-signature}(conn, object_path,
"${iface}", "${signal}"<loop name="in">, arg_${name}</loop>);
</toggle>
}
</template>
<template name="get-invoker">
struct sbus_get_${output-signature}_state {
struct _sbus_invoker_args_${output-signature} *out;
};
static void sbus_get_${output-signature}_done(struct tevent_req *subreq);
static struct tevent_req *
sbus_get_${output-signature}_send
(TALLOC_CTX *mem_ctx,
struct sbus_connection *conn,
const char *busname,
const char *object_path,
const char *interface,
const char *property)
{
struct sbus_get_${output-signature}_state *state;
struct tevent_req *subreq;
struct tevent_req *req;
errno_t ret;
req = tevent_req_create(mem_ctx, &state, struct sbus_get_${output-signature}_state);
if (req == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create tevent request!\n");
return NULL;
}
state->out = talloc_zero(state, struct _sbus_invoker_args_${output-signature});
if (state->out == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE,
"Unable to allocate space for output parameters!\n");
ret = ENOMEM;
goto done;
}
subreq = sbus_call_DBusProperties_Get_send(mem_ctx, conn,
busname, object_path, interface, property);
if (subreq == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create subrequest!\n");
ret = ENOMEM;
goto done;
}
tevent_req_set_callback(subreq, sbus_get_${output-signature}_done, req);
ret = EAGAIN;
done:
if (ret == EOK) {
tevent_req_done(req);
tevent_req_post(req, conn->ev);
} else if (ret != EAGAIN) {
tevent_req_error(req, ret);
tevent_req_post(req, conn->ev);
}
return req;
}
static void sbus_get_${output-signature}_done(struct tevent_req *subreq)
{
struct sbus_get_${output-signature}_state *state;
sbus_value_reader_fn reader;
sbus_value_reader_talloc_fn reader_talloc;
struct tevent_req *req;
DBusMessage *reply;
errno_t ret;
req = tevent_req_callback_data(subreq, struct tevent_req);
state = tevent_req_data(req, struct sbus_get_${output-signature}_state);
ret = sbus_call_DBusProperties_Get_recv(state, subreq, &reply);
talloc_zfree(subreq);
if (ret != EOK) {
tevent_req_error(req, ret);
return;
}
reader = <toggle line name="if-use-talloc">NULL<or>(sbus_value_reader_fn)sbus_iterator_read_${output-signature}</toggle>;
reader_talloc = <toggle line name="if-use-talloc">(sbus_value_reader_talloc_fn)sbus_iterator_read_${output-signature}<or>NULL</toggle>;
ret = sbus_parse_get_message(state->out, reader, reader_talloc, reply, &state->out->arg0);
if (ret != EOK) {
tevent_req_error(req, ret);
return;
}
tevent_req_done(req);
return;
}
static errno_t
sbus_get_${output-signature}_recv
(<toggle name="if-use-talloc">TALLOC_CTX *mem_ctx,
struct tevent_req *req,
<or>struct tevent_req *req,
</toggle>
${output-type} _value)
{
struct sbus_get_${output-signature}_state *state;
state = tevent_req_data(req, struct sbus_get_${output-signature}_state);
TEVENT_REQ_RETURN_ON_ERROR(req);
*_value = <toggle line name="if-use-talloc">talloc_steal(mem_ctx, state->out->arg0)<or>state->out->arg0</toggle>;
return EOK;
}
</template>
<template name="set-invoker">
struct sbus_set_${input-signature}_state {
struct _sbus_invoker_args_${input-signature} in;
};
static void sbus_set_${input-signature}_done(struct tevent_req *subreq);
static struct tevent_req *
sbus_set_${input-signature}_send
(TALLOC_CTX *mem_ctx,
struct sbus_connection *conn,
const char *busname,
const char *object_path,
const char *interface,
const char *property,
${input-type} value)
{
struct sbus_set_${input-signature}_state *state;
struct tevent_req *subreq;
struct tevent_req *req;
DBusMessage *raw_message;
errno_t ret;
req = tevent_req_create(mem_ctx, &state, struct sbus_set_${input-signature}_state);
if (req == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create tevent request!\n");
return NULL;
}
state->in.arg0 = value;
raw_message = sbus_create_set_call(state,
(sbus_invoker_writer_fn)_sbus_invoker_write_${input-signature},
busname, object_path, interface, property,
"${dbus-type}", &state->in);
if (raw_message == NULL) {
ret = ENOMEM;
goto done;
}
subreq = sbus_call_DBusProperties_Set_send(mem_ctx, conn, raw_message);
if (subreq == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create subrequest!\n");
ret = ENOMEM;
goto done;
}
tevent_req_set_callback(subreq, sbus_set_${input-signature}_done, req);
ret = EAGAIN;
done:
if (ret == EOK) {
tevent_req_done(req);
tevent_req_post(req, conn->ev);
} else if (ret != EAGAIN) {
tevent_req_error(req, ret);
tevent_req_post(req, conn->ev);
}
return req;
}
static void sbus_set_${input-signature}_done(struct tevent_req *subreq)
{
struct tevent_req *req;
errno_t ret;
req = tevent_req_callback_data(subreq, struct tevent_req);
ret = sbus_call_DBusProperties_Set_recv(subreq);
talloc_zfree(subreq);
if (ret != EOK) {
tevent_req_error(req, ret);
return;
}
tevent_req_done(req);
return;
}
static errno_t
sbus_set_${input-signature}_recv
(struct tevent_req *req)
{
TEVENT_REQ_RETURN_ON_ERROR(req);
return EOK;
}
</template>
<template name="property-caller">
<toggle name="get-static">
struct tevent_req *
sbus_get_${token}_send
(TALLOC_CTX *mem_ctx,
struct sbus_connection *conn,
const char *busname,
const char *object_path)
{
return sbus_get_${output-signature}_send(mem_ctx,
conn, busname, object_path,
"${iface}", "${property}");
}
errno_t sbus_get_${token}_recv
(struct tevent_req *req,
${output-type} _value)
{
return sbus_get_${output-signature}_recv(req, _value);
}
</toggle>
<toggle name="get-talloc">
struct tevent_req *
sbus_get_${token}_send
(TALLOC_CTX *mem_ctx,
struct sbus_connection *conn,
const char *busname,
const char *object_path)
{
return sbus_get_${output-signature}_send(mem_ctx,
conn, busname, object_path,
"${iface}", "${property}");
}
errno_t sbus_get_${token}_recv
(TALLOC_CTX *mem_ctx,
struct tevent_req *req,
${output-type} _value)
{
return sbus_get_${output-signature}_recv(mem_ctx, req, _value);
}
</toggle>
<toggle name="set">
struct tevent_req *
sbus_set_${token}_send
(TALLOC_CTX *mem_ctx,
struct sbus_connection *conn,
const char *busname,
const char *object_path,
${input-type} value)
{
return sbus_set_${input-signature}_send(mem_ctx,
conn, busname, object_path,
"${iface}", "${property}", value);
}
errno_t sbus_set_${token}_recv
(struct tevent_req *req)
{
return sbus_set_${input-signature}_recv(req);
}
</toggle>
</template>
<template name="getall-caller">
struct sbus_getall_${token}_state {
struct sbus_all_${token} *properties;
};
static void sbus_getall_${token}_done(struct tevent_req *subreq);
struct tevent_req *
sbus_getall_${token}_send
(TALLOC_CTX *mem_ctx,
struct sbus_connection *conn,
const char *busname,
const char *object_path)
{
struct sbus_getall_${token}_state *state;
struct tevent_req *subreq;
struct tevent_req *req;
errno_t ret;
req = tevent_req_create(mem_ctx, &state, struct sbus_getall_${token}_state);
if (req == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create tevent request!\n");
return NULL;
}
state->properties = talloc_zero(state, struct sbus_all_${token});
if (state->properties == NULL) {
ret = ENOMEM;
goto done;
}
subreq = sbus_call_DBusProperties_GetAll_send(mem_ctx, conn,
busname, object_path, "${iface}");
if (subreq == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create subrequest!\n");
ret = ENOMEM;
goto done;
}
tevent_req_set_callback(subreq, sbus_getall_${token}_done, req);
ret = EAGAIN;
done:
if (ret == EOK) {
tevent_req_done(req);
tevent_req_post(req, conn->ev);
} else if (ret != EAGAIN) {
tevent_req_error(req, ret);
tevent_req_post(req, conn->ev);
}
return req;
}
static void sbus_getall_${token}_done(struct tevent_req *subreq)
{
struct sbus_getall_${token}_state *state;
struct tevent_req *req;
DBusMessage *reply;
errno_t ret;
req = tevent_req_callback_data(subreq, struct tevent_req);
state = tevent_req_data(req, struct sbus_getall_${token}_state);
ret = sbus_call_DBusProperties_GetAll_recv(state, subreq, &reply);
talloc_zfree(subreq);
if (ret != EOK) {
tevent_req_error(req, ret);
return;
}
struct sbus_parse_getall_table table[] = {
<loop name="property-static">
{"${name}", (sbus_value_reader_fn)sbus_iterator_read_${output-signature}, NULL,
&state->properties->${name}.value, &state->properties->${name}.is_set},
</loop>
<loop name="property-talloc">
{"${name}", NULL, (sbus_value_reader_talloc_fn)sbus_iterator_read_${output-signature},
&state->properties->${name}.value, &state->properties->${name}.is_set},
</loop>
{NULL, NULL, NULL, NULL, NULL}
};
ret = sbus_parse_getall_message(state, table, reply);
if (ret != EOK) {
tevent_req_error(req, ret);
return;
}
tevent_req_done(req);
return;
}
errno_t sbus_getall_${token}_recv
(TALLOC_CTX *mem_ctx,
struct tevent_req *req,
struct sbus_all_${token} **_properties)
{
struct sbus_getall_${token}_state *state;
state = tevent_req_data(req, struct sbus_getall_${token}_state);
TEVENT_REQ_RETURN_ON_ERROR(req);
*_properties = talloc_steal(mem_ctx, state->properties);
return EOK;
}
</template>
|