Changeset 987cf3f for functions.c


Ignore:
Timestamp:
Jul 4, 2010, 12:15:12 PM (11 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, 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)
Message:
Pass around owl_zwrite objects, instead of continually re-parsing them.

In addition to be cleaner and shorter, this fixes a bug where ': zcrypt' ended
in an unencrypted zwrite.

Reported-by: Tony Valderrama <tvald@mit.edu>
File:
1 edited

Legend:

Unmodified
Added
Removed
  • functions.c

    r13ebf92 r987cf3f  
    223223 * that.
    224224 */
    225 owl_message *owl_function_make_outgoing_zephyr(const char *body, const char *zwriteline, const char *zsig)
     225owl_message *owl_function_make_outgoing_zephyr(const owl_zwrite *z)
    226226{
    227227  owl_message *m;
    228   owl_zwrite zw;
    229 
    230   owl_zwrite_create_from_line(&zw, zwriteline);
    231   owl_zwrite_set_zsig(&zw, zsig);
    232228
    233229  /* create the message */
    234230  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));
    238232
    239233  return(m);
     
    296290}
    297291
    298 static void owl_function_write_setup(const char *line, const char *noun, void (*callback)(owl_editwin *))
     292static void owl_function_write_setup(const char *noun)
    299293{
    300294
     
    307301                         "End with a dot on a line by itself.  ^C will quit.",
    308302                         noun);
    309 
    310   owl_function_start_edit_win(line, callback,
     303}
     304
     305void 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
     319void 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,
    311324                              owl_strdup(line),
    312325                              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
    340327}
    341328
    342329void owl_function_loopwrite_setup(void)
    343330{
    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);
    345335}
    346336
    347337void 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));
    351340}
    352341
     
    354343 * the message is expected to be set from the zwrite line itself
    355344 */
    356 void owl_function_zwrite(const char *line, const char *msg)
    357 {
    358   owl_zwrite z;
    359   const char *mymsg;
     345void owl_function_zwrite(owl_zwrite *z, const char *msg)
     346{
    360347  owl_message *m;
    361348
    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);
    364351    return;
    365352  }
    366353
    367354  /* 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);
    370356  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);
    374360  owl_function_makemsg("Waiting for ack...");
    375361
    376362  /* If it's personal */
    377   if (owl_zwrite_is_personal(&z)) {
     363  if (owl_zwrite_is_personal(z)) {
    378364    /* 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);
    381366
    382367    if (m) {
     
    386371    }
    387372  }
    388 
    389   /* free the zwrite */
    390   owl_zwrite_cleanup(&z);
    391373}
    392374
     
    394376 * the message is expected to be set from the zwrite line itself
    395377 */
    396 void owl_function_zcrypt(const char *line, const char *msg)
    397 {
    398   owl_zwrite z;
    399   const char *mymsg;
     378void owl_function_zcrypt(owl_zwrite *z, const char *msg)
     379{
    400380  char *cryptmsg;
    401381  owl_message *m;
     
    405385
    406386  /* 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);
    409388  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
    414392
    415393  zcrypt = owl_sprintf("%s/zcrypt", owl_get_bindir());
    416394  argv[0] = "zcrypt";
    417395  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);
    420398  argv[6] = NULL;
    421399
    422   rv = call_filter(zcrypt, argv, mymsg, &cryptmsg, &status);
     400  rv = call_filter(zcrypt, argv, owl_zwrite_get_message(z), &cryptmsg, &status);
    423401
    424402  owl_free(zcrypt);
     
    428406    owl_function_error("Error in zcrypt, possibly no key found.  Message not sent.");
    429407    owl_function_beep();
    430     owl_zwrite_cleanup(&z);
    431408    return;
    432409  }
    433410
    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");
    436413   
    437   owl_zwrite_send_message(&z);
     414  owl_zwrite_send_message(z);
    438415  owl_function_makemsg("Waiting for ack...");
    439416
    440417  /* If it's personal */
    441   if (owl_zwrite_is_personal(&z)) {
     418  if (owl_zwrite_is_personal(z)) {
    442419    /* 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);
    445421    if (m) {
    446422      owl_global_messagequeue_addmsg(&g, m);
     
    452428  /* free the zwrite */
    453429  owl_free(cryptmsg);
    454   owl_zwrite_cleanup(&z);
    455430}
    456431
Note: See TracChangeset for help on using the changeset viewer.