Changeset 9ceee9d for functions.c


Ignore:
Timestamp:
Jul 4, 2003, 12:26:03 AM (18 years ago)
Author:
James M. Kretchmar <kretch@mit.edu>
Branches:
master, barnowl_perlaim, debian, owl, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
3ba3af0
Parents:
5b85d19
Message:
There is now a zcrypt command
Replies to zcrypted messages now work
File:
1 edited

Legend:

Unmodified
Added
Removed
  • functions.c

    r5b85d19 r9ceee9d  
    255255}
    256256
    257 
    258 
    259 void owl_function_zcrypt_setup(char *line)
    260 {
    261   owl_editwin *e;
    262   char buff[1024];
    263   owl_zwrite z;
    264   int ret;
    265 
    266   /* check the arguments */
    267   ret=owl_zwrite_create_from_line(&z, line);
    268   if (ret) {
    269     owl_function_makemsg("Error in zwrite arugments");
    270     owl_zwrite_free(&z);
    271     return;
    272   }
    273 
    274   if (owl_zwrite_get_numrecips(&z)>0) {
    275     owl_function_makemsg("You may not specifiy a recipient for a zcrypt message");
    276     owl_zwrite_free(&z);
    277     return;
    278   }
    279 
    280   /* send a ping if necessary */
    281   if (owl_global_is_txping(&g)) {
    282     owl_zwrite_send_ping(&z);
    283   }
    284   owl_zwrite_free(&z);
    285 
    286   /* create and setup the editwin */
    287   e=owl_global_get_typwin(&g);
    288   owl_editwin_new_style(e, OWL_EDITWIN_STYLE_MULTILINE, owl_global_get_msg_history(&g));
    289 
    290   if (!owl_global_get_lockout_ctrld(&g)) {
    291     owl_function_makemsg("Type your zephyr below.  End with ^D or a dot on a line by itself.  ^C will quit.");
    292   } else {
    293     owl_function_makemsg("Type your zephyr below.  End with a dot on a line by itself.  ^C will quit.");
    294   }
    295 
    296   owl_editwin_clear(e);
    297   owl_editwin_set_dotsend(e);
    298   strcpy(buff, "----> ");
    299   strcat(buff, line);
    300   strcat(buff, "\n");
    301   owl_editwin_set_locktext(e, buff);
    302 
    303   /* make it active */
    304   owl_global_set_typwin_active(&g);
    305 
    306   owl_global_set_buffercommand(&g, line);
    307 }
    308 
    309257/* send, log and display an outgoing zephyr.  If 'msg' is NULL
    310258 * the message is expected to be set from the zwrite line itself
     
    341289
    342290  /* free the zwrite */
     291  owl_zwrite_free(&z);
     292}
     293
     294/* send, log and display an outgoing zcrypt zephyr.  If 'msg' is NULL
     295 * the message is expected to be set from the zwrite line itself
     296 */
     297void owl_function_zcrypt(char *line, char *msg)
     298{
     299  owl_zwrite z;
     300  int i, j, ret;
     301  char *mymsg;
     302  char *cryptmsg;
     303
     304  /* create the zwrite and send the message */
     305  owl_zwrite_create_from_line(&z, line);
     306  if (msg) {
     307    owl_zwrite_set_message(&z, msg);
     308  }
     309
     310  mymsg=owl_zwrite_get_message(&z);
     311#ifdef OWL_ENABLE_ZCRYPT
     312  cryptmsg=owl_malloc(strlen(mymsg)*4);
     313  ret=owl_zcrypt_encrypt(cryptmsg, mymsg, owl_zwrite_get_class(&z), owl_zwrite_get_instance(&z));
     314  if (ret) {
     315    owl_function_makemsg("Error in zcrypt, possibly no key found.  Message not sent.");
     316    owl_function_beep();
     317    owl_free(cryptmsg);
     318    return;
     319  }
     320#else
     321  cryptmsg=owl_strdup(mymsg);
     322#endif
     323
     324  owl_zwrite_set_message(&z, cryptmsg);
     325  owl_zwrite_set_opcode(&z, "crypt");
     326  mymsg=cryptmsg;
     327   
     328  owl_zwrite_send_message(&z);
     329  owl_function_makemsg("Waiting for ack...");
     330
     331  /* display the message as an outgoing message in the receive window */
     332  if (owl_global_is_displayoutgoing(&g) && owl_zwrite_is_personal(&z)) {
     333    owl_function_make_outgoing_zephyr(mymsg, line, owl_zwrite_get_zsig(&z));
     334  }
     335
     336  /* log it if we have logging turned on */
     337  if (owl_global_is_logging(&g) && owl_zwrite_is_personal(&z)) {
     338    j=owl_zwrite_get_numrecips(&z);
     339    for (i=0; i<j; i++) {
     340      owl_log_outgoing_zephyr(owl_zwrite_get_recip_n(&z, i), mymsg);
     341    }
     342  }
     343
     344  /* free the zwrite */
     345  owl_free(cryptmsg);
    343346  owl_zwrite_free(&z);
    344347}
     
    10871090  if (!strncmp(buff, "zwrite ", 7)) {
    10881091    owl_function_zwrite(buff, owl_editwin_get_text(owl_global_get_typwin(&g)));
     1092  } else if (!strncmp(buff, "zcrypt ", 7)) {
     1093    owl_function_zcrypt(buff, owl_editwin_get_text(owl_global_get_typwin(&g)));
    10891094  } else if (!strncmp(buff, "aimwrite ", 9)) {
    10901095    owl_function_aimwrite(buff+9);
     
    17741779    /* zephyr */
    17751780    if (owl_message_is_type_zephyr(m)) {
    1776       /* for now we disable replies to zcrypt messages, since we can't
    1777          support an encrypted reply */
    1778       if (!strcasecmp(owl_message_get_opcode(m), "crypt")) {
    1779         owl_function_makemsg("Replies to zcrypt messages are not enabled in this release");
    1780         return;
    1781       }
    1782 
    17831781      /* if it's a zephyr we sent, send it out the same way again */
    17841782      if (owl_message_is_direction_out(m)) {
     
    18241822       
    18251823      /* create the command line */
    1826       buff = owl_strdup("zwrite");
     1824      if (!strcasecmp(owl_message_get_opcode(m), "CRYPT")) {
     1825        buff=owl_strdup("zcrypt");
     1826      } else {
     1827        buff = owl_strdup("zwrite");
     1828      }
    18271829      if (strcasecmp(class, "message")) {
    18281830        buff = owl_sprintf("%s -c %s%s%s", oldbuff=buff, owl_getquoting(class), class, owl_getquoting(class));
Note: See TracChangeset for help on using the changeset viewer.