thrasherbird.pl: Item disco target config was missing.
[thrasher.git] / thperl.h
blob7daa709d19f623cf4ce3b5eff8b2017f85d32198
1 /*
2 * Thrasher Bird - XMPP transport via libpurple
3 * Copyright (C) 2008 Barracuda Networks, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with Thrasher Bird; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
20 #ifdef SWIG
22 %module "THPPW"
25 #include "purple.h"
27 %include libpurple/conversation.h
30 #include "thperl.h"
31 #include "thrasher.h"
32 #include "thblist.h"
33 #include "thconnection.h"
34 #include "glib.h"
38 /*
39 Define a typemap that goes from perl hash to a
40 string -> string g_hash_table (that C subsequently owns)
42 Note that contrary to what I'd expect, this is actually keyed
43 off of the C variable name in the incoming function.
46 %typemap(in) GHashTable* hash_args
48 if (!SvROK($input))
50 croak("$input is not a reference.");
53 if (SvTYPE(SvRV($input)) != SVt_PVHV)
55 croak("$input is not a hashref.");
58 $1 = g_hash_table_new_full(g_str_hash, g_str_equal,
59 g_free, g_free);
61 HV *hv = (HV*)SvRV($input);
62 I32 len;
63 SV *elt;
64 char *key;
65 char *new_value;
66 STRLEN strlen;
68 hv_iterinit(hv);
69 while (elt = hv_iternextsv(hv, &key, &len) )
71 new_value = SvPV(elt, strlen);
72 char *new_key = g_strdup(key);
73 new_value = g_strdup(SvPV(elt, strlen));
75 g_hash_table_insert($1, new_key, new_value);
79 /* Map GList of char* to a Perl string list. */
80 %typemap(out) GList_String* {
81 /* Push new Perl strings onto the Perl argument stack. */
82 GList *c_list = $1;
83 while (c_list) {
84 if (argvi >= items) {
85 EXTEND(sp, 1);
87 ST(argvi) = sv_newmortal();
88 sv_setpv(ST(argvi),
89 (char *) c_list->data);
90 c_list = g_list_next(c_list);
91 argvi++;
93 g_list_free(c_list);
96 #endif /* SWIG */
98 #ifndef THPERL_H
99 #define THPERL_H
101 #include <stdio.h>
102 #include <stdlib.h>
103 #include <string.h>
104 #include <unistd.h>
105 #include <limits.h>
106 #include <error.h>
107 #include <sys/types.h>
108 #include <sys/stat.h>
109 #include <fcntl.h>
110 #include <signal.h>
111 #include <glib.h>
113 #include "blist.h"
115 /* Perl */
116 #include "EXTERN.h"
117 #include "perl.h"
118 #include "XSUB.h"
120 /* libpurple */
121 #include "eventloop.h"
123 /* We can't use the Glib macros because they're int-based */
124 #define LONG_TO_PTR(a) (void*) a
125 #define PTR_TO_LONG(a) (long) a
126 #define TTRUE 1
127 #define TFALSE 0
128 #define TNULL 0
130 typedef struct _perl_callbacks {
131 SV *timeout_add;
132 SV *input_add;
133 SV *source_remove;
134 SV *incoming_msg;
135 SV *presence_in;
136 SV *subscription_add;
137 SV *legacy_user_add_user;
138 SV *connection_error;
139 SV *connection;
140 SV *incoming_chatstate;
141 } perl_callbacks;
143 typedef struct _perl_ft_callbacks {
144 SV *ft_recv_request_cb;
145 SV *ft_recv_accept_cb;
146 SV *ft_recv_start_cb;
147 SV *ft_recv_cancel_cb;
148 SV *ft_recv_complete_cb;
149 SV *ft_send_accept_cb;
150 SV *ft_send_start_cb;
151 SV *ft_send_cancel_cb;
152 SV *ft_send_complete_cb;
153 SV *ft_read_cb;
154 SV *ft_write_cb;
155 SV *ft_data_not_sent_cb;
156 } perl_ft_callbacks;
158 typedef enum {
159 TIMEOUT_ADD = 1,
160 INPUT_ADD = 2
161 } record_type;
163 typedef struct _hash_record {
164 record_type type;
165 void *function;
166 void *data;
167 /* These values pertain only to type == INPUT_ADD */
168 PurpleInputCondition cond;
169 guint fd;
170 } hash_record;
172 typedef GList GList_String;
174 /* Push the internal init through */
175 extern void thrasher_init();
177 void thrasher_blist_init();
178 void thrasher_connection_init();
180 /* Actions */
181 int thrasher_action_login (GHashTable *hash_args);
182 int thrasher_action_logout (char *jid);
183 void thrasher_action_debug_logged_in(void);
184 int thrasher_action_outgoing_msg (char *jid, char *recipient, char *message);
185 void thrasher_action_outgoing_chatstate(char *jid, char *recipient, PurpleTypingState chatstate);
186 int thrasher_action_presence (char *jid, int status, char *message);
187 int thrasher_action_buddy_add (char *jid, char *buddy_name);
188 int thrasher_action_buddy_remove (char *jid, char *buddy_name);
189 void thrasher_action_buddy_authorize(char *jid, char *legacy_username);
190 void thrasher_action_buddy_deauthorize(char *jid, char *legacy_username);
191 GList_String* thrasher_action_get_logged_in_jids();
193 void thrasher_perl_init(void);
194 void thrasher_purple_debug (int tf);
196 /* FT Actions */
197 void thrasher_action_ft_ui_ready(size_t id);
198 void thrasher_action_ft_recv_request_respond(size_t id, unsigned int accept);
199 void thrasher_action_ft_cancel_local(size_t id);
201 /* Perl-end Wrappers */
202 #ifdef SWIG
203 %varargs(1, SV *cb_arg = NULL) thrasher_wrapper_init;
204 #endif /* SWIG */
205 void thrasher_wrapper_init (SV *timeout_add_cb,
206 SV *input_add_cb,
207 SV *source_remove_cb,
208 SV *incoming_msg_cb,
209 SV *presence_in_cb,
210 SV *subscription_add_cb,
211 SV *legacy_user_add_user_cb,
212 SV *connection_error_cb,
213 SV *connection_cb,
214 ...);
216 void thrasher_wrapper_ft_init(SV *ft_recv_request_cb,
217 SV *ft_recv_accept_cb,
218 SV *ft_recv_start_cb,
219 SV *ft_recv_cancel_cb,
220 SV *ft_recv_complete_cb,
221 SV *ft_send_accept_cb,
222 SV *ft_send_start_cb,
223 SV *ft_send_cancel_cb,
224 SV *ft_send_complete_cb,
225 SV *ft_read_cb,
226 SV *ft_write_cb,
227 SV *ft_data_not_sent_cb);
229 int thrasher_wrapper_legacy_user_add_user(const char *jid,
230 const char *sender);
232 int thrasher_wrapper_subscription_add(const char *jid,
233 const char *sender,
234 const guint status);
236 int thrasher_wrapper_incoming_msg (const char *jid,
237 const char *sender,
238 const char *alias,
239 const char *message,
240 PurpleMessageFlags flags);
242 int thrasher_wrapper_connection (const char *jid);
244 /* Would have to swig PurpleStatusPrimitive if Perl were to ever call this. */
245 int thrasher_wrapper_presence_in(const char *jid,
246 const char *sender,
247 const char *alias,
248 const char *group,
249 const PurpleStatusPrimitive status,
250 const char * message);
252 int thrasher_wrapper_connection_error(const char *jid,
253 const guint error_code,
254 const char *message);
256 int thrasher_wrapper_trigger_timeout_func(long key);
257 int thrasher_wrapper_trigger_input_func(long fd, SV *cond, long key);
258 void thrasher_wrapper_destructor ();
260 void thrasher_wrapper_incoming_chatstate(PurpleAccount* pa, const char* who, PurpleTypingState state);
262 /* Core wrapper */
263 int thrasher_wrapper_call_source_remove (long key);
264 long thrasher_wrapper_set_timeout_add (guint interval, GSourceFunc function, gpointer data);
265 long thrasher_wrapper_set_input_add (guint fd, PurpleInputCondition cond, PurpleInputFunction func, gpointer user_data);
267 /* File transfer wrappers */
268 size_t thrasher_wrapper_send_file(const char *jid, const char *who, char *filename, size_t size, char *desc);
269 int thrasher_wrapper_ft_send_start(guint id);
270 void thrasher_wrapper_ft_send_cancel(guint id);
271 void thrasher_wrapper_ft_send_complete(guint id);
272 gssize thrasher_wrapper_ft_read(guint id, guchar **buffer, gssize size);
273 void thrasher_wrapper_ft_data_not_sent(guint id, const char *buffer, gsize size);
274 void thrasher_wrapper_ft_recv_request(PurpleXfer *xfer, const char* remote_filename);
275 gssize thrasher_wrapper_ft_write(guint id, const char *buffer, gssize size);
276 void thrasher_wrapper_ft_recv_cancel(guint id);
277 void thrasher_wrapper_ft_recv_complete(guint id);
279 #ifdef TH_DEBUG
280 long thrasher_wrapper_trigger_timeout_add ();
281 long thrasher_wrapper_trigger_timeout_add2 ();
282 long thrasher_wrapper_trigger_timeout_add3 ();
283 int thrasher_wrapper_trigger_timeout_remove (long key);
284 #endif /* TH_DEBUG */
286 #endif /* THPERL_H */