Added local ez_setup.py.
[python-purple] / connection_cbs.pxd
1 #
2 #  Copyright (c) 2008 INdT - Instituto Nokia de Tecnologia
3 #
4 #  This file is part of python-purple.
5 #
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.
10 #
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.
15 #
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/>.
18 #
19
20 cimport purple
21
22 connection_cbs = {}
23
24 cdef extern from *:
25     ctypedef int size_t
26
27 cdef void connect_progress (connection.PurpleConnection *gc, const_char *text,
28                             size_t step, size_t step_count):
29     debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "connection",
30                          "connect_progress\n")
31     try:
32         (<object>connection_cbs["connect_progress"])(<char *>text, step, step_count)
33     except KeyError:
34         pass
35
36 cdef void connected (connection.PurpleConnection *gc):
37     debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "connection",
38                          "connected\n")
39     try:
40         (<object>connection_cbs["connected"])()
41     except KeyError:
42         pass
43
44 cdef void disconnected (connection.PurpleConnection *gc):
45     debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "connection",
46                          "disconnected\n")
47     try:
48         (<object>connection_cbs["disconnected"])()
49     except KeyError:
50         pass
51
52 cdef void notice (connection.PurpleConnection *gc, const_char *text):
53     debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "connection",
54                          "notice\n")
55     try:
56         (<object>connection_cbs["notice"])("notice")
57     except KeyError:
58         pass
59
60 cdef void report_disconnect (connection.PurpleConnection *gc,
61                              const_char *text):
62     debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "connection",
63                          "report_disconnect\n")
64     try:
65         (<object>connection_cbs["report_disconnect"])(<char *>text)
66     except KeyError:
67         pass
68
69 cdef void network_connected ():
70     debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "connection",
71                          "network_connected\n")
72     try:
73         (<object>connection_cbs["network_connected"])("network_connected")
74     except KeyError:
75         pass
76
77 cdef void network_disconnected ():
78     debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "connection",
79                          "network_disconnected\n")
80     try:
81         (<object>connection_cbs["network_disconnected"])("network_disconnected")
82     except KeyError:
83         pass
84
85 cdef void report_disconnect_reason (connection.PurpleConnection *gc,
86                                     connection.PurpleConnectionError reason,
87                                     const_char *text):
88     debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "connection",
89                          "report_disconnect_reason\n")
90
91     reason_string = {
92         0: 'Network error',
93         1: 'Invalid username',
94         2: 'Authentication failed',
95         3: 'Authentication impossible',
96         4: 'No SSL support',
97         5: 'Encryption error',
98         6: 'Name in use',
99         7: 'Invalid settings',
100         8: 'Certificate not provided',
101         9: 'Certificate untrusted',
102         10: 'Certificate expired',
103         11: 'Certificate not activated',
104         12: 'Certificate hostname mismatch',
105         13: 'Certificate fingerprint mismatch',
106         14: 'Certificate self signed',
107         15: 'Certificate error (other)',
108         16: 'Other error' }[reason]
109
110     try:
111         (<object>connection_cbs["report_disconnect_reason"])(reason_string, <char *>text)
112     except KeyError:
113         pass