Changeset ce7db4d


Ignore:
Timestamp:
Jun 24, 2003, 11:12:09 PM (17 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:
658dc2f
Parents:
723c427
Message:
zwrite -m now logs and displays an outgoing message
zwrite -s now works
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r79a0e82 rce7db4d  
    1818        Fixed personal aim messages logging to class directory
    1919        Log "LOGIN" or "LOGOUT" for AIM buddy messages message
     20        zwrite -m now logs and displays an outgoing message
     21        zwrite -s now works
    2022
    21232.0.4-pre-1
  • commands.c

    ref56a67 rce7db4d  
    15261526
    15271527char *owl_command_zwrite(int argc, char **argv, char *buff) {
    1528   char *tmpbuff, *pos, *cmd, *msg;
     1528  owl_zwrite z;
    15291529
    15301530  /* check for a zwrite -m */
    1531   for (pos = buff; *pos; pos = skiptokens(pos, 1)) {
    1532     if (!strncmp(pos, "-m ", 3)) {
    1533       cmd = owl_strdup(buff);
    1534       msg = cmd+(pos-buff);
    1535       *msg = '\0';
    1536       msg += 3;
    1537       owl_zwrite_create_and_send_from_line(cmd, msg);
    1538       owl_free(cmd);
    1539       return NULL;
    1540     }
     1531  owl_zwrite_create_from_line(&z, buff);
     1532  if (owl_zwrite_is_message_set(&z)) {
     1533    owl_function_zwrite(buff, NULL);
     1534    owl_zwrite_free(&z);
     1535    return (NULL);
    15411536  }
    15421537
     
    15441539    owl_function_makemsg("Not enough arguments to the zwrite command.");
    15451540  } else {
    1546     tmpbuff = owl_strdup(buff);
    1547     owl_function_zwrite_setup(tmpbuff);
    1548     owl_global_set_buffercommand(&g, tmpbuff);
    1549     owl_free(tmpbuff);
    1550   }
    1551   return NULL;
     1541    owl_function_zwrite_setup(buff);
     1542    owl_global_set_buffercommand(&g, buff);
     1543  }
     1544  return(NULL);
    15521545}
    15531546
    15541547char *owl_command_aimwrite(int argc, char **argv, char *buff) {
    1555   char *tmpbuff;
    1556 
    15571548  if (!owl_global_is_aimloggedin(&g)) {
    15581549    owl_function_makemsg("You are not logged in to AIM.");
     
    15651556  }
    15661557
    1567   tmpbuff=owl_strdup(buff);
    1568   owl_function_aimwrite_setup(tmpbuff);
    1569   owl_global_set_buffercommand(&g, tmpbuff);
    1570   owl_free(tmpbuff);
     1558  owl_function_aimwrite_setup(buff);
     1559  owl_global_set_buffercommand(&g, buff);
    15711560  return(NULL);
    15721561}
    15731562
    15741563char *owl_command_zcrypt(int argc, char **argv, char *buff) {
    1575   char *tmpbuff, *pos, *cmd, *msg;
    1576  
     1564  owl_zwrite z;
     1565
    15771566  /* check for a zwrite -m */
    1578   for (pos = buff; *pos; pos = skiptokens(pos, 1)) {
    1579     if (!strncmp(pos, "-m ", 3)) {
    1580       cmd = owl_strdup(buff);
    1581       msg = cmd+(pos-buff);
    1582       *msg = '\0';
    1583       msg += 3;
    1584       owl_zwrite_create_and_send_from_line(cmd, msg);
    1585       owl_free(cmd);
    1586       return NULL;
    1587     }
     1567  owl_zwrite_create_from_line(&z, buff);
     1568  if (owl_zwrite_is_message_set(&z)) {
     1569    owl_zwrite_send_message(&z);
     1570    owl_function_make_outgoing_zephyr(owl_zwrite_get_message(&z), buff, owl_zwrite_get_zsig(&z));
     1571    owl_zwrite_free(&z);
     1572    return (NULL);
    15881573  }
    15891574
     
    15911576    owl_function_makemsg("Not enough arguments to the zcrypt command.");
    15921577  } else {
    1593     tmpbuff = owl_strdup(buff);
    1594     owl_function_zwrite_setup(tmpbuff);
    1595     owl_global_set_buffercommand(&g, tmpbuff);
    1596     owl_free(tmpbuff);
     1578    owl_function_zwrite_setup(buff);
     1579    owl_global_set_buffercommand(&g, buff);
    15971580  }
    15981581  return(NULL);
  • functions.c

    rf1cbb7a rce7db4d  
    302302}
    303303
    304 void owl_function_zwrite(char *line)
     304/* send, log and display an outgoing zephyr.  If 'msg' is NULL
     305 * the message is expected to be set from the zwrite line itself
     306 */
     307void owl_function_zwrite(char *line, char *msg)
    305308{
    306309  owl_zwrite z;
    307310  int i, j;
     311  char *mymsg;
    308312
    309313  /* create the zwrite and send the message */
    310314  owl_zwrite_create_from_line(&z, line);
    311   owl_zwrite_send_message(&z, owl_editwin_get_text(owl_global_get_typwin(&g)));
     315  if (msg) {
     316    owl_zwrite_set_message(&z, msg);
     317  }
     318
     319  owl_zwrite_send_message(&z);
    312320  owl_function_makemsg("Waiting for ack...");
     321
     322  mymsg=owl_zwrite_get_message(&z);
    313323
    314324  /* display the message as an outgoing message in the receive window */
    315325  if (owl_global_is_displayoutgoing(&g) && owl_zwrite_is_personal(&z)) {
    316     owl_function_make_outgoing_zephyr(owl_editwin_get_text(owl_global_get_typwin(&g)), line, owl_zwrite_get_zsig(&z));
     326    owl_function_make_outgoing_zephyr(mymsg, line, owl_zwrite_get_zsig(&z));
    317327  }
    318328
     
    321331    j=owl_zwrite_get_numrecips(&z);
    322332    for (i=0; i<j; i++) {
    323       owl_log_outgoing_zephyr(owl_zwrite_get_recip_n(&z, i),
    324                        owl_editwin_get_text(owl_global_get_typwin(&g)));
     333      owl_log_outgoing_zephyr(owl_zwrite_get_recip_n(&z, i), mymsg);
    325334    }
    326335  }
     
    10731082  buff=owl_global_get_buffercommand(&g);
    10741083  if (!strncmp(buff, "zwrite ", 7)) {
    1075     owl_function_zwrite(buff);
     1084    owl_function_zwrite(buff, owl_editwin_get_text(owl_global_get_typwin(&g)));
    10761085  } else if (!strncmp(buff, "aimwrite ", 9)) {
    10771086    owl_function_aimwrite(buff+9);
  • owl.c

    ref56a67 rce7db4d  
    283283  strcat(startupmsg, buff);
    284284  strcat(startupmsg, "                                                                         \n");
    285   strcat(startupmsg, "If you would like to receive release announcments about owl you can join \n");
     285  strcat(startupmsg, "If you would like to receive release announcements about owl you can join \n");
    286286  strcat(startupmsg, "the owl-users@mit.edu mailing list.  MIT users can add themselves,       \n");
    287287  strcat(startupmsg, "otherwise send a request to owner-owl-users@mit.edu.               ^ ^   \n");
  • owl.h

    r0c502e9 rce7db4d  
    231231
    232232typedef struct _owl_zwrite {
    233   char class[LINE];
    234   char inst[LINE];
    235   char realm[LINE];
    236   char opcode[LINE];
     233  char *class;
     234  char *inst;
     235  char *realm;
     236  char *opcode;
    237237  char *zsig;
     238  char *message;
    238239  owl_list recips;
    239240  int cc;
  • zwrite.c

    r8262340 rce7db4d  
    77static const char fileIdent[] = "$Id$";
    88
    9 int owl_zwrite_create_and_send_from_line(char *cmd, char *msg) {
    10   owl_zwrite z;
    11   int rv;
    12   rv = owl_zwrite_create_from_line(&z, cmd);
    13   if (rv) return(rv);
    14   owl_zwrite_send_message(&z, msg);
    15   owl_zwrite_free(&z);
    16   return(0);
    17 }
    18 
    19 int owl_zwrite_create_from_line(owl_zwrite *z, char *line) {
     9int owl_zwrite_create_from_line(owl_zwrite *z, char *line)
     10{
    2011  int argc, badargs, myargc;
    2112  char **argv, **myargv;
     
    2516  badargs=0;
    2617 
    27   /* set the defaults */
    28   strcpy(z->realm, "");
    29   strcpy(z->class, "message");
    30   strcpy(z->inst, "personal");
    31   strcpy(z->opcode, "");
    32   z->zsig=owl_strdup("");
     18  /* start with null entires */
     19  z->realm=NULL;
     20  z->class=NULL;
     21  z->inst=NULL;
     22  z->opcode=NULL;
     23  z->zsig=NULL;
     24  z->message=NULL;
    3325  z->cc=0;
    3426  z->noping=0;
     
    5244        break;
    5345      }
    54       strcpy(z->class, myargv[1]);
     46      z->class=owl_strdup(myargv[1]);
    5547      myargv+=2;
    5648      myargc-=2;
     
    6052        break;
    6153      }
    62       strcpy(z->inst, myargv[1]);
     54      z->inst=owl_strdup(myargv[1]);
    6355      myargv+=2;
    6456      myargc-=2;
     
    6860        break;
    6961      }
    70       strcpy(z->realm, myargv[1]);
     62      z->realm=owl_strdup(myargv[1]);
     63      myargv+=2;
     64      myargc-=2;
     65    } else if (!strcmp(myargv[0], "-s")) {
     66      if (myargc<2) {
     67        badargs=1;
     68        break;
     69      }
     70      z->zsig=owl_strdup(myargv[1]);
    7171      myargv+=2;
    7272      myargc-=2;
     
    7676        break;
    7777      }
    78       strcpy(z->opcode, myargv[1]);
    79       myargv+=2;
    80       myargc-=2;
     78      z->opcode=owl_strdup(myargv[1]);
     79      myargv+=2;
     80      myargc-=2;
     81    } else if (!strcmp(myargv[0], "-m")) {
     82      if (myargc<2) {
     83        badargs=1;
     84        break;
     85      }
     86      /* we must already have users */
     87      if (owl_list_get_size(&(z->recips))<1) {
     88        badargs=1;
     89        break;
     90      }
     91
     92      /* Once we have -m, gobble up everything else on the line */
     93      myargv++;
     94      myargc--;
     95      z->message=owl_strdup("");
     96      while (myargc) {
     97        z->message=realloc(z->message, strlen(z->message)+strlen(myargv[0])+5);
     98        strcat(z->message, " ");
     99        strcat(z->message, myargv[0]);
     100        myargc--;
     101        myargv++;
     102      }
     103      break;
    81104    } else if (!strcmp(myargv[0], "-C")) {
    82105      z->cc=1;
     
    101124  }
    102125
     126  /* now deal with defaults */
     127  if (z->class==NULL) z->class=owl_strdup("message");
     128  if (z->inst==NULL) z->inst=owl_strdup("personal");
     129  if (z->realm==NULL) z->realm=owl_strdup("");
     130  if (z->opcode==NULL) z->opcode=owl_strdup("");
     131  /* z->message is allowed to stay NULL */
     132 
    103133  if (!strcasecmp(z->class, "message") &&
    104134      !strcasecmp(z->inst, "personal") &&
    105135      owl_list_get_size(&(z->recips))==0) {
    106     /* do the makemsg somewhere else */
    107136    owl_function_makemsg("You must specify a recipient");
    108137    return(-1);
    109138  }
    110139
    111   /* set a zsig */
    112   zsigproc = owl_global_get_zsigproc(&g);
    113   zsigowlvar = owl_global_get_zsig(&g);
    114   zsigzvar = ZGetVariable("zwrite-signature");
    115 
    116   if (zsigowlvar && *zsigowlvar) {
    117     owl_free(z->zsig);
    118     z->zsig=strdup(zsigowlvar);
    119   } else if (zsigproc && *zsigproc) {
    120     FILE *file;
    121     char buff[LINE], *openline;
    122 
    123     /* simple hack for now to nuke stderr */
    124     openline=owl_malloc(strlen(zsigproc)+40);
    125     strcpy(openline, zsigproc);
    126     strcat(openline, " 2> /dev/null");
    127     file=popen(openline, "r");
    128     owl_free(openline);
    129     if (!file) {
    130       if (zsigzvar && *zsigzvar) {
    131         owl_free(z->zsig);
    132         z->zsig=owl_strdup(zsigzvar);
    133       }
    134     } else {
    135       owl_free(z->zsig);
    136       z->zsig=owl_malloc(LINE);
    137       strcpy(z->zsig, "");
    138       while (fgets(buff, LINE, file)) { /* wrong sizing */
    139         strcat(z->zsig, buff);
    140       }
    141       pclose(file);
    142       if (z->zsig[strlen(z->zsig)-1]=='\n') {
    143         z->zsig[strlen(z->zsig)-1]='\0';
    144       }
    145     }
    146   } else if (zsigzvar) {
    147     owl_free(z->zsig);
    148     z->zsig=owl_strdup(zsigzvar);
    149   } else if (((pw=getpwuid(getuid()))!=NULL) && (pw->pw_gecos)) {
    150     owl_free(z->zsig);
    151     z->zsig=strdup(pw->pw_gecos);
    152     ptr=strchr(z->zsig, ',');
    153     if (ptr) {
    154       ptr[0]='\0';
    155     }
    156   }
    157 
    158   return(0);
    159 }
    160 
    161 void owl_zwrite_send_ping(owl_zwrite *z) {
     140  /* get a zsig, if not given */
     141  if (z->zsig==NULL) {
     142    zsigproc = owl_global_get_zsigproc(&g);
     143    zsigowlvar = owl_global_get_zsig(&g);
     144    zsigzvar = ZGetVariable("zwrite-signature");
     145
     146    if (zsigowlvar && *zsigowlvar) {
     147      z->zsig=owl_strdup(zsigowlvar);
     148    } else if (zsigproc && *zsigproc) {
     149      FILE *file;
     150      char buff[LINE], *openline;
     151     
     152      /* simple hack for now to nuke stderr */
     153      openline=owl_malloc(strlen(zsigproc)+40);
     154      strcpy(openline, zsigproc);
     155      strcat(openline, " 2> /dev/null");
     156      file=popen(openline, "r");
     157      owl_free(openline);
     158      if (!file) {
     159        if (zsigzvar && *zsigzvar) {
     160          z->zsig=owl_strdup(zsigzvar);
     161        }
     162      } else {
     163        z->zsig=owl_malloc(LINE*5);
     164        strcpy(z->zsig, "");
     165        while (fgets(buff, LINE, file)) { /* wrong sizing */
     166          strcat(z->zsig, buff);
     167        }
     168        pclose(file);
     169        if (z->zsig[strlen(z->zsig)-1]=='\n') {
     170          z->zsig[strlen(z->zsig)-1]='\0';
     171        }
     172      }
     173    } else if (zsigzvar) {
     174      z->zsig=owl_strdup(zsigzvar);
     175    } else if (((pw=getpwuid(getuid()))!=NULL) && (pw->pw_gecos)) {
     176      z->zsig=strdup(pw->pw_gecos);
     177      ptr=strchr(z->zsig, ',');
     178      if (ptr) {
     179        ptr[0]='\0';
     180      }
     181    }
     182  }
     183
     184  return(0);
     185}
     186
     187void owl_zwrite_send_ping(owl_zwrite *z)
     188{
    162189  int i, j;
    163190  char to[LINE];
     
    184211}
    185212
    186 void owl_zwrite_send_message(owl_zwrite *z, char *msg) {
     213void owl_zwrite_set_message(owl_zwrite *z, char *msg)
     214{
     215  if (z->message) owl_free(z->message);
     216  z->message=owl_strdup(msg);
     217}
     218
     219char *owl_zwrite_get_message(owl_zwrite *z)
     220{
     221  if (z->message) return(z->message);
     222  return("");
     223}
     224
     225int owl_zwrite_is_message_set(owl_zwrite *z)
     226{
     227  if (z->message) return(1);
     228  return(0);
     229}
     230
     231int owl_zwrite_send_message(owl_zwrite *z)
     232{
    187233  int i, j;
    188234  char to[LINE];
     235
     236  if (z->message==NULL) return(-1);
    189237
    190238  j=owl_list_get_size(&(z->recips));
     
    202250        }
    203251      }
    204       tmpmsg=owl_malloc(strlen(msg)+strlen(toline)+30);
    205       sprintf(tmpmsg, "%s\n%s", toline, msg);
     252      tmpmsg=owl_malloc(strlen(z->message)+strlen(toline)+30);
     253      sprintf(tmpmsg, "%s\n%s", toline, z->message);
    206254    }
    207255
     
    215263        send_zephyr(z->opcode, z->zsig, z->class, z->inst, to, tmpmsg);
    216264      } else {
    217         send_zephyr(z->opcode, z->zsig, z->class, z->inst, to, msg);
     265        send_zephyr(z->opcode, z->zsig, z->class, z->inst, to, z->message);
    218266      }
    219267    }
     
    223271  } else {
    224272    sprintf(to, "@%s", z->realm);
    225     send_zephyr(z->opcode, z->zsig, z->class, z->inst, to, msg);
    226   }
    227 }
    228 
    229 char *owl_zwrite_get_class(owl_zwrite *z) {
     273    send_zephyr(z->opcode, z->zsig, z->class, z->inst, to, z->message);
     274  }
     275  return(0);
     276}
     277
     278int owl_zwrite_create_and_send_from_line(char *cmd, char *msg)
     279{
     280  owl_zwrite z;
     281  int rv;
     282  rv=owl_zwrite_create_from_line(&z, cmd);
     283  if (rv) return(rv);
     284  if (!owl_zwrite_is_message_set(&z)) {
     285    owl_zwrite_set_message(&z, msg);
     286  }
     287  owl_zwrite_send_message(&z);
     288  owl_zwrite_free(&z);
     289  return(0);
     290}
     291
     292char *owl_zwrite_get_class(owl_zwrite *z)
     293{
    230294  return(z->class);
    231295}
    232296
    233 char *owl_zwrite_get_instance(owl_zwrite *z) {
     297char *owl_zwrite_get_instance(owl_zwrite *z)
     298{
    234299  return(z->inst);
    235300}
    236301
    237 char *owl_zwrite_get_opcode(owl_zwrite *z) {
     302char *owl_zwrite_get_opcode(owl_zwrite *z)
     303{
    238304  return(z->opcode);
    239305}
    240306
    241 char *owl_zwrite_get_realm(owl_zwrite *z) {
     307char *owl_zwrite_get_realm(owl_zwrite *z)
     308{
    242309  return(z->realm);
    243310}
    244311
    245 char *owl_zwrite_get_zsig(owl_zwrite *z) {
    246   return(z->zsig);
    247 }
    248 
    249 void owl_zwrite_get_recipstr(owl_zwrite *z, char *buff) {
     312char *owl_zwrite_get_zsig(owl_zwrite *z)
     313{
     314  if (z->zsig) return(z->zsig);
     315  return("");
     316}
     317
     318void owl_zwrite_get_recipstr(owl_zwrite *z, char *buff)
     319{
    250320  int i, j;
    251321
     
    259329}
    260330
    261 int owl_zwrite_get_numrecips(owl_zwrite *z) {
     331int owl_zwrite_get_numrecips(owl_zwrite *z)
     332{
    262333  return(owl_list_get_size(&(z->recips)));
    263334}
    264335
    265 char *owl_zwrite_get_recip_n(owl_zwrite *z, int n) {
     336char *owl_zwrite_get_recip_n(owl_zwrite *z, int n)
     337{
    266338  return(owl_list_get_element(&(z->recips), n));
    267339}
    268340
    269 int owl_zwrite_is_personal(owl_zwrite *z) {
     341int owl_zwrite_is_personal(owl_zwrite *z)
     342{
    270343  /* return true if at least one of the recipients is personal */
    271344  int i, j;
     
    280353}
    281354 
    282 void owl_zwrite_free(owl_zwrite *z) {
     355void owl_zwrite_free(owl_zwrite *z)
     356{
    283357  owl_list_free_all(&(z->recips), &owl_free);
    284   owl_free(z->zsig);
    285 }
     358  if (z->class) owl_free(z->class);
     359  if (z->inst) owl_free(z->inst);
     360  if (z->opcode) owl_free(z->opcode);
     361  if (z->realm) owl_free(z->realm);
     362  if (z->message) owl_free(z->message);
     363  if (z->zsig) owl_free(z->zsig);
     364}
Note: See TracChangeset for help on using the changeset viewer.