about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2016-03-23 22:57:03 +0000
committerJames Booth <boothj5@gmail.com>2016-03-23 22:57:03 +0000
commit4c913aa08baa5e27972ee10d453e440c13fb7fb7 (patch)
treed507c4d8917dd230f9a275855146238b50fd0415
parent503fc9e393708cab48de47bc80d4f6a0c0f6cc43 (diff)
downloadprofani-tty-4c913aa08baa5e27972ee10d453e440c13fb7fb7.tar.gz
Added prof_send_stanza to plugins API
-rw-r--r--src/plugins/api.c7
-rw-r--r--src/plugins/api.h1
-rw-r--r--src/plugins/c_api.c7
-rw-r--r--src/plugins/profapi.c1
-rw-r--r--src/plugins/profapi.h2
-rw-r--r--src/plugins/python_api.c19
-rw-r--r--src/xmpp/connection.c11
-rw-r--r--src/xmpp/iq.c12
-rw-r--r--src/xmpp/xmpp.h1
-rw-r--r--tests/unittests/xmpp/stub_xmpp.c6
10 files changed, 61 insertions, 6 deletions
diff --git a/src/plugins/api.c b/src/plugins/api.c
index e81467a9..81b464ca 100644
--- a/src/plugins/api.c
+++ b/src/plugins/api.c
@@ -325,3 +325,10 @@ api_win_show_themed(const char *tag, const char *const group, const char *const
 
     return 1;
 }
+
+int
+api_send_stanza(const char *const stanza)
+{
+    return jabber_send_stanza(stanza);
+}
+
diff --git a/src/plugins/api.h b/src/plugins/api.h
index 6494097e..2ded857c 100644
--- a/src/plugins/api.h
+++ b/src/plugins/api.h
@@ -70,5 +70,6 @@ int api_win_focus(const char *tag);
 int api_win_show(const char *tag, const char *line);
 int api_win_show_themed(const char *tag, const char *const group, const char *const key, const char *const def, const char *line);
 
+int api_send_stanza(const char *const stanza);
 
 #endif
diff --git a/src/plugins/c_api.c b/src/plugins/c_api.c
index f2cce6a6..82b89bfd 100644
--- a/src/plugins/c_api.c
+++ b/src/plugins/c_api.c
@@ -188,6 +188,12 @@ c_api_win_show_themed(char *tag, char *group, char *key, char *def, char *line)
     return api_win_show_themed(tag, group, key, def, line);
 }
 
+static int
+c_api_send_stanza(char *stanza)
+{
+    return api_send_stanza(stanza);
+}
+
 void
 c_command_callback(PluginCommand *command, gchar **args)
 {
@@ -236,4 +242,5 @@ c_api_init(void)
     prof_win_focus = c_api_win_focus;
     prof_win_show = c_api_win_show;
     prof_win_show_themed = c_api_win_show_themed;
+    prof_send_stanza = c_api_send_stanza;
 }
diff --git a/src/plugins/profapi.c b/src/plugins/profapi.c
index 84670c33..33bc1694 100644
--- a/src/plugins/profapi.c
+++ b/src/plugins/profapi.c
@@ -69,3 +69,4 @@ int (*prof_win_focus)(PROF_WIN_TAG win) = NULL;
 int (*prof_win_show)(PROF_WIN_TAG win, char *line) = NULL;
 int (*prof_win_show_themed)(PROF_WIN_TAG tag, char *group, char *key, char *def, char *line) = NULL;
 
+int (*prof_send_stanza)(char *stanza) = NULL;
diff --git a/src/plugins/profapi.h b/src/plugins/profapi.h
index 77288f94..5e212110 100644
--- a/src/plugins/profapi.h
+++ b/src/plugins/profapi.h
@@ -69,5 +69,7 @@ int (*prof_win_focus)(PROF_WIN_TAG win);
 int (*prof_win_show)(PROF_WIN_TAG win, char *line);
 int (*prof_win_show_themed)(PROF_WIN_TAG tag, char *group, char *key, char *def, char *line);
 
+int (*prof_send_stanza)(char *stanza);
+
 
 #endif
diff --git a/src/plugins/python_api.c b/src/plugins/python_api.c
index 42222065..7d0ebc89 100644
--- a/src/plugins/python_api.c
+++ b/src/plugins/python_api.c
@@ -433,6 +433,24 @@ python_api_win_show_themed(PyObject *self, PyObject *args)
     return Py_BuildValue("");
 }
 
