Changeset 2e42098 for functions.c
- Timestamp:
- Feb 5, 2014, 3:04:26 AM (10 years ago)
- Parents:
- 9ae6095 (diff), 0071c88 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
functions.c
r0071c88 r7dcef03 115 115 void owl_function_show_license(void) 116 116 { 117 const char *text; 118 119 text="" 120 "BarnOwl version " OWL_VERSION_STRING "\n" 117 char *text = g_strdup_printf( 118 "BarnOwl version %s\n" 121 119 "Copyright (c) 2006-2011 The BarnOwl Developers. All rights reserved.\n" 122 120 "Copyright (c) 2004 James Kretchmar. All rights reserved.\n" … … 155 153 "WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE\n" 156 154 "OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN\n" 157 "IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"; 155 "IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n", 156 version); 158 157 owl_function_popless_text(text); 158 g_free(text); 159 159 } 160 160 … … 196 196 owl_message *m; 197 197 198 m=g_ new(owl_message, 1);198 m=g_slice_new(owl_message); 199 199 owl_message_create_admin(m, header, body); 200 200 … … 204 204 205 205 /* do followlast if necessary */ 206 if (owl_global_should_followlast(&g)) owl_function_lastmsg _noredisplay();206 if (owl_global_should_followlast(&g)) owl_function_lastmsg(); 207 207 208 208 /* redisplay etc. */ … … 216 216 void owl_function_add_outgoing_zephyrs(const owl_zwrite *z) 217 217 { 218 if (z->cc || owl_zwrite_get_numrecips(z) == 0) {218 if (z->cc && owl_zwrite_is_personal(z)) { 219 219 /* create the message */ 220 owl_message *m = g_ new(owl_message, 1);220 owl_message *m = g_slice_new(owl_message); 221 221 owl_message_create_from_zwrite(m, z, owl_zwrite_get_message(z), 0); 222 222 … … 225 225 int i; 226 226 for (i = 0; i < owl_zwrite_get_numrecips(z); i++) { 227 owl_message *m; 228 229 if (!owl_zwrite_recip_is_personal(owl_zwrite_get_recip_n(z, i))) 230 continue; 231 227 232 /* create the message */ 228 owl_message *m = g_new(owl_message, 1);233 m = g_slice_new(owl_message); 229 234 owl_message_create_from_zwrite(m, z, owl_zwrite_get_message(z), i); 230 235 … … 246 251 if (!owl_global_is_aimloggedin(&g)) return(NULL); 247 252 248 m=g_ new(owl_message, 1);253 m=g_slice_new(owl_message); 249 254 owl_message_create_aim(m, 250 255 owl_global_get_aim_screenname(&g), … … 265 270 266 271 /* create the message */ 267 m=g_ new(owl_message, 1);272 m=g_slice_new(owl_message); 268 273 owl_message_create_loopback(m, body); 269 274 owl_message_set_direction_out(m); … … 272 277 } 273 278 274 void owl_function_start_edit_win(const char *line, void (*callback)(owl_editwin *), void *data, void (*cleanup)(void *))279 owl_editwin *owl_function_start_edit_win(const char *line) 275 280 { 276 281 owl_editwin *e; … … 286 291 g_free(s); 287 292 288 owl_editwin_set_cbdata(e, data, cleanup);289 owl_editwin_set_callback(e, callback);290 293 ctx = owl_editcontext_new(OWL_CTX_EDITMULTI, e, "editmulti", 291 294 owl_global_deactivate_editcontext, &g); 292 295 owl_global_push_context_obj(&g, ctx); 293 296 return e; 294 297 } 295 298 … … 309 312 void owl_function_zwrite_setup(owl_zwrite *z) 310 313 { 314 owl_editwin *e; 311 315 /* send a ping if necessary */ 312 316 if (owl_global_is_txping(&g)) { … … 316 320 317 321 owl_function_write_setup("zephyr"); 318 owl_function_start_edit_win(z->zwriteline,319 &owl_callback_zwrite,320 z, (void(*)(void*))owl_zwrite_delete);322 e = owl_function_start_edit_win(z->zwriteline); 323 owl_editwin_set_cbdata(e, z, (void (*)(void *))owl_zwrite_delete); 324 owl_editwin_set_callback(e, &owl_callback_zwrite); 321 325 } 322 326 323 327 void owl_function_aimwrite_setup(const char *to) 324 328 { 329 owl_editwin *e; 325 330 /* TODO: We probably actually want an owl_aimwrite object like 326 331 * owl_zwrite. */ 327 332 char *line = g_strdup_printf("aimwrite %s", to); 328 333 owl_function_write_setup("message"); 329 owl_function_start_edit_win(line, 330 &owl_callback_aimwrite, 331 g_strdup(to), 332 g_free); 334 e = owl_function_start_edit_win(line); 335 owl_editwin_set_cbdata(e, g_strdup(to), g_free); 336 owl_editwin_set_callback(e, &owl_callback_aimwrite); 333 337 g_free(line); 334 338 } … … 336 340 void owl_function_loopwrite_setup(void) 337 341 { 342 owl_editwin *e; 338 343 owl_function_write_setup("message"); 339 owl_function_start_edit_win("loopwrite", 340 &owl_callback_loopwrite, 341 NULL, NULL); 342 } 343 344 void owl_callback_zwrite(owl_editwin *e) { 344 e = owl_function_start_edit_win("loopwrite"); 345 owl_editwin_set_callback(e, &owl_callback_loopwrite); 346 } 347 348 void owl_callback_zwrite(owl_editwin *e, bool success) 349 { 350 if (!success) return; 345 351 owl_zwrite *z = owl_editwin_get_cbdata(e); 346 352 owl_function_zwrite(z, owl_editwin_get_text(e)); … … 372 378 owl_function_makemsg("Waiting for ack..."); 373 379 374 /* If it's personal */ 375 if (owl_zwrite_is_personal(z)) { 376 /* create the outgoing message */ 377 owl_function_add_outgoing_zephyrs(z); 378 } 380 /* create the outgoing message */ 381 owl_function_add_outgoing_zephyrs(z); 379 382 } 380 383 #else … … 402 405 403 406 zcrypt = g_build_filename(owl_get_bindir(), "zcrypt", NULL); 404 argv[0] = "zcrypt";407 argv[0] = zcrypt; 405 408 argv[1] = "-E"; 406 409 argv[2] = "-c"; argv[3] = owl_zwrite_get_class(z); … … 408 411 argv[6] = NULL; 409 412 410 rv = call_filter( zcrypt,argv, owl_zwrite_get_message(z), &cryptmsg, &status);413 rv = call_filter(argv, owl_zwrite_get_message(z), &cryptmsg, &status); 411 414 412 415 g_free(zcrypt); … … 426 429 owl_function_makemsg("Waiting for ack..."); 427 430 428 /* If it's personal */ 429 if (owl_zwrite_is_personal(z)) { 430 /* Create the outgoing message. Restore the un-crypted message for display. */ 431 owl_zwrite_set_message_raw(z, old_msg); 432 owl_function_add_outgoing_zephyrs(z); 433 } 434 435 /* free the zwrite */ 431 /* Create the outgoing message. Restore the un-crypted message for display. */ 432 owl_zwrite_set_message_raw(z, old_msg); 433 owl_function_add_outgoing_zephyrs(z); 434 435 /* Clean up. */ 436 436 g_free(cryptmsg); 437 } 438 439 void owl_callback_aimwrite(owl_editwin *e) { 437 g_free(old_msg); 438 } 439 440 void owl_callback_aimwrite(owl_editwin *e, bool success) 441 { 442 if (!success) return; 440 443 char *to = owl_editwin_get_cbdata(e); 441 444 owl_function_aimwrite(to, owl_editwin_get_text(e), true); … … 501 504 } 502 505 503 void owl_callback_loopwrite(owl_editwin *e) { 506 void owl_callback_loopwrite(owl_editwin *e, bool success) 507 { 508 if (!success) return; 504 509 owl_function_loopwrite(owl_editwin_get_text(e)); 505 510 } … … 511 516 /* create a message and put it on the message queue. This simulates 512 517 * an incoming message */ 513 min=g_ new(owl_message, 1);518 min=g_slice_new(owl_message); 514 519 mout=owl_function_make_outgoing_loopback(msg); 515 520 … … 808 813 } 809 814 810 void owl_function_lastmsg _noredisplay(void)815 void owl_function_lastmsg(void) 811 816 { 812 817 int oldcurmsg, curmsg; … … 826 831 owl_global_set_curmsg(&g, curmsg+1); 827 832 } 828 /* owl_mainwin_redisplay(owl_global_get_mainwin(&g)); */833 owl_mainwin_redisplay(owl_global_get_mainwin(&g)); 829 834 owl_global_set_direction_downwards(&g); 830 }831 832 void owl_function_lastmsg(void)833 {834 owl_function_lastmsg_noredisplay();835 owl_mainwin_redisplay(owl_global_get_mainwin(&g));836 835 } 837 836 … … 856 855 void owl_function_unsuball(void) 857 856 { 858 unsuball();859 owl_function_makemsg("Unsubscribed from all messages.");857 if (unsuball()) 858 owl_function_makemsg("Unsubscribed from all messages."); 860 859 } 861 860 … … 872 871 void owl_function_loadsubs(const char *file) 873 872 { 874 int ret, ret2; 875 const char *foo; 873 int ret, ret2, ret3; 876 874 char *path; 877 875 … … 885 883 886 884 /* for backwards compatibility for now */ 887 ret2=owl_zephyr_loaddefaultsubs(); 885 ret2 = owl_zephyr_loaddefaultsubs(); 886 ret3 = owl_zephyr_loadbarnowldefaultsubs(); 888 887 889 888 if (!owl_context_is_interactive(owl_global_get_context(&g))) return; 890 889 891 foo=file?file:"file"; 892 if (ret==0 && ret2==0) { 890 if (ret == 0 && ret2 == 0 && ret3 == 0) { 893 891 if (!file) { 894 892 owl_function_makemsg("Subscribed to messages."); … … 896 894 owl_function_makemsg("Subscribed to messages from %s", file); 897 895 } 898 } else if (ret ==-1) {899 owl_function_error("Could not read %s", f oo);900 } else {896 } else if (ret == -1) { 897 owl_function_error("Could not read %s", file ? file : "file"); 898 } else if (ret2 == -1) { 901 899 owl_function_error("Error subscribing to messages"); 900 } else { 901 owl_function_error("Error subscribing to instanced personals"); 902 902 } 903 903 } … … 918 918 } 919 919 920 void owl_callback_aimlogin(owl_editwin *e) { 920 void owl_callback_aimlogin(owl_editwin *e, bool success) 921 { 922 if (!success) return; 921 923 char *user = owl_editwin_get_cbdata(e); 922 924 owl_function_aimlogin(user, … … 989 991 /* owl_aim_set_awaymsg(""); */ 990 992 owl_function_makemsg("AIM away off"); 993 } 994 995 bool owl_function_is_away(void) 996 { 997 return owl_global_is_zaway(&g) || 998 owl_global_is_aaway(&g) || 999 owl_perlconfig_perl_call_bool("BarnOwl::Hooks::_get_is_away", 0, NULL); 991 1000 } 992 1001 … … 1350 1359 void owl_function_about(void) 1351 1360 { 1352 owl_function_popless_text(1353 "This is BarnOwl version " OWL_VERSION_STRING ".\n\n"1361 char *text = g_strdup_printf( 1362 "This is BarnOwl version %s.\n\n" 1354 1363 "BarnOwl is a fork of the Owl zephyr client, written and\n" 1355 1364 "maintained by Alejandro Sedeno and Nelson Elhage at the\n" … … 1370 1379 "This program is free software. You can redistribute it and/or\n" 1371 1380 "modify under the terms of the Sleepycat License. Use the \n" 1372 "':show license' command to display the full license\n" 1373 ); 1381 "':show license' command to display the full license\n", 1382 version); 1383 owl_function_popless_text(text); 1384 g_free(text); 1374 1385 } 1375 1386 … … 1430 1441 char *tmpbuff, *tmpbuff2; 1431 1442 int i, fields; 1443 const char *f; 1432 1444 1433 1445 if (!owl_message_is_pseudo(m)) { … … 1460 1472 owl_fmtext_append_normal(&fm, "\n"); 1461 1473 owl_fmtext_appendf_normal(&fm, " Port : %i\n", ntohs(n->z_port)); 1474 owl_fmtext_appendf_normal(&fm, " Charset : %s\n", owl_zephyr_get_charsetstr(n)); 1462 1475 owl_fmtext_appendf_normal(&fm, " Auth : %s\n", owl_zephyr_get_authstr(n)); 1463 1476 … … 1471 1484 owl_fmtext_appendf_normal(&fm, " Fields : %i\n", fields); 1472 1485 1473 for (i = 0; i < fields; i++) { 1474 tmpbuff = owl_zephyr_get_field_as_utf8(n, i + 1); 1486 for (i = 0, f = owl_zephyr_first_raw_field(n); f != NULL; 1487 i++, f = owl_zephyr_next_raw_field(n, f)) { 1488 tmpbuff = owl_zephyr_field_as_utf8(n, f); 1475 1489 tmpbuff2 = owl_text_indent(tmpbuff, 14, false); 1476 1490 owl_fmtext_appendf_normal(&fm, " Field %i : %s\n", i + 1, tmpbuff2); … … 1770 1784 1771 1785 owl_fmtext_append_normal(&fm, " Version: "); 1772 owl_fmtext_append_normal(&fm, OWL_VERSION_STRING);1786 owl_fmtext_append_normal(&fm, version); 1773 1787 owl_fmtext_append_normal(&fm, "\n"); 1774 1788 … … 1940 1954 } 1941 1955 1942 void owl_callback_command(owl_editwin *e) 1943 { 1956 void owl_callback_command(owl_editwin *e, bool success) 1957 { 1958 if (!success) return; 1944 1959 char *rv; 1945 1960 const char *line = owl_editwin_get_text(e); … … 1952 1967 } 1953 1968 1954 voidowl_function_start_command(const char *line)1969 owl_editwin *owl_function_start_command(const char *line) 1955 1970 { 1956 1971 owl_editwin *tw; … … 1967 1982 owl_global_push_context_obj(&g, ctx); 1968 1983 owl_editwin_set_callback(tw, owl_callback_command); 1969 } 1970 1971 CALLER_OWN owl_editwin *owl_function_start_question(const char *line) 1984 return tw; 1985 } 1986 1987 owl_editwin *owl_function_start_question(const char *line) 1972 1988 { 1973 1989 owl_editwin *tw; … … 1984 2000 } 1985 2001 1986 CALLER_OWNowl_editwin *owl_function_start_password(const char *line)2002 owl_editwin *owl_function_start_password(const char *line) 1987 2003 { 1988 2004 owl_editwin *tw; … … 2181 2197 f = owl_filter_new(argv[1], argc-2, argv+2); 2182 2198 if (f == NULL) { 2183 owl_function_error("Invalid filter ");2199 owl_function_error("Invalid filter: %s", argv[1]); 2184 2200 return false; 2185 2201 } … … 3466 3482 while (zaldptr) { 3467 3483 ZFreeALD(zaldptr->data); 3468 g_ free(zaldptr->data);3484 g_slice_free(ZAsyncLocateData_t, zaldptr->data); 3469 3485 zaldptr = g_list_next(zaldptr); 3470 3486 } … … 3476 3492 for (i = 0; i < anyone->len; i++) { 3477 3493 user = anyone->pdata[i]; 3478 zald = g_ new(ZAsyncLocateData_t, 1);3494 zald = g_slice_new(ZAsyncLocateData_t); 3479 3495 if (ZRequestLocations(zstr(user), zald, UNACKED, ZAUTH) == ZERR_NONE) { 3480 3496 *zaldlist = g_list_append(*zaldlist, zald); 3481 3497 } else { 3482 g_ free(zald);3498 g_slice_free(ZAsyncLocateData_t, zald); 3483 3499 } 3484 3500 }
Note: See TracChangeset
for help on using the changeset viewer.