Added ping to C and Python test plugins

This commit is contained in:
James Booth
2016-03-23 23:00:43 +00:00
parent ff885058d4
commit c9f9a4ebad
2 changed files with 47 additions and 5 deletions

View File

@@ -6,6 +6,7 @@ import time
plugin_win = "Python Test"
count = 0
ping_id = 1
def _inc_counter():
global count
@@ -21,6 +22,7 @@ def create_win():
prof.win_create(plugin_win, _handle_win_input)
def cmd_pythontest(arg1=None, arg2=None, arg3=None, arg4=None, arg5=None):
global ping_id
if arg1 == "consalert":
create_win()
prof.win_focus(plugin_win)
@@ -154,6 +156,18 @@ def cmd_pythontest(arg1=None, arg2=None, arg3=None, arg4=None, arg5=None):
create_win()
prof.win_focus(plugin_win)
prof.win_show(plugin_win, "Count: " + str(count))
elif arg1 == "ping":
if arg2 == None:
prof.cons_bad_cmd_usage("/python-test")
else:
create_win()
prof.win_focus(plugin_win)
res = prof.send_stanza("<iq to='" + arg2 + "' id='pythonplugin-" + str(ping_id) + "' type='get'><ping xmlns='urn:xmpp:ping'/></iq>")
ping_id = ping_id + 1
if res:
prof.win_show(plugin_win, "Ping sent successfully")
else:
prof.win_show(plugin_win, "Error sending ping")
else:
prof.cons_bad_cmd_usage("/python-test")
@@ -179,7 +193,8 @@ def prof_init(version, status):
"/python-test sendline <line>",
"/python-test get recipient|room",
"/python-test log debug|info|warning|error <message>",
"/python-test count"
"/python-test count",
"/python-test ping <jid>"
]
description = "Python test plugins. All commands focus the plugin window."
args = [
@@ -194,19 +209,21 @@ def prof_init(version, status):
[ "get recipient", "Show the current chat recipient, if in a chat window" ],
[ "get room", "Show the current room JID, if ina a chat room"],
[ "log debug|info|warning|error <message>", "Log a message at the specified level" ],
[ "count", "Show the counter, incremented every 5 seconds by a worker thread" ]
[ "count", "Show the counter, incremented every 5 seconds by a worker thread" ],
[ "ping <jid>", "Send an XMPP ping to the specified Jabber ID" ]
]
examples = [
"/python-test sendline /about",
"/python-test log debug \"Test debug message\"",
"/python-test consshow_t c-test cons.show none \"This is themed\"",
"/python-test consshow_t none none bold_cyan \"This is bold_cyan\""
"/python-test consshow_t none none bold_cyan \"This is bold_cyan\"",
"/python-test ping buddy@server.org"
]
prof.register_command("/python-test", 1, 5, synopsis, description, args, examples, cmd_pythontest)
prof.register_ac("/python-test",
[ "consalert", "consshow", "consshow_t", "constest", "winshow", "winshow_t", "notify", "sendline", "get", "log", "count" ]
[ "consalert", "consshow", "consshow_t", "constest", "winshow", "winshow_t", "notify", "sendline", "get", "log", "count", "ping" ]
)
prof.register_ac("/python-test get",
[ "recipient", "room" ]

View File

@@ -11,6 +11,7 @@
static PROF_WIN_TAG plugin_win = "C Test";
static pthread_t worker_thread;
static int count = 0;
static int ping_id = 1;
void*
inc_counter(void *arg)
@@ -227,6 +228,27 @@ cmd_ctest(char **args)
char buf[100];
sprintf(buf, "Count: %d", count);
prof_win_show(plugin_win, buf);
} else if (strcmp(args[0], "ping") == 0) {
if (args[1] == NULL) {
prof_cons_bad_cmd_usage("/c-test");
} else {
create_win();
prof_win_focus(plugin_win);
char *strstart = "<iq to='";
char *strend = "' type='get'><ping xmlns='urn:xmpp:ping'/></iq>";
char *idstart = "' id='cplugin-";
char idbuf[strlen(idstart) + 10];
sprintf(idbuf, "%s%d", idstart, ping_id);
char buf[strlen(strstart) + strlen(args[1]) + strlen(idbuf) + strlen(strend)];
sprintf(buf, "%s%s%s%s", strstart, args[1], idbuf, strend);
int res = prof_send_stanza(buf);
ping_id++;
if (res) {
prof_win_show(plugin_win, "Ping sent successfully");
} else {
prof_win_show(plugin_win, "Error sending ping");
}
}
} else {
prof_cons_bad_cmd_usage("/c-test");
}
@@ -258,6 +280,7 @@ prof_init(const char * const version, const char * const status)
"/c-test get recipient|room",
"/c-test log debug|info|warning|error <message>",
"/c-test count",
"/c-test ping <jid>",
NULL
};
const char *description = "C test plugin. All commands focus the plugin window.";
@@ -274,6 +297,7 @@ prof_init(const char * const version, const char * const status)
{ "get room", "Show the current room JID, if in a chat room" },
{ "log debug|info|warning|error <message>", "Log a message at the specified level" },
{ "count", "Show the counter, incremented every 5 seconds by a worker thread" },
{ "ping <jid>", "Send an XMPP ping to the specified Jabber ID" },
{ NULL, NULL }
};
@@ -282,12 +306,13 @@ prof_init(const char * const version, const char * const status)
"/c-test log debug \"Test debug message\"",
"/c-test consshow_t c-test cons.show none \"This is themed\"",
"/c-test consshow_t none none bold_cyan \"This is bold_cyan\"",
"/c-test ping buddy@server.org",
NULL
};
prof_register_command("/c-test", 1, 5, synopsis, description, args, examples, cmd_ctest);
char *cmd_ac[] = { "consalert", "consshow", "consshow_t", "constest", "winshow", "winshow_t", "notify", "sendline", "get", "log", "count", NULL };
char *cmd_ac[] = { "consalert", "consshow", "consshow_t", "constest", "winshow", "winshow_t", "notify", "sendline", "get", "log", "count", "ping", NULL };
prof_register_ac("/c-test", cmd_ac);
char *get_ac[] = { "recipient", "room", NULL };