+static PyObject*
+python_api_send_stanza(PyObject *self, PyObject *args)
+{
+    const char *stanza = NULL;
+    if (!PyArg_ParseTuple(args, "s", &stanza)) {
+        return Py_BuildValue("i", 0);
+    }
+
+    allow_python_threads();
+    int res = api_send_stanza(stanza);
+    disable_python_threads();
+    if (res) {
+        return Py_BuildValue("i", 1);
+    } else {
+        return Py_BuildValue("i", 0);
+    }
+}
+
 void
 python_command_callback(PluginCommand *command, gchar **args)
 {
@@ -522,6 +540,7 @@ static PyMethodDef apiMethods[] = {
     { "win_focus", python_api_win_focus, METH_VARARGS, "Focus a window." },
     { "win_show", python_api_win_show, METH_VARARGS, "Show text in the window." },
     { "win_show_themed", python_api_win_show_themed, METH_VARARGS, "Show themed text in the window." },
+    { "send_stanza", python_api_send_stanza, METH_VARARGS, "Send an XMPP stanza." },
     { NULL, NULL, 0, NULL }
 };
 
diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c
index 35fd9938..b70614de 100644
--- a/src/xmpp/connection.c
+++ b/src/xmpp/connection.c
@@ -480,6 +480,17 @@ jabber_conn_is_secured(void)
     }
 }
 
+gboolean
+jabber_send_stanza(const char *const stanza)
+{
+    if (jabber_conn.conn_status != JABBER_CONNECTED) {
+        return FALSE;
+    } else {
+        xmpp_send_raw(jabber_conn.conn, stanza, strlen(stanza));
+        return TRUE;
+    }
+}
+
 static jabber_conn_status_t
 _jabber_connect(const char *const fulljid, const char *const passwd, const char *const altdomain, int port,
     const char *const tls_policy)
diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c
index c2c56cd6..7a052633 100644
--- a/src/xmpp/iq.c
+++ b/src/xmpp/iq.c
@@ -637,13 +637,13 @@ _caps_response_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza,
     }
 
     if (query == NULL) {
-        log_warning("No query element found.");
+        log_info("No query element found.");
         return 0;
     }
 
     char *node = xmpp_stanza_get_attribute(query, STANZA_ATTR_NODE);
     if (node == NULL) {
-        log_warning("No node attribute found");
+        log_info("No node attribute found");
         return 0;
     }
 
@@ -715,14 +715,14 @@ _caps_response_handler_for_jid(xmpp_conn_t *const conn, xmpp_stanza_t *const sta
     }
 
     if (query == NULL) {
-        log_warning("No query element found.");
+        log_info("No query element found.");
         free(jid);
         return 0;
     }
 
     char *node = xmpp_stanza_get_attribute(query, STANZA_ATTR_NODE);
     if (node == NULL) {
-        log_warning("No node attribute found");
+        log_info("No node attribute found");
         free(jid);
         return 0;
     }
@@ -774,14 +774,14 @@ _caps_response_handler_legacy(xmpp_conn_t *const conn, xmpp_stanza_t *const stan
     }
 
     if (query == NULL) {
-        log_warning("No query element found.");
+        log_info("No query element found.");
         free(expected_node);
         return 0;
     }
 
     char *node = xmpp_stanza_get_attribute(query, STANZA_ATTR_NODE);
     if (node == NULL) {
-        log_warning("No node attribute found");
+        log_info("No node attribute found");
         free(expected_node);
         return 0;
     }
diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h
index 7e3a2c84..8a7d4850 100644
--- a/src/xmpp/xmpp.h
+++ b/src/xmpp/xmpp.h
@@ -159,6 +159,7 @@ void jabber_free_uuid(char *uuid);
 TLSCertificate* jabber_get_tls_peer_cert(void);
 #endif
 gboolean jabber_conn_is_secured(void);
+gboolean jabber_send_stanza(const char *const stanza);
 
 // message functions
 char* message_send_chat(const char *const barejid, const char *const msg);
diff --git a/tests/unittests/xmpp/stub_xmpp.c b/tests/unittests/xmpp/stub_xmpp.c
index dc630198..3ba7f2b3 100644
--- a/tests/unittests/xmpp/stub_xmpp.c
+++ b/tests/unittests/xmpp/stub_xmpp.c
@@ -64,6 +64,12 @@ GList * jabber_get_available_resources(void)
     return NULL;
 }
 
+gboolean
+jabber_send_stanza(const char *const stanza)
+{
+    return TRUE;
+}
+
 // message functions
 char* message_send_chat(const char * const barejid, const char * const msg)
 {
ious revision' href='/gbmor/getwtxt/blame/cache.go?h=v0.3.3&id=bd23ef0959496aba4c6fc8ca2b3969bbf17aa9d5'>^
b29e1c1 ^
c896e6b ^
b29e1c1 ^
c896e6b ^
b29e1c1 ^
c896e6b ^

b29e1c1 ^
c896e6b ^



b29e1c1 ^


cd635e6 ^


c896e6b ^



b29e1c1 ^

c896e6b ^
b29e1c1 ^



c896e6b ^
b29e1c1 ^
c896e6b ^


bded77f ^
c896e6b ^
bded77f ^

c896e6b ^
bded77f ^
c896e6b ^

c896e6b ^
bded77f ^







c896e6b ^
bded77f ^



















c896e6b ^
bded77f ^





c896e6b ^

bded77f ^


c896e6b ^
bded77f ^
c896e6b ^

c896e6b ^






c896e6b ^
2b0d4a5 ^









25972a6 ^











2b0d4a5 ^


25972a6 ^

2b0d4a5 ^
25972a6 ^





2b0d4a5 ^
25972a6 ^


2b0d4a5 ^
2b0d4a5 ^










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