comparison src/protocols/silc/ft.c @ 12143:cbebda5f019c

[gaim-migrate @ 14444] SF Patch #1360399 from Evan Schoenberg (evands) "I discussed this previously with Mark and he said it'd be fine. This factors out the part of the send_file function which creates a new GaimXfer into a separate prpl function, new_xfer. It's called in each of the existing send_file functions. This is needed so that another client (okay, Adium) can get a new outgoing GaimXfer from a prpl without depending upon the specific ft.c logic of send_file; previously I was adding a duplicate method to each prpl and then calling it directly." I fixed a couple small bugs in this. Otherwise, it looks good, and seems like a reasonable libgaim request. committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Sat, 19 Nov 2005 00:26:12 +0000
parents 45ceaa1ccc6e
children 4e46eeec4ace
comparison
equal deleted inserted replaced
12142:0c672be21798 12143:cbebda5f019c
345 345
346 silcgaim_ftp_send_file(client->application, (const char *)context, NULL); 346 silcgaim_ftp_send_file(client->application, (const char *)context, NULL);
347 silc_free(context); 347 silc_free(context);
348 } 348 }
349 349
350 void silcgaim_ftp_send_file(GaimConnection *gc, const char *name, const char *file) 350 GaimXfer *silcgaim_ftp_new_xfer(GaimConnection *gc, const char *name)
351 { 351 {
352 SilcGaim sg = gc->proto_data; 352 SilcGaim sg = gc->proto_data;
353 SilcClient client = sg->client; 353 SilcClient client = sg->client;
354 SilcClientConnection conn = sg->conn; 354 SilcClientConnection conn = sg->conn;
355 SilcClientEntry *clients; 355 SilcClientEntry *clients;
356 SilcUInt32 clients_count; 356 SilcUInt32 clients_count;
357 SilcGaimXfer xfer; 357 SilcGaimXfer xfer;
358 char *nickname; 358 char *nickname;
359 359
360 if (!name) 360 g_return_val_if_fail(name != NULL, NULL);
361 return;
362 361
363 if (!silc_parse_userfqdn(name, &nickname, NULL)) 362 if (!silc_parse_userfqdn(name, &nickname, NULL))
364 return; 363 return NULL;
365 364
366 /* Find client entry */ 365 /* Find client entry */
367 clients = silc_client_get_clients_local(client, conn, nickname, name, 366 clients = silc_client_get_clients_local(client, conn, nickname, name,
368 &clients_count); 367 &clients_count);
369 if (!clients) { 368 if (!clients) {
370 silc_client_get_clients(client, conn, nickname, NULL, 369 silc_client_get_clients(client, conn, nickname, NULL,
371 silcgaim_ftp_send_file_resolved, 370 silcgaim_ftp_send_file_resolved,
372 strdup(name)); 371 strdup(name));
373 silc_free(nickname); 372 silc_free(nickname);
374 return; 373 return NULL;
375 } 374 }
376 375
377 xfer = silc_calloc(1, sizeof(*xfer)); 376 xfer = silc_calloc(1, sizeof(*xfer));
378 if (!xfer) 377
379 return; 378 g_return_val_if_fail(xfer != NULL, NULL);
379
380 xfer->sg = sg; 380 xfer->sg = sg;
381 xfer->client_entry = clients[0]; 381 xfer->client_entry = clients[0];
382 xfer->xfer = gaim_xfer_new(xfer->sg->account, GAIM_XFER_SEND, 382 xfer->xfer = gaim_xfer_new(xfer->sg->account, GAIM_XFER_SEND,
383 xfer->client_entry->nickname); 383 xfer->client_entry->nickname);
384 if (!xfer->xfer) { 384 if (!xfer->xfer) {
385 silc_client_file_close(xfer->sg->client, xfer->sg->conn, xfer->session_id); 385 silc_client_file_close(xfer->sg->client, xfer->sg->conn, xfer->session_id);
386 g_free(xfer->hostname); 386 g_free(xfer->hostname);
387 silc_free(xfer); 387 silc_free(xfer);
388 return; 388 return NULL;
389 } 389 }
390 gaim_xfer_set_init_fnc(xfer->xfer, silcgaim_ftp_send); 390 gaim_xfer_set_init_fnc(xfer->xfer, silcgaim_ftp_send);
391 gaim_xfer_set_request_denied_fnc(xfer->xfer, silcgaim_ftp_request_denied); 391 gaim_xfer_set_request_denied_fnc(xfer->xfer, silcgaim_ftp_request_denied);
392 gaim_xfer_set_cancel_send_fnc(xfer->xfer, silcgaim_ftp_send_cancel); 392 gaim_xfer_set_cancel_send_fnc(xfer->xfer, silcgaim_ftp_send_cancel);
393 xfer->xfer->data = xfer; 393 xfer->xfer->data = xfer;
394
395 silc_free(clients);
396 silc_free(nickname);
397
398 return xfer;
399 }
400
401 void silcgaim_ftp_send_file(GaimConnection *gc, const char *name, const char *file)
402 {
403 GaimXfer *xfer = silcgaim_ftp_new_xfer(gc, name);
404
405 g_return_if_fail(xfer != NULL);
394 406
395 /* Choose file to send */ 407 /* Choose file to send */
396 if (file) 408 if (file)
397 gaim_xfer_request_accepted(xfer->xfer, file); 409 gaim_xfer_request_accepted(xfer->xfer, file);
398 else 410 else
399 gaim_xfer_request(xfer->xfer); 411 gaim_xfer_request(xfer->xfer);
400 412 }
401 silc_free(clients);
402 silc_free(nickname);
403 }