Fix crashes when filenames end up being NULL in some prpls.
[pidgin-git.git] / libpurple / whiteboard.c
blob319191d5271fe2064e7cc6dd0d56abf8beb47568
1 /*
2 * purple
4 * Purple is the legal property of its developers, whose names are too numerous
5 * to list here. Please refer to the COPYRIGHT file distributed with this
6 * source distribution.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
24 #include <string.h>
26 #include "internal.h"
27 #include "whiteboard.h"
28 #include "prpl.h"
30 /******************************************************************************
31 * Globals
32 *****************************************************************************/
33 static PurpleWhiteboardUiOps *whiteboard_ui_ops = NULL;
34 /* static PurpleWhiteboardPrplOps *whiteboard_prpl_ops = NULL; */
36 static GList *wbList = NULL;
38 /*static gboolean auto_accept = TRUE; */
40 /******************************************************************************
41 * API
42 *****************************************************************************/
43 void purple_whiteboard_set_ui_ops(PurpleWhiteboardUiOps *ops)
45 whiteboard_ui_ops = ops;
48 void purple_whiteboard_set_prpl_ops(PurpleWhiteboard *wb, PurpleWhiteboardPrplOps *ops)
50 wb->prpl_ops = ops;
53 PurpleWhiteboard *purple_whiteboard_create(PurpleAccount *account, const char *who, int state)
55 PurplePluginProtocolInfo *prpl_info;
56 PurpleWhiteboard *wb = g_new0(PurpleWhiteboard, 1);
58 wb->account = account;
59 wb->state = state;
60 wb->who = g_strdup(who);
62 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(purple_connection_get_prpl(
63 purple_account_get_connection(account)));
64 purple_whiteboard_set_prpl_ops(wb, prpl_info->whiteboard_prpl_ops);
66 /* Start up protocol specifics */
67 if(wb->prpl_ops && wb->prpl_ops->start)
68 wb->prpl_ops->start(wb);
70 wbList = g_list_append(wbList, wb);
72 return wb;
75 void purple_whiteboard_destroy(PurpleWhiteboard *wb)
77 g_return_if_fail(wb != NULL);
79 if(wb->ui_data)
81 /* Destroy frontend */
82 if(whiteboard_ui_ops && whiteboard_ui_ops->destroy)
83 whiteboard_ui_ops->destroy(wb);
86 /* Do protocol specific session ending procedures */
87 if(wb->prpl_ops && wb->prpl_ops->end)
88 wb->prpl_ops->end(wb);
90 g_free(wb->who);
91 wbList = g_list_remove(wbList, wb);
92 g_free(wb);
95 void purple_whiteboard_start(PurpleWhiteboard *wb)
97 /* Create frontend for whiteboard */
98 if(whiteboard_ui_ops && whiteboard_ui_ops->create)
99 whiteboard_ui_ops->create(wb);
102 /* Looks through the list of whiteboard sessions for one that is between
103 * usernames 'me' and 'who'. Returns a pointer to a matching whiteboard
104 * session; if none match, it returns NULL.
106 PurpleWhiteboard *purple_whiteboard_get_session(const PurpleAccount *account, const char *who)
108 PurpleWhiteboard *wb;
110 GList *l = wbList;
112 /* Look for a whiteboard session between the local user and the remote user
114 while(l != NULL)
116 wb = l->data;
118 if(wb->account == account && !strcmp(wb->who, who))
119 return wb;
121 l = l->next;
124 return NULL;
127 void purple_whiteboard_draw_list_destroy(GList *draw_list)
129 g_list_free(draw_list);
132 gboolean purple_whiteboard_get_dimensions(const PurpleWhiteboard *wb, int *width, int *height)
134 PurpleWhiteboardPrplOps *prpl_ops = wb->prpl_ops;
136 if (prpl_ops && prpl_ops->get_dimensions)
138 prpl_ops->get_dimensions(wb, width, height);
139 return TRUE;
142 return FALSE;
145 void purple_whiteboard_set_dimensions(PurpleWhiteboard *wb, int width, int height)
147 if(whiteboard_ui_ops && whiteboard_ui_ops->set_dimensions)
148 whiteboard_ui_ops->set_dimensions(wb, width, height);
151 void purple_whiteboard_send_draw_list(PurpleWhiteboard *wb, GList *list)
153 PurpleWhiteboardPrplOps *prpl_ops = wb->prpl_ops;
155 if (prpl_ops && prpl_ops->send_draw_list)
156 prpl_ops->send_draw_list(wb, list);
159 void purple_whiteboard_draw_point(PurpleWhiteboard *wb, int x, int y, int color, int size)
161 if(whiteboard_ui_ops && whiteboard_ui_ops->draw_point)
162 whiteboard_ui_ops->draw_point(wb, x, y, color, size);
165 void purple_whiteboard_draw_line(PurpleWhiteboard *wb, int x1, int y1, int x2, int y2, int color, int size)
167 if(whiteboard_ui_ops && whiteboard_ui_ops->draw_line)
168 whiteboard_ui_ops->draw_line(wb, x1, y1, x2, y2, color, size);
171 void purple_whiteboard_clear(PurpleWhiteboard *wb)
173 if(whiteboard_ui_ops && whiteboard_ui_ops->clear)
174 whiteboard_ui_ops->clear(wb);
177 void purple_whiteboard_send_clear(PurpleWhiteboard *wb)
179 PurpleWhiteboardPrplOps *prpl_ops = wb->prpl_ops;
181 if (prpl_ops && prpl_ops->clear)
182 prpl_ops->clear(wb);
185 void purple_whiteboard_send_brush(PurpleWhiteboard *wb, int size, int color)
187 PurpleWhiteboardPrplOps *prpl_ops = wb->prpl_ops;
189 if (prpl_ops && prpl_ops->set_brush)
190 prpl_ops->set_brush(wb, size, color);
193 gboolean purple_whiteboard_get_brush(const PurpleWhiteboard *wb, int *size, int *color)
195 PurpleWhiteboardPrplOps *prpl_ops = wb->prpl_ops;
197 if (prpl_ops && prpl_ops->get_brush)
199 prpl_ops->get_brush(wb, size, color);
200 return TRUE;
202 return FALSE;
205 void purple_whiteboard_set_brush(PurpleWhiteboard *wb, int size, int color)
207 if (whiteboard_ui_ops && whiteboard_ui_ops->set_brush)
208 whiteboard_ui_ops->set_brush(wb, size, color);