2 # Copyright (c) 2008 INdT - Instituto Nokia de Tecnologia
4 # This file is part of python-purple.
6 # python-purple is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # python-purple is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 ctypedef char const_gchar "const gchar"
25 cdef void signal_signed_on_cb(connection.PurpleConnection *gc, \
28 Emitted when a connection has signed on.
29 @params gc The connection that has signed on.
31 cdef account.PurpleAccount *acc = connection.purple_connection_get_account(gc)
32 cdef char *c_username = NULL
33 cdef char *c_protocol_id = NULL
35 c_username = <char *> account.purple_account_get_username(acc)
36 if c_username == NULL:
41 c_protocol_id = <char *> account.purple_account_get_protocol_id(acc)
42 if c_protocol_id == NULL:
45 protocol_id = c_protocol_id
47 if "signed-on" in signal_cbs:
48 (<object> signal_cbs["signed-on"])(username, protocol_id)
50 cdef void signal_signed_off_cb(connection.PurpleConnection *gc, \
53 Emitted when a connection has signed off.
54 @params gc The connection that has signed off.
56 cdef account.PurpleAccount *acc = connection.purple_connection_get_account(gc)
57 cdef char *c_username = NULL
58 cdef char *c_protocol_id = NULL
60 c_username = <char *> account.purple_account_get_username(acc)
61 if c_username == NULL:
66 c_protocol_id = <char *> account.purple_account_get_protocol_id(acc)
67 if c_protocol_id == NULL:
70 protocol_id = c_protocol_id
72 if "signed-off" in signal_cbs:
73 (<object> signal_cbs["signed-off"])(username, protocol_id)
75 cdef void signal_connection_error_cb(connection.PurpleConnection *gc, \
76 connection.PurpleConnectionError err, const_gchar *c_desc):
78 Emitted when a connection error occurs, before signed-off.
79 @params gc The connection on which the error has occured
80 @params err The error that occured
81 @params desc A description of the error, giving more information
83 cdef account.PurpleAccount *acc = connection.purple_connection_get_account(gc)
84 cdef char *c_username = NULL
85 cdef char *c_protocol_id = NULL
87 c_username = <char *> account.purple_account_get_username(acc)
89 username = <char *> c_username
93 c_protocol_id = <char *> account.purple_account_get_protocol_id(acc)
95 protocol_id = <char *> c_protocol_id
101 1: "Invalid username",
102 2: "Authentication failed",
103 3: "Authentication impossible",
105 5: "Encryption error",
107 7: "Invalid settings",
108 8: "SSL certificate not provided",
109 9: "SSL certificate untrusted",
110 10: "SSL certificate expired",
111 11: "SSL certificate not activated",
112 12: "SSL certificate hostname mismatch",
113 13: "SSL certificate fingerprint mismatch",
114 14: "SSL certificate self signed",
115 15: "SSL certificate other error",
116 16: "Other error" }[<int> err]
119 desc = str(<char *> c_desc)
123 if "connection-error" in signal_cbs:
124 (<object> signal_cbs["connection-error"])(username, protocol_id, \
127 cdef void signal_buddy_signed_on_cb(blist.PurpleBuddy *buddy):
129 Emitted when a buddy on your buddy list signs on.
130 @params buddy The buddy that signed on.
132 cdef char *c_name = NULL
133 cdef char *c_alias = NULL
135 c_name = <char *> blist.purple_buddy_get_name(buddy)
141 c_alias = <char *> blist.purple_buddy_get_alias_only(buddy)
147 if "buddy-signed-on" in signal_cbs:
148 (<object> signal_cbs["buddy-signed-on"])(name, alias)
150 cdef void signal_buddy_signed_off_cb(blist.PurpleBuddy *buddy):
152 Emitted when a buddy on your buddy list signs off.
153 @params buddy The buddy that signed off.
155 cdef char *c_name = NULL
156 cdef char *c_alias = NULL
158 c_name = <char *> blist.purple_buddy_get_name(buddy)
164 c_alias = <char *> blist.purple_buddy_get_alias_only(buddy)
170 if "buddy-signed-off" in signal_cbs:
171 (<object> signal_cbs["buddy-signed-off"])(name, alias)
173 cdef glib.gboolean signal_receiving_im_msg_cb(account.PurpleAccount *account, \
174 char **sender, char **message, conversation.PurpleConversation *conv, \
175 conversation.PurpleMessageFlags *flags):
177 Emitted when an IM is received. The callback can replace the name of the
178 sender, the message, or the flags by modifying the pointer to the strings
179 and integer. This can also be used to cancel a message by returning TRUE.
180 @note Make sure to free *sender and *message before you replace them!
181 @returns TRUE if the message should be canceled, or FALSE otherwise.
182 @params account The account the message was received on.
183 @params sender A pointer to the username of the sender.
184 @params message A pointer to the message that was sent.
185 @params conv The IM conversation.
186 @params flags A pointer to the IM message flags.
188 cdef blist.PurpleBuddy *buddy = blist.purple_find_buddy(account, sender[0])
189 cdef char *c_alias = NULL
191 c_alias = <char *> blist.purple_buddy_get_alias_only(buddy)
197 stripped = util.purple_markup_strip_html(message[0])
199 if "receiving-im-msg" in signal_cbs:
200 return (<object> signal_cbs["receiving-im-msg"])(sender[0], alias, stripped)
202 cdef void jabber_receiving_xmlnode_cb(connection.PurpleConnection *gc, \
203 xmlnode.xmlnode **packet, glib.gpointer null):
205 Emitted when jabber receives a XML node.
207 message = xmlnode.xmlnode_to_str(packet[0], NULL)
209 if "jabber-receiving-xmlnode" in signal_cbs:
210 (<object> signal_cbs["jabber-receiving-xmlnode"])(message)