Handle unescaped accented chars in incoming MSN presences.
[thrasher.git] / thperl.h
blob9930a49f0703ddfb9847908a030dc181d119f600
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 #endif /* SWIG */
81 #ifndef THPERL_H
82 #define THPERL_H
84 #include <stdio.h>
85 #include <stdlib.h>
86 #include <string.h>
87 #include <unistd.h>
88 #include <limits.h>
89 #include <error.h>
90 #include <sys/types.h>
91 #include <sys/stat.h>
92 #include <fcntl.h>
93 #include <signal.h>
94 #include <glib.h>
96 #include "blist.h"
98 /* Perl */
99 #include "EXTERN.h"
100 #include "perl.h"
101 #include "XSUB.h"
103 /* libpurple */
104 #include "eventloop.h"
106 /* We can't use the Glib macros because they're int-based */
107 #define LONG_TO_PTR(a) (void*) a
108 #define PTR_TO_LONG(a) (long) a
109 #define TTRUE 1
110 #define TFALSE 0
111 #define TNULL 0
113 typedef struct _perl_callbacks {
114 SV *timeout_add;
115 SV *input_add;
116 SV *source_remove;
117 SV *incoming_msg;
118 SV *presence_in;
119 SV *subscription_add;
120 SV *legacy_user_add_user;
121 SV *connection_error;
122 SV *connection;
123 SV *incoming_chatstate;
124 } perl_callbacks;
126 typedef struct _perl_ft_callbacks {
127 SV *ft_recv_request_cb;
128 SV *ft_recv_accept_cb;
129 SV *ft_recv_start_cb;
130 SV *ft_recv_cancel_cb;
131 SV *ft_recv_complete_cb;
132 SV *ft_send_accept_cb;
133 SV *ft_send_start_cb;
134 SV *ft_send_cancel_cb;
135 SV *ft_send_complete_cb;
136 SV *ft_read_cb;
137 SV *ft_write_cb;
138 SV *ft_data_not_sent_cb;
139 } perl_ft_callbacks;
141 typedef enum {
142 TIMEOUT_ADD = 1,
143 INPUT_ADD = 2
144 } record_type;
146 typedef struct _hash_record {
147 record_type type;
148 void *function;
149 void *data;
150 /* These values pertain only to type == INPUT_ADD */
151 PurpleInputCondition cond;
152 guint fd;
153 } hash_record;
155 /* Push the internal init through */
156 extern void thrasher_init();
158 void thrasher_blist_init();
159 void thrasher_connection_init();
161 /* Actions */
162 int thrasher_action_login (GHashTable *hash_args);
163 int thrasher_action_logout (char *jid);
164 void thrasher_action_debug_logged_in(void);
165 int thrasher_action_outgoing_msg (char *jid, char *recipient, char *message);
166 void thrasher_action_outgoing_chatstate(char *jid, char *recipient, PurpleTypingState chatstate);
167 int thrasher_action_presence (char *jid, int status, char *message);
168 int thrasher_action_buddy_add (char *jid, char *buddy_name);
169 int thrasher_action_buddy_remove (char *jid, char *buddy_name);
170 void thrasher_action_buddy_authorize(char *jid, char *legacy_username);
171 void thrasher_action_buddy_deauthorize(char *jid, char *legacy_username);
174 void thrasher_perl_init(void);
175 void thrasher_purple_debug (int tf);
177 /* FT Actions */
178 void thrasher_action_ft_ui_ready(size_t id);
179 void thrasher_action_ft_recv_request_respond(size_t id, unsigned int accept);
180 void thrasher_action_ft_cancel_local(size_t id);
182 /* Perl-end Wrappers */
183 #ifdef SWIG
184 %varargs(1, SV *cb_arg = NULL) thrasher_wrapper_init;
185 #endif /* SWIG */
186 void thrasher_wrapper_init (SV *timeout_add_cb,
187 SV *input_add_cb,
188 SV *source_remove_cb,
189 SV *incoming_msg_cb,
190 SV *presence_in_cb,
191 SV *subscription_add_cb,
192 SV *legacy_user_add_user_cb,
193 SV *connection_error_cb,
194 SV *connection_cb,
195 ...);
197 void thrasher_wrapper_ft_init(SV *ft_recv_request_cb,
198 SV *ft_recv_accept_cb,
199 SV *ft_recv_start_cb,
200 SV *ft_recv_cancel_cb,
201 SV *ft_recv_complete_cb,
202 SV *ft_send_accept_cb,
203 SV *ft_send_start_cb,
204 SV *ft_send_cancel_cb,
205 SV *ft_send_complete_cb,
206 SV *ft_read_cb,
207 SV *ft_write_cb,
208 SV *ft_data_not_sent_cb);
210 int thrasher_wrapper_legacy_user_add_user(const char *jid,
211 const char *sender);
213 int thrasher_wrapper_subscription_add(const char *jid,
214 const char *sender,
215 const guint status);
217 int thrasher_wrapper_incoming_msg (const char *jid,
218 const char *sender,
219 const char *alias,
220 const char *message,
221 PurpleMessageFlags flags);
223 int thrasher_wrapper_connection (const char *jid);
225 /* Would have to swig PurpleStatusPrimitive if Perl were to ever call this. */
226 int thrasher_wrapper_presence_in(const char *jid,
227 const char *sender,
228 const char *alias,
229 const char *group,
230 const PurpleStatusPrimitive status,
231 const char * message);
233 int thrasher_wrapper_connection_error(const char *jid,
234 const guint error_code,
235 const char *message);
237 int thrasher_wrapper_trigger_timeout_func(long key);
238 int thrasher_wrapper_trigger_input_func(long fd, SV *cond, long key);
239 void thrasher_wrapper_destructor ();
241 void thrasher_wrapper_incoming_chatstate(PurpleAccount* pa, const char* who, PurpleTypingState state);
243 /* Core wrapper */
244 int thrasher_wrapper_call_source_remove (long key);
245 long thrasher_wrapper_set_timeout_add (guint interval, GSourceFunc function, gpointer data);
246 long thrasher_wrapper_set_input_add (guint fd, PurpleInputCondition cond, PurpleInputFunction func, gpointer user_data);
248 /* File transfer wrappers */
249 size_t thrasher_wrapper_send_file(const char *jid, const char *who, char *filename, size_t size, char *desc);
250 int thrasher_wrapper_ft_send_start(guint id);
251 void thrasher_wrapper_ft_send_cancel(guint id);
252 void thrasher_wrapper_ft_send_complete(guint id);
253 gssize thrasher_wrapper_ft_read(guint id, guchar **buffer, gssize size);
254 void thrasher_wrapper_ft_data_not_sent(guint id, const guchar *buffer, gsize size);
255 void thrasher_wrapper_ft_recv_request(PurpleXfer *xfer, const char* remote_filename);
256 gssize thrasher_wrapper_ft_write(guint id, const guchar *buffer, gssize size);
257 void thrasher_wrapper_ft_recv_cancel(guint id);
258 void thrasher_wrapper_ft_recv_complete(guint id);
260 #ifdef TH_DEBUG
261 long thrasher_wrapper_trigger_timeout_add ();
262 long thrasher_wrapper_trigger_timeout_add2 ();
263 long thrasher_wrapper_trigger_timeout_add3 ();
264 int thrasher_wrapper_trigger_timeout_remove (long key);
265 #endif /* TH_DEBUG */
267 #endif /* THPERL_H */