Changeset 987cf3f


Ignore:
Timestamp:
Jul 4, 2010, 12:15:12 PM (14 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
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)
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>
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • commands.c

    r89ce405 r987cf3f  
    136136              "Send a local message.\n"),
    137137
    138   OWLCMD_ARGS("zcrypt", owl_command_zcrypt, OWL_CTX_INTERACTIVE,
     138  OWLCMD_ARGS("zcrypt", owl_command_zwrite, OWL_CTX_INTERACTIVE,
    139139              "send an encrypted zephyr",
    140140              "zcrypt [-n] [-C] [-c class] [-i instance] [-r realm] [-O opcode] [-m <message...>]\n",
     
    19141914char *owl_command_zwrite(int argc, const char *const *argv, const char *buff)
    19151915{
    1916   owl_zwrite z;
     1916  owl_zwrite *z;
    19171917
    19181918  if (!owl_global_is_havezephyr(&g)) {
     
    19211921  }
    19221922  /* 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  }
    19301934
    19311935  if (argc < 2) {
     1936    owl_zwrite_delete(z);
    19321937    owl_function_makemsg("Not enough arguments to the zwrite command.");
    19331938  } else {
    1934     owl_function_zwrite_setup(buff);
     1939    owl_function_zwrite_setup(z);
    19351940  }
    19361941  return(NULL);
     
    20192024{
    20202025  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   }
    20462026  return(NULL);
    20472027}
  • 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
  • owl.h

    r68e5464 r987cf3f  
    344344
    345345typedef struct _owl_zwrite {
     346  char *cmd;
    346347  char *zwriteline;
    347348  char *class;
  • zephyr.c

    r922f589 r987cf3f  
    852852  char *tmpbuff, *myuser, *to;
    853853  owl_message *mout;
     854  owl_zwrite *z;
    854855 
    855856  /* bail if it doesn't look like a message we should reply to.  Some
     
    887888  owl_free(to);
    888889
     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
    889894  /* 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);
    891896  owl_global_messagequeue_addmsg(&g, mout);
    892897  owl_free(tmpbuff);
     898  owl_zwrite_delete(z);
    893899#endif
    894900}
  • zwrite.c

    rc230bc1 r987cf3f  
    55#include "owl.h"
    66
     7owl_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
    717int owl_zwrite_create_from_line(owl_zwrite *z, const char *line)
    818{
     
    1525 
    1626  /* start with null entries */
     27  z->cmd=NULL;
    1728  z->realm=NULL;
    1829  z->class=NULL;
     
    3546  myargc=argc;
    3647  if (myargc && *(myargv[0])!='-') {
     48    z->cmd=owl_strdup(myargv[0]);
    3749    myargc--;
    3850    myargv++;
     
    350362}
    351363
     364void owl_zwrite_delete(owl_zwrite *z)
     365{
     366  owl_zwrite_cleanup(z);
     367  owl_free(z);
     368}
     369
    352370void owl_zwrite_cleanup(owl_zwrite *z)
    353371{
Note: See TracChangeset for help on using the changeset viewer.