Changeset 987cf3f
- Timestamp:
- Jul 4, 2010, 12:15:12 PM (14 years ago)
- Branches:
- master, release-1.10, release-1.7, release-1.8, release-1.9
- Children:
- efc460e
- Parents:
- aeadc74
- git-author:
- Nelson Elhage <nelhage@mit.edu> (06/20/10 16:47:23)
- git-committer:
- Nelson Elhage <nelhage@mit.edu> (07/04/10 12:15:12)
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
commands.c
r89ce405 r987cf3f 136 136 "Send a local message.\n"), 137 137 138 OWLCMD_ARGS("zcrypt", owl_command_z crypt, OWL_CTX_INTERACTIVE,138 OWLCMD_ARGS("zcrypt", owl_command_zwrite, OWL_CTX_INTERACTIVE, 139 139 "send an encrypted zephyr", 140 140 "zcrypt [-n] [-C] [-c class] [-i instance] [-r realm] [-O opcode] [-m <message...>]\n", … … 1914 1914 char *owl_command_zwrite(int argc, const char *const *argv, const char *buff) 1915 1915 { 1916 owl_zwrite z;1916 owl_zwrite *z; 1917 1917 1918 1918 if (!owl_global_is_havezephyr(&g)) { … … 1921 1921 } 1922 1922 /* check for a zwrite -m */ 1923 owl_zwrite_create_from_line(&z, buff); 1924 if (owl_zwrite_is_message_set(&z)) { 1925 owl_function_zwrite(buff, NULL); 1926 owl_zwrite_cleanup(&z); 1927 return (NULL); 1928 } 1929 owl_zwrite_cleanup(&z); 1923 z = owl_zwrite_new(buff); 1924 if (!z) { 1925 owl_function_error("Error in zwrite arguments"); 1926 return NULL; 1927 } 1928 1929 if (owl_zwrite_is_message_set(z)) { 1930 owl_function_zwrite(z, NULL); 1931 owl_zwrite_delete(z); 1932 return NULL; 1933 } 1930 1934 1931 1935 if (argc < 2) { 1936 owl_zwrite_delete(z); 1932 1937 owl_function_makemsg("Not enough arguments to the zwrite command."); 1933 1938 } else { 1934 owl_function_zwrite_setup( buff);1939 owl_function_zwrite_setup(z); 1935 1940 } 1936 1941 return(NULL); … … 2019 2024 { 2020 2025 owl_function_loopwrite_setup(); 2021 return(NULL);2022 }2023 2024 char *owl_command_zcrypt(int argc, const char *const *argv, const char *buff)2025 {2026 owl_zwrite z;2027 2028 if (!owl_global_is_havezephyr(&g)) {2029 owl_function_makemsg("Zephyr is not available");2030 return(NULL);2031 }2032 /* check for a zcrypt -m */2033 owl_zwrite_create_from_line(&z, buff);2034 if (owl_zwrite_is_message_set(&z)) {2035 owl_function_zcrypt(buff, NULL);2036 owl_zwrite_cleanup(&z);2037 return (NULL);2038 }2039 owl_zwrite_cleanup(&z);2040 2041 if (argc < 2) {2042 owl_function_makemsg("Not enough arguments to the zcrypt command.");2043 } else {2044 owl_function_zwrite_setup(buff);2045 }2046 2026 return(NULL); 2047 2027 } -
functions.c
r13ebf92 r987cf3f 223 223 * that. 224 224 */ 225 owl_message *owl_function_make_outgoing_zephyr(const char *body, const char *zwriteline, const char *zsig)225 owl_message *owl_function_make_outgoing_zephyr(const owl_zwrite *z) 226 226 { 227 227 owl_message *m; 228 owl_zwrite zw;229 230 owl_zwrite_create_from_line(&zw, zwriteline);231 owl_zwrite_set_zsig(&zw, zsig);232 228 233 229 /* create the message */ 234 230 m=owl_malloc(sizeof(owl_message)); 235 236 owl_message_create_from_zwrite(m, &zw, body); 237 owl_zwrite_cleanup(&zw); 231 owl_message_create_from_zwrite(m, z, owl_zwrite_get_message(z)); 238 232 239 233 return(m); … … 296 290 } 297 291 298 static void owl_function_write_setup(const char * line, const char *noun, void (*callback)(owl_editwin *))292 static void owl_function_write_setup(const char *noun) 299 293 { 300 294 … … 307 301 "End with a dot on a line by itself. ^C will quit.", 308 302 noun); 309 310 owl_function_start_edit_win(line, callback, 303 } 304 305 void owl_function_zwrite_setup(owl_zwrite *z) 306 { 307 /* send a ping if necessary */ 308 if (owl_global_is_txping(&g)) { 309 owl_zwrite_send_ping(z); 310 } 311 312 313 owl_function_write_setup("zephyr"); 314 owl_function_start_edit_win(z->zwriteline, 315 &owl_callback_zwrite, 316 z, (void(*)(void*))owl_zwrite_delete); 317 } 318 319 void owl_function_aimwrite_setup(const char *line) 320 { 321 owl_function_write_setup("message"); 322 owl_function_start_edit_win(line, 323 &owl_callback_aimwrite, 311 324 owl_strdup(line), 312 325 owl_free); 313 } 314 315 void owl_function_zwrite_setup(const char *line) 316 { 317 owl_zwrite z; 318 int ret; 319 320 /* check the arguments */ 321 ret=owl_zwrite_create_from_line(&z, line); 322 if (ret) { 323 owl_function_error("Error in zwrite arguments"); 324 owl_zwrite_cleanup(&z); 325 return; 326 } 327 328 /* send a ping if necessary */ 329 if (owl_global_is_txping(&g)) { 330 owl_zwrite_send_ping(&z); 331 } 332 owl_zwrite_cleanup(&z); 333 334 owl_function_write_setup(line, "zephyr", &owl_callback_zwrite); 335 } 336 337 void owl_function_aimwrite_setup(const char *line) 338 { 339 owl_function_write_setup(line, "message", &owl_callback_aimwrite); 326 340 327 } 341 328 342 329 void owl_function_loopwrite_setup(void) 343 330 { 344 owl_function_write_setup("loopwrite", "message", owl_callback_loopwrite); 331 owl_function_write_setup("message"); 332 owl_function_start_edit_win("loopwrite", 333 &owl_callback_loopwrite, 334 "loopwrite", NULL); 345 335 } 346 336 347 337 void owl_callback_zwrite(owl_editwin *e) { 348 char *command = owl_editwin_get_cbdata(e); 349 owl_function_zwrite(command, 350 owl_editwin_get_text(e)); 338 owl_zwrite *z = owl_editwin_get_cbdata(e); 339 owl_function_zwrite(z, owl_editwin_get_text(e)); 351 340 } 352 341 … … 354 343 * the message is expected to be set from the zwrite line itself 355 344 */ 356 void owl_function_zwrite(const char *line, const char *msg) 357 { 358 owl_zwrite z; 359 const char *mymsg; 345 void owl_function_zwrite(owl_zwrite *z, const char *msg) 346 { 360 347 owl_message *m; 361 348 362 if( !strncmp(line, "zcrypt", strlen("zcrypt"))) {363 owl_function_zcrypt( line, msg);349 if(strcmp(z->cmd, "zcrypt") == 0) { 350 owl_function_zcrypt(z, msg); 364 351 return; 365 352 } 366 353 367 354 /* create the zwrite and send the message */ 368 owl_zwrite_create_from_line(&z, line); 369 owl_zwrite_populate_zsig(&z); 355 owl_zwrite_populate_zsig(z); 370 356 if (msg) { 371 owl_zwrite_set_message( &z, msg);372 } 373 owl_zwrite_send_message( &z);357 owl_zwrite_set_message(z, msg); 358 } 359 owl_zwrite_send_message(z); 374 360 owl_function_makemsg("Waiting for ack..."); 375 361 376 362 /* If it's personal */ 377 if (owl_zwrite_is_personal( &z)) {363 if (owl_zwrite_is_personal(z)) { 378 364 /* create the outgoing message */ 379 mymsg=owl_zwrite_get_message(&z); 380 m=owl_function_make_outgoing_zephyr(mymsg, line, owl_zwrite_get_zsig(&z)); 365 m=owl_function_make_outgoing_zephyr(z); 381 366 382 367 if (m) { … … 386 371 } 387 372 } 388 389 /* free the zwrite */390 owl_zwrite_cleanup(&z);391 373 } 392 374 … … 394 376 * the message is expected to be set from the zwrite line itself 395 377 */ 396 void owl_function_zcrypt(const char *line, const char *msg) 397 { 398 owl_zwrite z; 399 const char *mymsg; 378 void owl_function_zcrypt(owl_zwrite *z, const char *msg) 379 { 400 380 char *cryptmsg; 401 381 owl_message *m; … … 405 385 406 386 /* create the zwrite and send the message */ 407 owl_zwrite_create_from_line(&z, line); 408 owl_zwrite_populate_zsig(&z); 387 owl_zwrite_populate_zsig(z); 409 388 if (msg) { 410 owl_zwrite_set_message(&z, msg); 411 } 412 413 mymsg=owl_zwrite_get_message(&z); 389 owl_zwrite_set_message(z, msg); 390 } 391 414 392 415 393 zcrypt = owl_sprintf("%s/zcrypt", owl_get_bindir()); 416 394 argv[0] = "zcrypt"; 417 395 argv[1] = "-E"; 418 argv[2] = "-c"; argv[3] = owl_zwrite_get_class( &z);419 argv[4] = "-i"; argv[5] = owl_zwrite_get_instance( &z);396 argv[2] = "-c"; argv[3] = owl_zwrite_get_class(z); 397 argv[4] = "-i"; argv[5] = owl_zwrite_get_instance(z); 420 398 argv[6] = NULL; 421 399 422 rv = call_filter(zcrypt, argv, mymsg, &cryptmsg, &status);400 rv = call_filter(zcrypt, argv, owl_zwrite_get_message(z), &cryptmsg, &status); 423 401 424 402 owl_free(zcrypt); … … 428 406 owl_function_error("Error in zcrypt, possibly no key found. Message not sent."); 429 407 owl_function_beep(); 430 owl_zwrite_cleanup(&z);431 408 return; 432 409 } 433 410 434 owl_zwrite_set_message( &z, cryptmsg);435 owl_zwrite_set_opcode( &z, "crypt");411 owl_zwrite_set_message(z, cryptmsg); 412 owl_zwrite_set_opcode(z, "crypt"); 436 413 437 owl_zwrite_send_message( &z);414 owl_zwrite_send_message(z); 438 415 owl_function_makemsg("Waiting for ack..."); 439 416 440 417 /* If it's personal */ 441 if (owl_zwrite_is_personal( &z)) {418 if (owl_zwrite_is_personal(z)) { 442 419 /* create the outgoing message */ 443 mymsg=owl_zwrite_get_message(&z); 444 m=owl_function_make_outgoing_zephyr(mymsg, line, owl_zwrite_get_zsig(&z)); 420 m=owl_function_make_outgoing_zephyr(z); 445 421 if (m) { 446 422 owl_global_messagequeue_addmsg(&g, m); … … 452 428 /* free the zwrite */ 453 429 owl_free(cryptmsg); 454 owl_zwrite_cleanup(&z);455 430 } 456 431 -
owl.h
r68e5464 r987cf3f 344 344 345 345 typedef struct _owl_zwrite { 346 char *cmd; 346 347 char *zwriteline; 347 348 char *class; -
zephyr.c
r922f589 r987cf3f 852 852 char *tmpbuff, *myuser, *to; 853 853 owl_message *mout; 854 owl_zwrite *z; 854 855 855 856 /* bail if it doesn't look like a message we should reply to. Some … … 887 888 owl_free(to); 888 889 890 z = owl_zwrite_new(tmpbuff); 891 owl_zwrite_set_message(z, owl_global_get_zaway_msg(&g)); 892 owl_zwrite_set_zsig(z, "Automated reply:"); 893 889 894 /* display the message as an admin message in the receive window */ 890 mout=owl_function_make_outgoing_zephyr( owl_global_get_zaway_msg(&g), tmpbuff, "Automated reply:");895 mout=owl_function_make_outgoing_zephyr(z); 891 896 owl_global_messagequeue_addmsg(&g, mout); 892 897 owl_free(tmpbuff); 898 owl_zwrite_delete(z); 893 899 #endif 894 900 } -
zwrite.c
rc230bc1 r987cf3f 5 5 #include "owl.h" 6 6 7 owl_zwrite *owl_zwrite_new(const char *line) 8 { 9 owl_zwrite *z = owl_malloc(sizeof *z); 10 if (owl_zwrite_create_from_line(z, line) < 0) { 11 owl_zwrite_delete(z); 12 return NULL; 13 } 14 return z; 15 } 16 7 17 int owl_zwrite_create_from_line(owl_zwrite *z, const char *line) 8 18 { … … 15 25 16 26 /* start with null entries */ 27 z->cmd=NULL; 17 28 z->realm=NULL; 18 29 z->class=NULL; … … 35 46 myargc=argc; 36 47 if (myargc && *(myargv[0])!='-') { 48 z->cmd=owl_strdup(myargv[0]); 37 49 myargc--; 38 50 myargv++; … … 350 362 } 351 363 364 void owl_zwrite_delete(owl_zwrite *z) 365 { 366 owl_zwrite_cleanup(z); 367 owl_free(z); 368 } 369 352 370 void owl_zwrite_cleanup(owl_zwrite *z) 353 371 {
Note: See TracChangeset
for help on using the changeset viewer.