static void on_pws_hangup(void *closure);
static void on_pws_reply(void *closure, void *request, struct json_object *result, const char *error, const char *info);
-static void on_pws_event_create(void *closure, const char *event_name, int event_id);
-static void on_pws_event_remove(void *closure, const char *event_name, int event_id);
-static void on_pws_event_subscribe(void *closure, void *request, const char *event_name, int event_id);
-static void on_pws_event_unsubscribe(void *closure, void *request, const char *event_name, int event_id);
-static void on_pws_event_push(void *closure, const char *event_name, int event_id, struct json_object *data);
-static void on_pws_event_broadcast(void *closure, const char *event_name, struct json_object *data);
+static void on_pws_event_create(void *closure, uint16_t event_id, const char *event_name);
+static void on_pws_event_remove(void *closure, uint16_t event_id);
+static void on_pws_event_subscribe(void *closure, void *request, uint16_t event_id);
+static void on_pws_event_unsubscribe(void *closure, void *request, uint16_t event_id);
+static void on_pws_event_push(void *closure, uint16_t event_id, struct json_object *data);
+static void on_pws_event_broadcast(void *closure, const char *event_name, struct json_object *data, const afb_proto_ws_uuid_t uuid, uint8_t hop);
static void idle();
static int process_stdin();
" --help, -h Display this help\n"
" --human, -H Display human readable JSON\n"
" --raw, -r Raw output (default)\n"
- " --sync, -s Synchronous: wait for answers\n"
+ " --sync, -s Synchronous: wait for answers (like -p 1)\n"
" --keep-running, -k Keep running until disconnect, even if input closed\n"
+ " --pipe, -p COUNT Allow to pipe COUNT requests\n"
"Example:\n"
" %s --human 'localhost:1234/api?token=HELLO&uuid=magic' hello ping\n"
"\n", name
int main(int ac, char **av, char **env)
{
int rc;
- char *a0;
+ char *a0, *an;
/* get the program name */
a0 = av[0];
/* check options */
- while (ac > 1 && av[1][0] == '-') {
- if (av[1][1] == '-') {
+ while (ac > 1 && (an = av[1])[0] == '-') {
+ if (an[1] == '-') {
/* long option */
- if (!strcmp(av[1], "--human")) /* request for human output */
+ if (!strcmp(an, "--human")) /* request for human output */
human = 1;
- else if (!strcmp(av[1], "--raw")) /* request for raw output */
+ else if (!strcmp(an, "--raw")) /* request for raw output */
raw = 1;
- else if (!strcmp(av[1], "--direct")) /* request for direct api */
+ else if (!strcmp(an, "--direct")) /* request for direct api */
direct = 1;
- else if (!strcmp(av[1], "--break")) /* request to break connection */
+ else if (!strcmp(an, "--break")) /* request to break connection */
breakcon = 1;
- else if (!strcmp(av[1], "--keep-running")) /* request to break connection */
+ else if (!strcmp(an, "--keep-running")) /* request to break connection */
keeprun = 1;
- else if (!strcmp(av[1], "--sync")) /* request to break connection */
+ else if (!strcmp(an, "--sync")) /* request to break connection */
synchro = 1;
- else if (!strcmp(av[1], "--echo")) /* request to echo inputs */
+ else if (!strcmp(an, "--echo")) /* request to echo inputs */
echo = 1;
+ else if (!strcmp(an, "--pipe") && av[2] && atoi(av[2]) > 0) {
+ synchro = atoi(av[2]);
+ av++;
+ ac--;
+ }
+
/* emit usage and exit */
else
- usage(strcmp(av[1], "--help") ? Exit_Bad_Arg : Exit_Success, a0);
+ usage(strcmp(an, "--help") ? Exit_Bad_Arg : Exit_Success, a0);
} else {
/* short option(s) */
- for (rc = 1 ; av[1][rc] ; rc++)
- switch (av[1][rc]) {
+ for (rc = 1 ; an[rc] ; rc++)
+ switch (an[rc]) {
case 'H': human = 1; break;
case 'r': raw = 1; break;
case 'd': direct = 1; break;
case 'k': keeprun = 1; break;
case 's': synchro = 1; break;
case 'e': echo = 1; break;
- default: usage(av[1][rc] != 'h' ? Exit_Bad_Arg : Exit_Success, a0);
+ case 'p': if (av[2] && atoi(av[2]) > 0) { synchro = atoi(av[2]); av++; ac--; break; } /*@fallthrough@*/
+ default: usage(an[rc] != 'h' ? Exit_Bad_Arg : Exit_Success, a0);
}
}
av++;
exit(exitcode);
sd_event_run(loop, 30000000);
}
- else if (!synchro || !callcount) {
+ else if (!synchro || callcount < synchro) {
if (!process_stdin() && usein)
sd_event_run(loop, 100000);
} else {
}
}
count += (size_t)rc;
- if (synchro && callcount)
+ if (synchro && callcount >= synchro)
return 0;
/* normalise the buffer content */
dec_callcount();
}
-static void on_pws_event_create(void *closure, const char *event_name, int event_id)
+static void on_pws_event_create(void *closure, uint16_t event_id, const char *event_name)
{
printf("ON-EVENT-CREATE: [%d:%s]\n", event_id, event_name);
fflush(stdout);
}
-static void on_pws_event_remove(void *closure, const char *event_name, int event_id)
+static void on_pws_event_remove(void *closure, uint16_t event_id)
{
- printf("ON-EVENT-REMOVE: [%d:%s]\n", event_id, event_name);
+ printf("ON-EVENT-REMOVE: [%d]\n", event_id);
fflush(stdout);
}
-static void on_pws_event_subscribe(void *closure, void *request, const char *event_name, int event_id)
+static void on_pws_event_subscribe(void *closure, void *request, uint16_t event_id)
{
- printf("ON-EVENT-SUBSCRIBE %s: [%d:%s]\n", (char*)request, event_id, event_name);
+ printf("ON-EVENT-SUBSCRIBE %s: [%d]\n", (char*)request, event_id);
fflush(stdout);
}
-static void on_pws_event_unsubscribe(void *closure, void *request, const char *event_name, int event_id)
+static void on_pws_event_unsubscribe(void *closure, void *request, uint16_t event_id)
{
- printf("ON-EVENT-UNSUBSCRIBE %s: [%d:%s]\n", (char*)request, event_id, event_name);
+ printf("ON-EVENT-UNSUBSCRIBE %s: [%d]\n", (char*)request, event_id);
fflush(stdout);
}
-static void on_pws_event_push(void *closure, const char *event_name, int event_id, struct json_object *data)
+static void on_pws_event_push(void *closure, uint16_t event_id, struct json_object *data)
{
if (raw)
- printf("ON-EVENT-PUSH: [%d:%s]\n%s\n", event_id, event_name, json_object_to_json_string_ext(data, JSON_C_TO_STRING_NOSLASHESCAPE));
+ printf("ON-EVENT-PUSH: [%d]\n%s\n", event_id, json_object_to_json_string_ext(data, JSON_C_TO_STRING_NOSLASHESCAPE));
if (human)
- printf("ON-EVENT-PUSH: [%d:%s]\n%s\n", event_id, event_name, json_object_to_json_string_ext(data, JSON_C_TO_STRING_PRETTY|JSON_C_TO_STRING_NOSLASHESCAPE));
+ printf("ON-EVENT-PUSH: [%d]\n%s\n", event_id, json_object_to_json_string_ext(data, JSON_C_TO_STRING_PRETTY|JSON_C_TO_STRING_NOSLASHESCAPE));
fflush(stdout);
}
-static void on_pws_event_broadcast(void *closure, const char *event_name, struct json_object *data)
+static void on_pws_event_broadcast(void *closure, const char *event_name, struct json_object *data, const afb_proto_ws_uuid_t uuid, uint8_t hop)
{
if (raw)
printf("ON-EVENT-BROADCAST: [%s]\n%s\n", event_name, json_object_to_json_string_ext(data, JSON_C_TO_STRING_NOSLASHESCAPE));
if (jerr != json_tokener_success)
o = json_object_new_string(object);
}
- rc = afb_proto_ws_client_call(pws, verb, o, sessionid, key, NULL);
+ rc = afb_proto_ws_client_call(pws, verb, o, 0, 0, key, NULL);
json_object_put(o);
if (rc < 0) {
fprintf(stderr, "calling %s(%s) failed: %m\n", verb, object?:"");