int message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { xmpp_stanza_t *reply, *body, *text; char *intext, *replytext; int ret; xmpp_ctx_t *ctx = (xmpp_ctx_t*)userdata; if(!xmpp_stanza_get_child_by_name(stanza, "body")) return 1; if(!strcmp(xmpp_stanza_get_attribute(stanza, "type"), "error")) return 1; intext = xmpp_stanza_get_text(xmpp_stanza_get_child_by_name(stanza, "body")); printf("Incoming message from %s: %s\n", xmpp_stanza_get_attribute(stanza, "from"), intext); /* exec command */ ret = cs_exe(cs, intext, ctx, conn, stanza); reply = xmpp_stanza_new(ctx); xmpp_stanza_set_name(reply, "message"); xmpp_stanza_set_type(reply, xmpp_stanza_get_type(stanza)?xmpp_stanza_get_type(stanza):"chat"); xmpp_stanza_set_attribute(reply, "to", xmpp_stanza_get_attribute(stanza, "from")); body = xmpp_stanza_new(ctx); xmpp_stanza_set_name(body, "body"); replytext = malloc(strlen(" to you too!") + strlen(intext) + 1); strcpy(replytext, intext); strcat(replytext, " to you too!"); text = xmpp_stanza_new(ctx); xmpp_stanza_set_text(text, replytext); xmpp_stanza_add_child(body, text); xmpp_stanza_add_child(reply, body); xmpp_send(conn, reply); xmpp_stanza_release(reply); free(replytext); return 1; }
int message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { char *intext, replytext[512]; int ret; xmpp_ctx_t *ctx = (xmpp_ctx_t*)userdata; if(!xmpp_stanza_get_child_by_name(stanza, "body")) return 1; if(!strcmp(xmpp_stanza_get_attribute(stanza, "type"), "error")) return 1; intext = xmpp_stanza_get_text(xmpp_stanza_get_child_by_name(stanza, "body")); printf("Incoming message from %s: %s\n", xmpp_stanza_get_attribute(stanza, "from"), intext); /* exec command */ ret = cs_exe(cs, intext, ctx, conn, stanza); sprintf(replytext, "%s ret:%d.", intext, ret); send_chattext(ctx, conn, stanza, replytext); xmpp_free(ctx, intext); return 1; }
main (int argc, char **argv) { int errs = 0; int nprocs = 1; int c; extern int optind; extern char *optarg; char *name; extern GROUP *hostGroup; GROUP *group; EXE *exe; EXE *dummy; CHANNEL *channel = cs_channel (NULL, "dummy_chan"); supervisor_mode = 1 << 2; while((c = getopt (argc, argv, "n:vis")) != -1) { switch (c) { case 'v': verbose++; break; case 'i': cs_nowait (); break; case 'n': nprocs = atoi (optarg); break; case 's': supervisor_mode |= (1 << 0) | (1 << 3); break; case '?': errs++; break; } } if (errs || optind != (argc-1)) { fprintf (stderr, "usage: %s [-vin num] file\n", argv[0]); exit (1); } group = cs_group (NULL, "code"); cs_option (group, "commit", "transputer"); /* cs_option (hostGroup, "connect", group); */ exe = cs_exe (group, "code", name = argv[optind], "OutChan dummy", channel, 0); for (c = 0; c < nprocs - 1; c++) { CHANNEL *next = cs_channel (NULL, "dummy_chan"); dummy = cs_exe (NULL, "dummy_exe", "dummy.ex8", "InChan in", channel, "OutChan out", next, 0); cs_option (dummy, "mode", "system"); channel = next; } dummy = cs_exe (NULL, "dummy_exe", "dummy.ex8", "InChan in", channel, 0); cs_option (dummy, "mode", "system"); cs_load (); }