Changeset 24ccc01


Ignore:
Timestamp:
Aug 26, 2009, 11:50:56 PM (12 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
e2ebf39
Parents:
36486be
git-author:
Nelson Elhage <nelhage@mit.edu> (08/19/09 23:41:06)
git-committer:
Nelson Elhage <nelhage@mit.edu> (08/26/09 23:50:56)
Message:
Replace owl_message_create_from_zwriteline with owl_message_create_from_zwrite.

By passing in a zwrite structure instead of a line, we make it easier to
construct faked messages without having to go through generaring and
parsing a zwrite command line. We change owl_zephyr_handle_ack to fake a
zwrite structure, fixing the segfault on zephyring users with
quotes (fixes #94), as well as logging errors sending instanced personals
slightly better.
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • functions.c

    r36486be r24ccc01  
    229229{
    230230  owl_message *m;
     231  owl_zwrite zw;
     232
     233  owl_zwrite_create_from_line(&zw, zwriteline);
     234  owl_zwrite_set_zsig(&zw, zsig);
    231235
    232236  /* create the message */
    233237  m=owl_malloc(sizeof(owl_message));
    234   owl_message_create_from_zwriteline(m, zwriteline, body, zsig);
     238 
     239  owl_message_create_from_zwrite(m, &zw, body);
     240  owl_zwrite_free(&zw);
    235241
    236242  return(m);
  • logging.c

    r4542047 r24ccc01  
    171171
    172172
    173 void owl_log_outgoing_zephyr_error(const char *to, const char *text)
     173void owl_log_outgoing_zephyr_error(const owl_zwrite *zw, const char *text)
    174174{
    175175  FILE *file;
     
    181181   * owl_log_shouldlog_message()
    182182   */
    183   zwriteline=owl_sprintf("zwrite %s", to);
    184   m=owl_function_make_outgoing_zephyr(text, zwriteline, "");
    185   owl_free(zwriteline);
     183  m = owl_malloc(sizeof(owl_message));
     184  owl_message_create_from_zwrite(m, zw, text);
    186185  if (!owl_log_shouldlog_message(m)) {
    187186    owl_message_free(m);
     
    191190
    192191  /* chop off a local realm */
    193   tobuff=short_zuser(to);
     192  tobuff = short_zuser(owl_list_get_element(&(zw->recips), 0));
    194193
    195194  /* expand ~ in path names */
  • message.c

    r27f6487 r24ccc01  
    898898}
    899899
    900 void owl_message_create_from_zwriteline(owl_message *m, const char *line, const char *body, const char *zsig)
    901 {
    902   owl_zwrite z;
     900void owl_message_create_from_zwrite(owl_message *m, const owl_zwrite *z, const char *body)
     901{
    903902  int ret;
    904903  char hostbuff[5000];
    905904 
    906905  owl_message_init(m);
    907 
    908   /* create a zwrite for the purpose of filling in other message fields */
    909   owl_zwrite_create_from_line(&z, line);
    910906
    911907  /* set things */
     
    913909  owl_message_set_type_zephyr(m);
    914910  owl_message_set_sender(m, owl_zephyr_get_sender());
    915   owl_message_set_class(m, owl_zwrite_get_class(&z));
    916   owl_message_set_instance(m, owl_zwrite_get_instance(&z));
    917   if (owl_zwrite_get_numrecips(&z)>0) {
    918     char *longzuser = long_zuser(owl_zwrite_get_recip_n(&z, 0));
     911  owl_message_set_class(m, owl_zwrite_get_class(z));
     912  owl_message_set_instance(m, owl_zwrite_get_instance(z));
     913  if (owl_zwrite_get_numrecips(z)>0) {
     914    char *longzuser = long_zuser(owl_zwrite_get_recip_n(z, 0));
    919915    owl_message_set_recipient(m,
    920916                              longzuser); /* only gets the first user, must fix */
    921917    owl_free(longzuser);
    922918  }
    923   owl_message_set_opcode(m, owl_zwrite_get_opcode(&z));
    924   owl_message_set_realm(m, owl_zwrite_get_realm(&z)); /* also a hack, but not here */
    925   owl_message_set_zwriteline(m, line);
     919  owl_message_set_opcode(m, owl_zwrite_get_opcode(z));
     920  owl_message_set_realm(m, owl_zwrite_get_realm(z)); /* also a hack, but not here */
     921  if(z->zwriteline) {
     922    owl_message_set_zwriteline(m, z->zwriteline);
     923  }
    926924  owl_message_set_body(m, body);
    927   owl_message_set_zsig(m, zsig);
     925  owl_message_set_zsig(m, owl_zwrite_get_zsig(z));
    928926 
    929927  /* save the hostname */
     
    937935
    938936  /* set the "isprivate" attribute if it's a private zephyr. */
    939   if (owl_zwrite_is_personal(&z)) {
     937  if (owl_zwrite_is_personal(z)) {
    940938    owl_message_set_isprivate(m);
    941939  }
    942 
    943   owl_zwrite_free(&z);
    944940}
    945941
  • owl.h

    r0e5afa2 r24ccc01  
    314314
    315315typedef struct _owl_zwrite {
     316  char *zwriteline;
    316317  char *class;
    317318  char *inst;
  • zephyr.c

    r36486be r24ccc01  
    769769    } else {
    770770      char buff[BUFFLEN];
     771      owl_zwrite zw;
     772      char *realm;
     773
    771774      tmp = short_zuser(retnotice->z_recipient);
    772775      owl_function_error("%s: Not logged in or subscribing.", tmp);
     
    796799      }
    797800      owl_function_adminmsg("", buff);
    798       owl_log_outgoing_zephyr_error(tmp, buff);
     801
     802      memset(&zw, 0, sizeof(zw));
     803      zw.class = owl_strdup(retnotice->z_class);
     804      zw.inst  = owl_strdup(retnotice->z_class_inst);
     805      realm = strchr(retnotice->z_recipient, '@');
     806      if(realm) {
     807        zw.realm = owl_strdup(realm + 1);
     808      } else {
     809        zw.realm = owl_strdup(owl_zephyr_get_realm());
     810      }
     811      zw.opcode = owl_strdup(retnotice->z_opcode);
     812      zw.zsig   = owl_strdup("");
     813      owl_list_create(&(zw.recips));
     814      owl_list_append_element(&(zw.recips), owl_strdup(tmp));
     815
     816      owl_log_outgoing_zephyr_error(&zw, buff);
     817
     818      owl_zwrite_free(&zw);
    799819      owl_free(tmp);
    800820    }
  • zwrite.c

    r36486be r24ccc01  
    2424  z->noping=0;
    2525  owl_list_create(&(z->recips));
     26  z->zwriteline = owl_strdup(line);
    2627
    2728  /* parse the command line for options */
     
    350351}
    351352
     353void owl_zwrite_set_zsig(owl_zwrite *z, const char *zsig)
     354{
     355  if(z->zsig) owl_free(z->zsig);
     356  z->zsig = owl_strdup(zsig);
     357}
     358
    352359void owl_zwrite_get_recipstr(const owl_zwrite *z, char *buff)
    353360{
     
    390397{
    391398  owl_list_free_all(&(z->recips), &owl_free);
     399  if (z->zwriteline) owl_free(z->zwriteline);
    392400  if (z->class) owl_free(z->class);
    393401  if (z->inst) owl_free(z->inst);
Note: See TracChangeset for help on using the changeset viewer.