comparison src/ft.c @ 10919:9695281b1aa1

[gaim-migrate @ 12683] Better handling of filenames in file transfers when using a non-UTF8 filename encoding on the filesyste. This should fix a number of bugs. committer: Tailor Script <tailor@pidgin.im>
author Stu Tomlinson <stu@nosnilmot.com>
date Sun, 15 May 2005 18:16:20 +0000
parents d83f745c997b
children 2c21bffa8200
comparison
equal deleted inserted replaced
10918:893921a6cc6e 10919:9695281b1aa1
138 g_free(escaped); 138 g_free(escaped);
139 } 139 }
140 140
141 static void gaim_xfer_show_file_error(GaimXfer *xfer, const char *filename) 141 static void gaim_xfer_show_file_error(GaimXfer *xfer, const char *filename)
142 { 142 {
143 gchar *msg = NULL; 143 int err = errno;
144 gchar *msg = NULL, *utf8;
144 GaimXferType xfer_type = gaim_xfer_get_type(xfer); 145 GaimXferType xfer_type = gaim_xfer_get_type(xfer);
145 GaimAccount *account = gaim_xfer_get_account(xfer); 146 GaimAccount *account = gaim_xfer_get_account(xfer);
146 147
148 utf8 = g_filename_to_utf8(filename, -1, NULL, NULL, NULL);
147 switch(xfer_type) { 149 switch(xfer_type) {
148 case GAIM_XFER_SEND: 150 case GAIM_XFER_SEND:
149 msg = g_strdup_printf(_("Error reading %s: \n%s.\n"), 151 msg = g_strdup_printf(_("Error reading %s: \n%s.\n"),
150 filename, strerror(errno)); 152 utf8, strerror(err));
151 break; 153 break;
152 case GAIM_XFER_RECEIVE: 154 case GAIM_XFER_RECEIVE:
153 msg = g_strdup_printf(_("Error writing %s: \n%s.\n"), 155 msg = g_strdup_printf(_("Error writing %s: \n%s.\n"),
154 filename, strerror(errno)); 156 utf8, strerror(err));
155 break; 157 break;
156 default: 158 default:
157 msg = g_strdup_printf(_("Error accessing %s: \n%s.\n"), 159 msg = g_strdup_printf(_("Error accessing %s: \n%s.\n"),
158 filename, strerror(errno)); 160 utf8, strerror(err));
159 break; 161 break;
160 } 162 }
163 g_free(utf8);
161 164
162 gaim_xfer_conversation_write(xfer, msg, TRUE); 165 gaim_xfer_conversation_write(xfer, msg, TRUE);
163 gaim_xfer_error(xfer_type, account, xfer->who, msg); 166 gaim_xfer_error(xfer_type, account, xfer->who, msg);
164 g_free(msg); 167 g_free(msg);
165 } 168 }
200 203
201 gaim_xfer_request_denied(xfer); 204 gaim_xfer_request_denied(xfer);
202 } 205 }
203 else if ((gaim_xfer_get_type(xfer) == GAIM_XFER_RECEIVE) && 206 else if ((gaim_xfer_get_type(xfer) == GAIM_XFER_RECEIVE) &&
204 S_ISDIR(st.st_mode)) { 207 S_ISDIR(st.st_mode)) {
205 char *msg = g_strdup_printf( 208 char *msg, *utf8;
206 _("%s is not a regular file. Cowardly refusing to overwrite it.\n"), filename); 209 utf8 = g_filename_to_utf8(filename, -1, NULL, NULL, NULL);
210 msg = g_strdup_printf(
211 _("%s is not a regular file. Cowardly refusing to overwrite it.\n"), utf8);
212 g_free(utf8);
207 gaim_notify_error(NULL, NULL, msg, NULL); 213 gaim_notify_error(NULL, NULL, msg, NULL);
208 g_free(msg); 214 g_free(msg);
209 gaim_xfer_request_denied(xfer); 215 gaim_xfer_request_denied(xfer);
210 } 216 }
211 else { 217 else {
345 void 351 void
346 gaim_xfer_request_accepted(GaimXfer *xfer, const char *filename) 352 gaim_xfer_request_accepted(GaimXfer *xfer, const char *filename)
347 { 353 {
348 GaimXferType type; 354 GaimXferType type;
349 struct stat st; 355 struct stat st;
350 char *msg; 356 char *msg, *utf8;
351 GaimAccount *account; 357 GaimAccount *account;
352 GaimBuddy *buddy; 358 GaimBuddy *buddy;
353 359
354 if (xfer == NULL) 360 if (xfer == NULL)
355 return; 361 return;
366 buddy = gaim_find_buddy(account, xfer->who); 372 buddy = gaim_find_buddy(account, xfer->who);
367 373
368 if (type == GAIM_XFER_SEND) { 374 if (type == GAIM_XFER_SEND) {
369 /* Check the filename. */ 375 /* Check the filename. */
370 if (g_strrstr(filename, "..")) { 376 if (g_strrstr(filename, "..")) {
371 377 char *utf8 = g_filename_to_utf8(filename, -1, NULL, NULL, NULL);
372 msg = g_strdup_printf(_("%s is not a valid filename.\n"), filename); 378
379 msg = g_strdup_printf(_("%s is not a valid filename.\n"), utf8);
373 gaim_xfer_error(type, account, xfer->who, msg); 380 gaim_xfer_error(type, account, xfer->who, msg);
381 g_free(utf8);
374 g_free(msg); 382 g_free(msg);
375 383
376 gaim_xfer_unref(xfer); 384 gaim_xfer_unref(xfer);
377 return; 385 return;
378 } 386 }
382 gaim_xfer_unref(xfer); 390 gaim_xfer_unref(xfer);
383 return; 391 return;
384 } 392 }
385 393
386 gaim_xfer_set_local_filename(xfer, filename); 394 gaim_xfer_set_local_filename(xfer, filename);
387 gaim_xfer_set_filename(xfer, g_basename(filename));
388 gaim_xfer_set_size(xfer, st.st_size); 395 gaim_xfer_set_size(xfer, st.st_size);
389 396
397 utf8 = g_filename_to_utf8(g_basename(filename), -1, NULL, NULL, NULL);
398 gaim_xfer_set_filename(xfer, utf8);
399
390 msg = g_strdup_printf(_("Offering to send %s to %s"), 400 msg = g_strdup_printf(_("Offering to send %s to %s"),
391 filename, buddy ? gaim_buddy_get_alias(buddy) : xfer->who); 401 utf8, buddy ? gaim_buddy_get_alias(buddy) : xfer->who);
402 g_free(utf8);
403
392 gaim_xfer_conversation_write(xfer, msg, FALSE); 404 gaim_xfer_conversation_write(xfer, msg, FALSE);
393 g_free(msg); 405 g_free(msg);
394 } 406 }
395 else { 407 else {
396 xfer->status = GAIM_XFER_STATUS_ACCEPTED; 408 xfer->status = GAIM_XFER_STATUS_ACCEPTED;