comparison src/conversation.c @ 7947:746404b12236

[gaim-migrate @ 8621] I removed some more of those dumb allocations. This also fixes a problem with changing the text of outgoing messages from a perl script, and I guess from C and tcl, also. Basically, before this change, if you editing a message from a script, your changes would get sent to the other person, but the old message would still get shown to the Gaim user. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sun, 28 Dec 2003 23:06:57 +0000
parents 68f70cf074d0
children 5f86d21b6232
comparison
equal deleted inserted replaced
7946:4eb96e3cf633 7947:746404b12236
181 common_send(GaimConversation *conv, const char *message) 181 common_send(GaimConversation *conv, const char *message)
182 { 182 {
183 GaimConversationType type; 183 GaimConversationType type;
184 GaimConnection *gc; 184 GaimConnection *gc;
185 GaimConversationUiOps *ops; 185 GaimConversationUiOps *ops;
186 char *buf, *buf2, *buffy = NULL; 186 char *buffy = NULL;
187 int plugin_return; 187 int plugin_return;
188 int limit;
189 int err = 0; 188 int err = 0;
190 GList *first; 189 GList *first;
191 190
191 if (strlen(message) == 0)
192 return;
193
192 gc = gaim_conversation_get_gc(conv); 194 gc = gaim_conversation_get_gc(conv);
193 195
194 g_return_if_fail(gc != NULL); 196 g_return_if_fail(gc != NULL);
195 197
196 type = gaim_conversation_get_type(conv); 198 type = gaim_conversation_get_type(conv);
197 ops = gaim_conversation_get_ui_ops(conv); 199 ops = gaim_conversation_get_ui_ops(conv);
198 200
199 limit = 32 * 1024; /* You shouldn't be sending more than 32K in your
200 messages. That's a book. */
201
202 buf = g_malloc(limit);
203 strncpy(buf, message, limit);
204
205 if (strlen(buf) == 0) {
206 g_free(buf);
207
208 return;
209 }
210
211 first = g_list_first(conv->send_history); 201 first = g_list_first(conv->send_history);
212 202
213 if (first->data) 203 if (first->data)
214 g_free(first->data); 204 g_free(first->data);
215 205
216 first->data = g_strdup(buf); 206 first->data = g_strdup(message);
217 207
218 conv->send_history = g_list_prepend(first, NULL); 208 conv->send_history = g_list_prepend(first, NULL);
219
220 buf2 = g_malloc(limit);
221 209
222 if ((gc->flags & GAIM_CONNECTION_HTML) && 210 if ((gc->flags & GAIM_CONNECTION_HTML) &&
223 gaim_prefs_get_bool("/core/conversations/send_urls_as_links")) { 211 gaim_prefs_get_bool("/core/conversations/send_urls_as_links")) {
224 212
225 buffy = gaim_markup_linkify(buf); 213 buffy = gaim_markup_linkify(message);
226 } 214 }
227 else 215 else
228 buffy = g_strdup(buf); 216 buffy = g_strdup(message);
229 217
230 plugin_return = 218 plugin_return =
231 GPOINTER_TO_INT(gaim_signal_emit_return_1( 219 GPOINTER_TO_INT(gaim_signal_emit_return_1(
232 gaim_conversations_get_handle(), 220 gaim_conversations_get_handle(),
233 (type == GAIM_CONV_IM 221 (type == GAIM_CONV_IM
234 ? "displaying-im-msg" : "displaying-chat-msg"), 222 ? "displaying-im-msg" : "displaying-chat-msg"),
235 gaim_conversation_get_account(conv), conv, &buffy)); 223 gaim_conversation_get_account(conv), conv, &buffy));
236 224
237 if (buffy == NULL) { 225 if (buffy == NULL)
238 g_free(buf2);
239 g_free(buf);
240 return; 226 return;
241 }
242 227
243 if (plugin_return) { 228 if (plugin_return) {
244 g_free(buffy); 229 g_free(buffy);
245 g_free(buf2);
246 g_free(buf);
247 return; 230 return;
248 } 231 }
249
250 strncpy(buf, buffy, limit);
251 g_free(buffy);
252 232
253 gaim_signal_emit(gaim_conversations_get_handle(), 233 gaim_signal_emit(gaim_conversations_get_handle(),
254 (type == GAIM_CONV_IM ? "displayed-im-msg" : "displayed-chat-msg"), 234 (type == GAIM_CONV_IM ? "displayed-im-msg" : "displayed-chat-msg"),
255 gaim_conversation_get_account(conv), conv, buffy); 235 gaim_conversation_get_account(conv), conv, buffy);
256 236
257 if (type == GAIM_CONV_IM) { 237 if (type == GAIM_CONV_IM) {
258 GaimConvIm *im = GAIM_CONV_IM(conv); 238 GaimConvIm *im = GAIM_CONV_IM(conv);
259 239
260 buffy = g_strdup(buf);
261 gaim_signal_emit(gaim_conversations_get_handle(), "sending-im-msg", 240 gaim_signal_emit(gaim_conversations_get_handle(), "sending-im-msg",
262 gaim_conversation_get_account(conv), 241 gaim_conversation_get_account(conv),
263 gaim_conversation_get_name(conv), &buffy); 242 gaim_conversation_get_name(conv), &buffy);
264 243
265 if (buffy != NULL) { 244 if (buffy != NULL && buffy[0] != '\0') {
266 GaimConvImFlags imflags = 0; 245 GaimConvImFlags imflags = 0;
267 GaimMessageFlags msgflags = GAIM_MESSAGE_SEND; 246 GaimMessageFlags msgflags = GAIM_MESSAGE_SEND;
268 247
269 if (im->images != NULL) { 248 if (im->images != NULL) {
270 imflags |= GAIM_CONV_IM_IMAGES; 249 imflags |= GAIM_CONV_IM_IMAGES;
273 252
274 err = serv_send_im(gc, gaim_conversation_get_name(conv), 253 err = serv_send_im(gc, gaim_conversation_get_name(conv),
275 buffy, imflags); 254 buffy, imflags);
276 255
277 if (err > 0) 256 if (err > 0)
278 gaim_conv_im_write(im, NULL, buf, msgflags, time(NULL)); 257 gaim_conv_im_write(im, NULL, buffy, msgflags, time(NULL));
279 258
280 if (im->images != NULL) { 259 if (im->images != NULL) {
281 GSList *tempy; 260 GSList *tempy;
282 int image; 261 int image;
283 262
294 } 273 }
295 274
296 gaim_signal_emit(gaim_conversations_get_handle(), "sent-im-msg", 275 gaim_signal_emit(gaim_conversations_get_handle(), "sent-im-msg",
297 gaim_conversation_get_account(conv), 276 gaim_conversation_get_account(conv),
298 gaim_conversation_get_name(conv), buffy); 277 gaim_conversation_get_name(conv), buffy);
299
300 g_free(buffy);
301 } 278 }
302 } 279 }
303 else { 280 else {
304 buffy = g_strdup(buf);
305
306 gaim_signal_emit(gaim_conversations_get_handle(), "sending-chat-msg", 281 gaim_signal_emit(gaim_conversations_get_handle(), "sending-chat-msg",
307 gaim_conversation_get_account(conv), &buffy, 282 gaim_conversation_get_account(conv), &buffy,
308 gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv))); 283 gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv)));
309 284
310 if (buffy != NULL) { 285 if (buffy != NULL && buffy[0] != '\0') {
311 err = serv_chat_send(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv)), buffy); 286 err = serv_chat_send(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv)), buffy);
312 287
313 gaim_signal_emit(gaim_conversations_get_handle(), "sent-chat-msg", 288 gaim_signal_emit(gaim_conversations_get_handle(), "sent-chat-msg",
314 gaim_conversation_get_account(conv), buf, 289 gaim_conversation_get_account(conv), buffy,
315 gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv))); 290 gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv)));
316 291 }
317 g_free(buffy); 292 }
318 }
319 }
320
321 g_free(buf2);
322 g_free(buf);
323 293
324 if (err < 0) { 294 if (err < 0) {
325 if (err == -E2BIG) { 295 if (err == -E2BIG) {
326 gaim_notify_error(NULL, NULL, 296 gaim_notify_error(NULL, NULL,
327 _("Unable to send message. The message is " 297 _("Unable to send message. The message is "