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/>.
25 ctypedef char const_gchar "const gchar"
27 cdef void signal_signed_on_cb(connection.PurpleConnection *gc, \
30 Emitted when a connection has signed on.
31 @params gc The connection that has signed on.
33 cdef account.PurpleAccount *acc = connection.purple_connection_get_account(gc)
34 cdef char *c_username = NULL
35 cdef char *c_protocol_id = NULL
37 c_username = <char *> account.purple_account_get_username(acc)
38 if c_username == NULL:
43 c_protocol_id = <char *> account.purple_account_get_protocol_id(acc)
44 if c_protocol_id == NULL:
47 protocol_id = c_protocol_id
49 if signal_cbs.has_key("signed-on"):
50 (<object> signal_cbs["signed-on"])(username, protocol_id)
52 cdef void signal_signed_off_cb(connection.PurpleConnection *gc, \
55 Emitted when a connection has signed off.
56 @params gc The connection that has signed off.
58 cdef account.PurpleAccount *acc = connection.purple_connection_get_account(gc)
59 cdef char *c_username = NULL
60 cdef char *c_protocol_id = NULL
62 c_username = <char *> account.purple_account_get_username(acc)
63 if c_username == NULL:
68 c_protocol_id = <char *> account.purple_account_get_protocol_id(acc)
69 if c_protocol_id == NULL:
72 protocol_id = c_protocol_id
74 if signal_cbs.has_key("signed-off"):
75 (<object> signal_cbs["signed-off"])(username, protocol_id)
77 cdef void signal_connection_error_cb(connection.PurpleConnection *gc, \
78 connection.PurpleConnectionError err, const_gchar *c_desc):
80 Emitted when a connection error occurs, before signed-off.
81 @params gc The connection on which the error has occured
82 @params err The error that occured
83 @params desc A description of the error, giving more information
85 cdef account.PurpleAccount *acc = connection.purple_connection_get_account(gc)
86 cdef char *c_username = NULL
87 cdef char *c_protocol_id = NULL
89 c_username = <char *> account.purple_account_get_username(acc)
91 username = <char *> c_username
95 c_protocol_id = <char *> account.purple_account_get_protocol_id(acc)
97 protocol_id = <char *> c_protocol_id
103 1: "Invalid username",
104 2: "Authentication failed",
105 3: "Authentication impossible",
107 5: "Encryption error",
109 7: "Invalid settings",
110 8: "SSL certificate not provided",
111 9: "SSL certificate untrusted",
112 10: "SSL certificate expired",
113 11: "SSL certificate not activated",
114 12: "SSL certificate hostname mismatch",
115 13: "SSL certificate fingerprint mismatch",
116 14: "SSL certificate self signed",
117 15: "SSL certificate other error",
118 16: "Other error" }[<int> err]
121 desc = str(<char *> c_desc)
125 if signal_cbs.has_key("connection-error"):
126 (<object> signal_cbs["connection-error"])(username, protocol_id, \
129 cdef void signal_buddy_signed_on_cb(blist.PurpleBuddy *buddy):
131 Emitted when a buddy on your buddy list signs on.
132 @params buddy The buddy that signed on.
134 cdef char *c_name = NULL
135 cdef char *c_alias = NULL
137 c_name = <char *> blist.purple_buddy_get_name(buddy)
143 c_alias = <char *> blist.purple_buddy_get_alias_only(buddy)
149 if signal_cbs.has_key("buddy-signed-on"):
150 (<object> signal_cbs["buddy-signed-on"])(name, alias)
152 cdef void signal_buddy_signed_off_cb(blist.PurpleBuddy *buddy):
154 Emitted when a buddy on your buddy list signs off.
155 @params buddy The buddy that signed off.
157 cdef char *c_name = NULL
158 cdef char *c_alias = NULL
160 c_name = <char *> blist.purple_buddy_get_name(buddy)
166 c_alias = <char *> blist.purple_buddy_get_alias_only(buddy)
172 if signal_cbs.has_key("buddy-signed-off"):
173 (<object> signal_cbs["buddy-signed-off"])(name, alias)
175 cdef glib.gboolean signal_receiving_im_msg_cb(account.PurpleAccount *account, \
176 char **sender, char **message, conversation.PurpleConversation *conv, \
177 conversation.PurpleMessageFlags *flags):
179 Emitted when an IM is received. The callback can replace the name of the
180 sender, the message, or the flags by modifying the pointer to the strings
181 and integer. This can also be used to cancel a message by returning TRUE.
182 @note Make sure to free *sender and *message before you replace them!
183 @returns TRUE if the message should be canceled, or FALSE otherwise.
184 @params account The account the message was received on.
185 @params sender A pointer to the username of the sender.
186 @params message A pointer to the message that was sent.
187 @params conv The IM conversation.
188 @params flags A pointer to the IM message flags.
190 cdef blist.PurpleBuddy *buddy = blist.purple_find_buddy(account, sender[0])
191 cdef char *c_alias = NULL
193 c_alias = <char *> blist.purple_buddy_get_alias_only(buddy)
199 stripped = util.purple_markup_strip_html(message[0])
201 if signal_cbs.has_key("receiving-im-msg"):
202 return (<object> signal_cbs["receiving-im-msg"])(sender[0], alias, stripped)
204 cdef void jabber_receiving_xmlnode_cb(connection.PurpleConnection *gc, \
205 xmlnode.xmlnode **packet, glib.gpointer null):
207 Emitted when jabber receives a XML node.
209 message = xmlnode.xmlnode_to_str(packet[0], NULL)
211 if signal_cbs.has_key("jabber-receiving-xmlnode"):
212 (<object> signal_cbs["jabber-receiving-xmlnode"])(message)