Changeset d0d65df


Ignore:
Timestamp:
Feb 17, 2003, 3:47:41 PM (21 years ago)
Author:
James M. Kretchmar <kretch@mit.edu>
Branches:
master, barnowl_perlaim, debian, owl, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
985f85b
Parents:
a2641cd9
Message:
The message object now uses a list of attributes internally, in
  prep. for supporting new messaging protocols
owl_function_info now uses fmtext instead of one staticly sized
  buffer
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    ra2641cd9 rd0d65df  
    77        Fixed a case sensitivity probelm in owl_message_is_personal and
    88           owl_message_is_private
     9        The message object now uses a list of attributes internally, in
     10          prep. for supporting new messaging protocols
     11        owl_function_info now uses fmtext instead of one staticly sized
     12          buffer
    913
    10141.2.8
  • Makefile.in

    rd309eb3 rd0d65df  
    1212     global.o text.o fmtext.o editwin.o util.o logging.o readconfig.o keys.o \
    1313     functions.o zwrite.o viewwin.o help.o filter.o regex.o history.o view.o \
    14      dict.o variable.o varstubs.o filterelement.o \
     14     dict.o variable.o varstubs.o filterelement.o pair.o \
    1515     keypress.o keymap.o keybinding.o cmd.o context.o perlglue.o zcrypt.o
    1616
  • functions.c

    r8f44c6b rd0d65df  
    10881088void owl_function_info() {
    10891089  owl_message *m;
     1090  owl_fmtext fm;
    10901091  ZNotice_t *n;
    1091   char buff[5000], tmpbuff[1024];
     1092  char buff[10000], tmpbuff[1024];
    10921093  char *ptr;
    10931094  int i, j, fields, len;
    10941095  owl_view *v;
    10951096
     1097  owl_fmtext_init_null(&fm);
     1098 
    10961099  v=owl_global_get_current_view(&g);
    10971100  m=owl_view_get_element(v, owl_global_get_curmsg(&g));
     
    11011104  }
    11021105
    1103   sprintf(buff,     "Msg Id    : %i\n", owl_message_get_id(m));
     1106  owl_fmtext_append_normal(&fm, "Msg Id    : ");
     1107  sprintf(buff, "%i", owl_message_get_id(m));
     1108  owl_fmtext_append_normal(&fm, buff);
     1109  owl_fmtext_append_normal(&fm, "\n");
    11041110  if (owl_message_is_type_zephyr(m)) {
    1105     sprintf(buff, "%sType      : zephyr\n", buff);
     1111    owl_fmtext_append_normal(&fm, "Type      : zephyr\n");
    11061112  } else if (owl_message_is_type_admin(m)) {
    1107     sprintf(buff, "%sType      : admin\n", buff);
     1113    owl_fmtext_append_normal(&fm, "Type      : admin\n");
    11081114  } else if (owl_message_is_type_generic(m)) {
    1109     sprintf(buff, "%sType      : generic\n", buff);
     1115    owl_fmtext_append_normal(&fm, "Type      : generic\n");
    11101116  } else {
    1111     sprintf(buff, "%sType      : unknown\n", buff);
     1117    owl_fmtext_append_normal(&fm, "Type      : unknown\n");
    11121118  }
    11131119  if (owl_message_is_direction_in(m)) {
    1114     sprintf(buff, "%sDirection : in\n", buff);
     1120    owl_fmtext_append_normal(&fm, "Direction : in\n");
    11151121  } else if (owl_message_is_direction_out(m)) {
    1116     sprintf(buff, "%sDirection : out\n", buff);
     1122    owl_fmtext_append_normal(&fm, "Direction : out\n");
    11171123  } else if (owl_message_is_direction_none(m)) {
    1118     sprintf(buff, "%sDirection : none\n", buff);
     1124    owl_fmtext_append_normal(&fm, "Direction : none\n");
    11191125  } else {
    1120     sprintf(buff, "%sDirection : unknown\n", buff);
    1121   }
    1122   sprintf(buff, "%sTime      : %s\n", buff, owl_message_get_timestr(m));
    1123 
    1124   if (!owl_message_is_type_zephyr(m)) {
    1125     owl_function_popless_text(buff);
    1126     return;
    1127   }
    1128 
    1129 
    1130   if (owl_message_is_direction_out(m)) {
    1131     sprintf(buff, "%sClass     : %s\n", buff, owl_message_get_class(m));
    1132     sprintf(buff, "%sInstance  : %s\n", buff, owl_message_get_instance(m));
    1133     sprintf(buff, "%sSender    : %s\n", buff, owl_message_get_sender(m));
    1134     sprintf(buff, "%sRecip     : %s\n", buff, owl_message_get_recipient(m));
    1135     sprintf(buff, "%sOpcode    : %s\n", buff, owl_message_get_opcode(m));
    1136    
    1137     owl_function_popless_text(buff);
    1138     return;
    1139   }
    1140 
    1141   n=owl_message_get_notice(m);
    1142 
    1143   sprintf(buff, "%sClass     : %s\n", buff, owl_message_get_class(m));
    1144   sprintf(buff, "%sInstance  : %s\n", buff, owl_message_get_instance(m));
    1145   sprintf(buff, "%sSender    : %s\n", buff, owl_message_get_sender(m));
    1146   sprintf(buff, "%sRecip     : %s\n", buff, owl_message_get_recipient(m));
    1147   sprintf(buff, "%sOpcode    : %s\n", buff, owl_message_get_opcode(m));
    1148   strcat(buff,    "Kind      : ");
    1149   if (n->z_kind==UNSAFE) {
    1150     strcat(buff, "UNSAFE\n");
    1151   } else if (n->z_kind==UNACKED) {
    1152     strcat(buff, "UNACKED\n");
    1153   } else if (n->z_kind==ACKED) {
    1154     strcat(buff, "ACKED\n");
    1155   } else if (n->z_kind==HMACK) {
    1156     strcat(buff, "HMACK\n");
    1157   } else if (n->z_kind==HMCTL) {
    1158     strcat(buff, "HMCTL\n");
    1159   } else if (n->z_kind==SERVACK) {
    1160     strcat(buff, "SERVACK\n");
    1161   } else if (n->z_kind==SERVNAK) {
    1162     strcat(buff, "SERVNAK\n");
    1163   } else if (n->z_kind==CLIENTACK) {
    1164     strcat(buff, "CLIENTACK\n");
    1165   } else if (n->z_kind==STAT) {
    1166     strcat(buff, "STAT\n");
    1167   } else {
    1168     strcat(buff, "ILLEGAL VALUE\n");
    1169   }
    1170   sprintf(buff, "%sTime      : %s\n", buff, owl_message_get_timestr(m));
    1171   sprintf(buff, "%sHost      : %s\n", buff, owl_message_get_hostname(m));
    1172   sprintf(buff, "%sPort      : %i\n", buff, n->z_port);
    1173   strcat(buff,    "Auth      : ");
    1174   if (n->z_auth == ZAUTH_FAILED) {
    1175     strcat(buff, "FAILED\n");
    1176   } else if (n->z_auth == ZAUTH_NO) {
    1177     strcat(buff, "NO\n");
    1178   } else if (n->z_auth == ZAUTH_YES) {
    1179     strcat(buff, "YES\n");
    1180   } else {
    1181     sprintf(buff, "%sUnknown State (%i)\n", buff, n->z_auth);
    1182   }
    1183   sprintf(buff, "%sCheckd Ath: %i\n", buff, n->z_checked_auth);
    1184   sprintf(buff, "%sMulti notc: %s\n", buff, n->z_multinotice);
    1185   sprintf(buff, "%sNum other : %i\n", buff, n->z_num_other_fields);
    1186   sprintf(buff, "%sMsg Len   : %i\n", buff, n->z_message_len);
    1187 
    1188   sprintf(buff, "%sFields    : %i\n", buff, owl_zephyr_get_num_fields(n));
    1189 
    1190   fields=owl_zephyr_get_num_fields(n);
    1191   for (i=0; i<fields; i++) {
    1192     sprintf(buff, "%sField %i   : ", buff, i+1);
    1193 
    1194     ptr=owl_zephyr_get_field(n, i+1, &len);
    1195     if (!ptr) break;
    1196     if (len<30) {
    1197       strncpy(tmpbuff, ptr, len);
    1198       tmpbuff[len]='\0';
    1199     } else {
    1200       strncpy(tmpbuff, ptr, 30);
    1201       tmpbuff[30]='\0';
    1202       strcat(tmpbuff, "...");
    1203     }
    1204 
    1205     /* just for testing for now */
    1206     for (j=0; j<strlen(tmpbuff); j++) {
    1207       if (tmpbuff[j]=='\n') tmpbuff[j]='~';
    1208       if (tmpbuff[j]=='\r') tmpbuff[j]='!';
    1209     }
    1210 
    1211     strcat(buff, tmpbuff);
    1212     strcat(buff, "\n");
    1213   }
    1214   sprintf(buff, "%sDefault Fm: %s\n", buff, n->z_default_format);
     1126    owl_fmtext_append_normal(&fm, "Direction : unknown\n");
     1127  }
     1128  owl_fmtext_append_normal(&fm, "Time      : ");
     1129  owl_fmtext_append_normal(&fm, owl_message_get_timestr(m));
     1130  owl_fmtext_append_normal(&fm, "\n");
     1131
     1132  if (owl_message_is_type_zephyr(m)) {
     1133
     1134    if (owl_message_is_direction_in(m)) {
     1135      n=owl_message_get_notice(m);
     1136      owl_fmtext_append_normal(&fm, "Class     : ");
     1137      owl_fmtext_append_normal(&fm, owl_message_get_class(m));
     1138      owl_fmtext_append_normal(&fm, "\n");
     1139      owl_fmtext_append_normal(&fm, "Instance  : ");
     1140      owl_fmtext_append_normal(&fm, owl_message_get_instance(m));
     1141      owl_fmtext_append_normal(&fm, "\n");
     1142      owl_fmtext_append_normal(&fm, "Sender    : ");
     1143      owl_fmtext_append_normal(&fm, owl_message_get_sender(m));
     1144      owl_fmtext_append_normal(&fm, "\n");
     1145      owl_fmtext_append_normal(&fm, "Recipient : ");
     1146      owl_fmtext_append_normal(&fm, owl_message_get_recipient(m));
     1147      owl_fmtext_append_normal(&fm, "\n");
     1148      owl_fmtext_append_normal(&fm, "Opcode    : ");
     1149      owl_fmtext_append_normal(&fm, owl_message_get_opcode(m));
     1150      owl_fmtext_append_normal(&fm, "\n");
     1151      owl_fmtext_append_normal(&fm, "Kind      : ");
     1152      if (n->z_kind==UNSAFE) {
     1153        owl_fmtext_append_normal(&fm, "UNSAFE\n");
     1154      } else if (n->z_kind==UNACKED) {
     1155        owl_fmtext_append_normal(&fm, "UNACKED\n");
     1156      } else if (n->z_kind==ACKED) {
     1157        owl_fmtext_append_normal(&fm, "ACKED\n");
     1158      } else if (n->z_kind==HMACK) {
     1159        owl_fmtext_append_normal(&fm, "HMACK\n");
     1160      } else if (n->z_kind==HMCTL) {
     1161        owl_fmtext_append_normal(&fm, "HMCTL\n");
     1162      } else if (n->z_kind==SERVACK) {
     1163        owl_fmtext_append_normal(&fm, "SERVACK\n");
     1164      } else if (n->z_kind==SERVNAK) {
     1165        owl_fmtext_append_normal(&fm, "SERVNACK\n");
     1166      } else if (n->z_kind==CLIENTACK) {
     1167        owl_fmtext_append_normal(&fm, "CLIENTACK\n");
     1168      } else if (n->z_kind==STAT) {
     1169        owl_fmtext_append_normal(&fm, "STAT\n");
     1170      } else {
     1171        owl_fmtext_append_normal(&fm, "ILLEGAL VALUE\n");
     1172      }
     1173
     1174      owl_fmtext_append_normal(&fm, "Time      : ");
     1175      owl_fmtext_append_normal(&fm, owl_message_get_timestr(m));
     1176      owl_fmtext_append_normal(&fm, "\n");
     1177      owl_fmtext_append_normal(&fm, "Host      : ");
     1178      owl_fmtext_append_normal(&fm, owl_message_get_hostname(m));
     1179      owl_fmtext_append_normal(&fm, "\n");
     1180      sprintf(buff, "Port      : %i\n", n->z_port);
     1181      owl_fmtext_append_normal(&fm, buff);
     1182
     1183      owl_fmtext_append_normal(&fm,    "Auth      : ");
     1184      if (n->z_auth == ZAUTH_FAILED) {
     1185        owl_fmtext_append_normal(&fm, "FAILED\n");
     1186      } else if (n->z_auth == ZAUTH_NO) {
     1187        owl_fmtext_append_normal(&fm, "NO\n");
     1188      } else if (n->z_auth == ZAUTH_YES) {
     1189        owl_fmtext_append_normal(&fm, "YES\n");
     1190      } else {
     1191        sprintf(buff, "Unknown State (%i)\n", n->z_auth);
     1192        owl_fmtext_append_normal(&fm, buff);
     1193      }
     1194
     1195      sprintf(buff, "Checkd Ath: %i\n", buff, n->z_checked_auth);
     1196      sprintf(buff, "%sMulti notc: %s\n", buff, n->z_multinotice);
     1197      sprintf(buff, "%sNum other : %i\n", buff, n->z_num_other_fields);
     1198      sprintf(buff, "%sMsg Len   : %i\n", buff, n->z_message_len);
     1199      owl_fmtext_append_normal(&fm, buff);
     1200     
     1201      sprintf(buff, "Fields    : %i\n", owl_zephyr_get_num_fields(n));
     1202      owl_fmtext_append_normal(&fm, buff);
     1203     
     1204      fields=owl_zephyr_get_num_fields(n);
     1205      for (i=0; i<fields; i++) {
     1206        sprintf(buff, "Field %i   : ", i+1);
    12151207       
    1216   owl_function_popless_text(buff);
     1208        ptr=owl_zephyr_get_field(n, i+1, &len);
     1209        if (!ptr) break;
     1210        if (len<30) {
     1211          strncpy(tmpbuff, ptr, len);
     1212          tmpbuff[len]='\0';
     1213        } else {
     1214          strncpy(tmpbuff, ptr, 30);
     1215          tmpbuff[30]='\0';
     1216          strcat(tmpbuff, "...");
     1217        }
     1218       
     1219        /* just for testing for now */
     1220        for (j=0; j<strlen(tmpbuff); j++) {
     1221          if (tmpbuff[j]=='\n') tmpbuff[j]='~';
     1222          if (tmpbuff[j]=='\r') tmpbuff[j]='!';
     1223        }
     1224       
     1225        strcat(buff, tmpbuff);
     1226        strcat(buff, "\n");
     1227        owl_fmtext_append_normal(&fm, buff);
     1228      }
     1229      owl_fmtext_append_normal(&fm, "Default Fm:");
     1230      owl_fmtext_append_normal(&fm, n->z_default_format);
     1231    }
     1232  }
     1233 
     1234  owl_function_popless_fmtext(&fm);
    12171235}
    12181236
  • message.c

    ra2641cd9 rd0d65df  
    1414static const char fileIdent[] = "$Id$";
    1515
    16 void owl_message_init_raw(owl_message *m) {
     16void owl_message_init(owl_message *m) {
    1717  time_t t;
    1818
     
    2121  owl_message_set_direction_none(m);
    2222  m->delete=0;
    23   m->sender=owl_strdup("");
    24   m->class=owl_strdup("");
    25   m->inst=owl_strdup("");
    26   m->recip=owl_strdup("");
    27   m->opcode=owl_strdup("");
    28   m->realm=owl_strdup("");
    29   m->zsig=owl_strdup("");
    3023  strcpy(m->hostname, "");
    3124  m->zwriteline=strdup("");
    3225
     26  owl_list_create(&(m->attributes));
     27 
    3328  /* save the time */
    3429  t=time(NULL);
     
    3732}
    3833
     34void owl_message_set_attribute(owl_message *m, char *attrname, char *attrvalue) {
     35  /* add the named attribute to the message.  If an attribute with the
     36     name already exists, replace the old value with the new value */
     37
     38  int i, j;
     39  owl_pair *p;
     40
     41  /* look for an existing pair with this key, and nuke the entry if
     42     found */
     43  j=owl_list_get_size(&(m->attributes));
     44  for (i=0; i<j; i++) {
     45    p=owl_list_get_element(&(m->attributes), i);
     46    if (!strcmp(owl_pair_get_key(p), attrname)) {
     47      owl_free(owl_pair_get_key(p));
     48      owl_free(owl_pair_get_value(p));
     49      owl_free(p);
     50      owl_list_remove_element(&(m->attributes), i);
     51      break;
     52    }
     53  }
     54
     55  p=owl_malloc(sizeof(owl_pair));
     56  owl_pair_create(p, owl_strdup(attrname), owl_strdup(attrvalue));
     57  owl_list_append_element(&(m->attributes), p);
     58}
     59
     60char *owl_message_get_attribute_value(owl_message *m, char *attrname) {
     61  /* return the value associated with the named attribute, or NULL if
     62     the attribute does not exist */
     63  int i, j;
     64  owl_pair *p;
     65
     66  j=owl_list_get_size(&(m->attributes));
     67  for (i=0; i<j; i++) {
     68    p=owl_list_get_element(&(m->attributes), i);
     69    if (!strcmp(owl_pair_get_key(p), attrname)) {
     70      return(owl_pair_get_value(p));
     71    }
     72  }
     73  owl_function_debugmsg("No attribute %s found", attrname);
     74  return(NULL);
     75}
     76
    3977
    4078owl_fmtext *owl_message_get_fmtext(owl_message *m) {
     
    4381
    4482void owl_message_set_class(owl_message *m, char *class) {
    45   if (m->class) owl_free(m->class);
    46   m->class=owl_strdup(class);
     83  owl_message_set_attribute(m, "class", class);
    4784}
    4885
    4986char *owl_message_get_class(owl_message *m) {
    50   return(m->class);
     87  char *class;
     88
     89  class=owl_message_get_attribute_value(m, "class");
     90  if (!class) return("");
     91  return(class);
    5192}
    5293
    5394void owl_message_set_instance(owl_message *m, char *inst) {
    54   if (m->inst) owl_free(m->inst);
    55   m->inst=owl_strdup(inst);
     95  owl_message_set_attribute(m, "instance", inst);
    5696}
    5797
    5898char *owl_message_get_instance(owl_message *m) {
    59   return(m->inst);
     99  char *instance;
     100
     101  instance=owl_message_get_attribute_value(m, "instance");
     102  if (!instance) return("");
     103  return(instance);
    60104}
    61105
    62106void owl_message_set_sender(owl_message *m, char *sender) {
    63   if (m->sender) owl_free(m->sender);
    64   m->sender=owl_strdup(sender);
     107  owl_message_set_attribute(m, "sender", sender);
    65108}
    66109
    67110char *owl_message_get_sender(owl_message *m) {
    68   return(m->sender);
     111  char *sender;
     112
     113  sender=owl_message_get_attribute_value(m, "sender");
     114  if (!sender) return("");
     115  return(sender);
    69116}
    70117
    71118void owl_message_set_zsig(owl_message *m, char *zsig) {
    72   if (m->zsig) owl_free(m->zsig);
    73   m->zsig=owl_strdup(zsig);
     119  owl_message_set_attribute(m, "zsig", zsig);
    74120}
    75121
    76122char *owl_message_get_zsig(owl_message *m) {
    77   return(m->zsig);
     123  char *zsig;
     124
     125  zsig=owl_message_get_attribute_value(m, "zsig");
     126  if (!zsig) return("");
     127  return(zsig);
    78128}
    79129
    80130void owl_message_set_recipient(owl_message *m, char *recip) {
    81   if (m->recip) owl_free(m->recip);
    82   m->recip=owl_strdup(recip);
     131  owl_message_set_attribute(m, "recipient", recip);
    83132}
    84133
    85134char *owl_message_get_recipient(owl_message *m) {
    86135  /* this is stupid for outgoing messages, we need to fix it. */
     136
     137  char *recip;
    87138     
    88139  if (m->type==OWL_MESSAGE_TYPE_ZEPHYR) {
    89     return(m->recip);
     140    recip=owl_message_get_attribute_value(m, "recipient");
    90141  } else if (owl_message_is_direction_out(m)) {
    91     return(m->zwriteline);
     142    recip=m->zwriteline;
    92143  } else {
    93     return(m->recip);
    94   }
     144    recip=owl_message_get_attribute_value(m, "recipient");
     145  }
     146  if (!recip) return("");
     147  return(recip);
    95148}
    96149
    97150void owl_message_set_realm(owl_message *m, char *realm) {
    98   if (m->realm) owl_free(m->realm);
    99   m->realm=owl_strdup(realm);
     151  owl_message_set_attribute(m, "realm", realm);
    100152}
    101153
    102154char *owl_message_get_realm(owl_message *m) {
    103   return(m->realm);
    104 }
     155  char *realm;
     156 
     157  realm=owl_message_get_attribute_value(m, "realm");
     158  if (!realm) return("");
     159  return(realm);
     160}
     161
     162void owl_message_set_body(owl_message *m, char *body) {
     163  owl_message_set_attribute(m, "body", body);
     164}
     165
     166char *owl_message_get_body(owl_message *m) {
     167  char *body;
     168
     169  body=owl_message_get_attribute_value(m, "body");
     170  if (!body) return("");
     171  return(body);
     172}
     173
    105174
    106175void owl_message_set_opcode(owl_message *m, char *opcode) {
    107   if (m->opcode) free(m->opcode);
    108   m->opcode=owl_strdup(opcode);
     176  owl_message_set_attribute(m, "opcode", opcode);
    109177}
    110178
    111179char *owl_message_get_opcode(owl_message *m) {
    112   return(m->opcode);
     180  char *opcode;
     181
     182  opcode=owl_message_get_attribute_value(m, "opcode");
     183  if (!opcode) return("");
     184  return(opcode);
    113185}
    114186
     
    142214char *owl_message_get_text(owl_message *m) {
    143215  return(owl_fmtext_get_text(&(m->fmtext)));
    144 }
    145 
    146 char *owl_message_get_body(owl_message *m) {
    147   return(m->body);
    148216}
    149217
     
    315383  char *indent;
    316384
    317   owl_message_init_raw(m);
    318 
    319   m->body=owl_strdup(text);
     385  owl_message_init(m);
     386
     387  owl_message_set_body(m, text);
    320388
    321389  indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10);
     
    336404  char *indent;
    337405
    338   owl_message_init_raw(m);
     406  owl_message_init(m);
    339407  owl_message_set_type_admin(m);
    340408
    341   m->body=owl_strdup(text);
     409  owl_message_set_body(m, text);
    342410
    343411  /* do something to make it clear the notice shouldn't be used for now */
     
    361429  struct hostent *hent;
    362430  int k, ret;
    363   char *ptr, *tmp;
    364 
    365   m->id=owl_global_get_nextmsgid(&g);
     431  char *ptr, *tmp, *tmp2;
     432
     433  owl_message_init(m);
     434 
    366435  owl_message_set_type_zephyr(m);
    367436  owl_message_set_direction_in(m);
     
    376445
    377446  /* set other info */
    378   m->sender=owl_strdup(n->z_sender);
    379   m->class=owl_strdup(n->z_class);
    380   m->inst=owl_strdup(n->z_class_inst);
    381   m->recip=owl_strdup(n->z_recipient);
     447  owl_message_set_sender(m, n->z_sender);
     448  owl_message_set_class(m, n->z_class);
     449  owl_message_set_instance(m, n->z_class_inst);
     450  owl_message_set_recipient(m, n->z_recipient);
    382451  if (n->z_opcode) {
    383     m->opcode=owl_strdup(n->z_opcode);
     452    owl_message_set_opcode(m, n->z_opcode);
    384453  } else {
    385     n->z_opcode=owl_strdup("");
    386   }
    387   m->zsig=owl_strdup(n->z_message);
     454    owl_message_set_opcode(m, "");
     455  }
     456  owl_message_set_zsig(m, n->z_message);
    388457
    389458  if ((ptr=strchr(n->z_recipient, '@'))!=NULL) {
    390     m->realm=owl_strdup(ptr+1);
     459    owl_message_set_realm(m, ptr+1);
    391460  } else {
    392     m->realm=owl_strdup(ZGetRealm());
     461    owl_message_set_realm(m, ZGetRealm());
    393462  }
    394463
     
    401470  tmp[k]='\0';
    402471  if (owl_global_is_newlinestrip(&g)) {
    403     m->body=owl_util_stripnewlines(tmp);
     472    tmp2=owl_util_stripnewlines(tmp);
     473    owl_message_set_body(m, tmp2);
    404474    owl_free(tmp);
     475    owl_free(tmp2);
    405476  } else {
    406     m->body=tmp;
     477    owl_message_set_body(m, tmp);
    407478  }
    408479
     
    411482    char *out;
    412483
    413     out=owl_malloc(strlen(m->body)*16+20);
    414     ret=zcrypt_decrypt(out, m->body, m->class, m->inst);
     484    out=owl_malloc(strlen(owl_message_get_body(m))*16+20);
     485    ret=zcrypt_decrypt(out, owl_message_get_body(m), owl_message_get_class(m), owl_message_get_instance(m));
    415486    if (ret==0) {
    416       owl_free(m->body);
    417       m->body=out;
     487      owl_message_set_body(m, out);
    418488    } else {
    419489      owl_free(out);
     
    449519  int ret;
    450520 
    451   owl_message_init_raw(m);
     521  owl_message_init(m);
    452522
    453523  /* create a zwrite for the purpose of filling in other message fields */
     
    460530  owl_message_set_class(m, owl_zwrite_get_class(&z));
    461531  owl_message_set_instance(m, owl_zwrite_get_instance(&z));
    462   m->recip=long_zuser(owl_zwrite_get_recip_n(&z, 0)); /* only gets the first user, must fix */
     532  owl_message_set_recipient(m,
     533                            long_zuser(owl_zwrite_get_recip_n(&z, 0))); /* only gets the first user, must fix */
    463534  owl_message_set_opcode(m, owl_zwrite_get_opcode(&z));
    464   m->realm=owl_strdup(owl_zwrite_get_realm(&z)); /* also a hack, but not here */
     535  owl_message_set_realm(m, owl_zwrite_get_realm(&z)); /* also a hack, but not here */
    465536  m->zwriteline=owl_strdup(line);
    466   m->body=owl_strdup(body);
     537  owl_message_set_body(m, body);
    467538  owl_message_set_zsig(m, zsig);
    468539 
     
    487558void _owl_message_make_text_from_config(owl_message *m) {
    488559  char *body, *indent;
    489  
     560
    490561  owl_fmtext_init_null(&(m->fmtext));
    491562
     
    571642 
    572643  /* get the body */
    573   body=owl_malloc(strlen(m->body)+30);
    574   strcpy(body, m->body);
     644  body=owl_malloc(strlen(owl_message_get_body(m))+30);
     645  strcpy(body, owl_message_get_body(m));
    575646
    576647  /* add a newline if we need to */
     
    584655
    585656  /* edit the from addr for printing */
    586   strcpy(frombuff, m->sender);
     657  strcpy(frombuff, owl_message_get_sender(m));
    587658  ptr=strchr(frombuff, '@');
    588659  if (ptr && !strncmp(ptr+1, ZGetRealm(), strlen(ZGetRealm()))) {
     
    594665  owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR);
    595666
    596   if (!strcasecmp(n->z_opcode, "ping") && owl_message_is_private(m)) {
     667  if (!strcasecmp(owl_message_get_opcode(m), "ping") && owl_message_is_private(m)) {
    597668    owl_fmtext_append_bold(&(m->fmtext), "PING");
    598669    owl_fmtext_append_normal(&(m->fmtext), " from ");
     
    625696    owl_fmtext_append_normal(&(m->fmtext), "\n");
    626697  } else {
    627     owl_fmtext_append_normal(&(m->fmtext), m->class);
     698    owl_fmtext_append_normal(&(m->fmtext), owl_message_get_class(m));
    628699    owl_fmtext_append_normal(&(m->fmtext), " / ");
    629     owl_fmtext_append_normal(&(m->fmtext), m->inst);
     700    owl_fmtext_append_normal(&(m->fmtext), owl_message_get_instance(m));
    630701    owl_fmtext_append_normal(&(m->fmtext), " / ");
    631702    owl_fmtext_append_bold(&(m->fmtext), frombuff);
     
    637708    if (n->z_opcode[0]!='\0') {
    638709      owl_fmtext_append_normal(&(m->fmtext), " [");
    639       owl_fmtext_append_normal(&(m->fmtext), n->z_opcode);
     710      owl_fmtext_append_normal(&(m->fmtext), owl_message_get_opcode(m));
    640711      owl_fmtext_append_normal(&(m->fmtext), "] ");
    641712    }
     
    672743
    673744  /* get the body */
    674   body=owl_malloc(strlen(m->body)+30);
    675   strcpy(body, m->body);
     745  body=owl_malloc(strlen(owl_message_get_body(m)+30));
     746  strcpy(body, owl_message_get_body(m));
    676747
    677748  /* add a newline if we need to */
     
    685756
    686757  /* edit the from addr for printing */
    687   strcpy(frombuff, m->sender);
     758  strcpy(frombuff, owl_message_get_sender(m));
    688759  ptr=strchr(frombuff, '@');
    689760  if (ptr && !strncmp(ptr+1, ZGetRealm(), strlen(ZGetRealm()))) {
     
    695766  owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR);
    696767
    697   if (!strcasecmp(n->z_opcode, "ping")) {
     768  if (!strcasecmp(owl_message_get_opcode(m), "ping")) {
    698769    owl_fmtext_append_bold(&(m->fmtext), "PING");
    699770    owl_fmtext_append_normal(&(m->fmtext), " from ");
    700771    owl_fmtext_append_bold(&(m->fmtext), frombuff);
    701772    owl_fmtext_append_normal(&(m->fmtext), "\n");
    702   } else if (!strcasecmp(n->z_class, "login")) {
     773  } else if (!strcasecmp(owl_message_get_class(m), "login")) {
    703774    char *ptr, host[LINE], tty[LINE];
    704775    int len;
     
    711782    tty[len]='\0';
    712783   
    713     if (!strcasecmp(n->z_opcode, "user_login")) {
     784    if (!strcasecmp(owl_message_get_opcode(m), "user_login")) {
    714785      owl_fmtext_append_bold(&(m->fmtext), "LOGIN");
    715     } else if (!strcasecmp(n->z_opcode, "user_logout")) {
     786    } else if (!strcasecmp(owl_message_get_opcode(m), "user_logout")) {
    716787      owl_fmtext_append_bold(&(m->fmtext), "LOGOUT");
    717788    }
    718789    owl_fmtext_append_normal(&(m->fmtext), " for ");
    719     ptr=short_zuser(n->z_class_inst);
     790    ptr=short_zuser(owl_message_get_instance(m));
    720791    owl_fmtext_append_bold(&(m->fmtext), ptr);
    721792    owl_free(ptr);
     
    727798  } else {
    728799    owl_fmtext_append_normal(&(m->fmtext), "From: ");
    729     if (strcasecmp(m->class, "message")) {
     800    if (strcasecmp(owl_message_get_class(m), "message")) {
    730801      owl_fmtext_append_normal(&(m->fmtext), "Class ");
    731       owl_fmtext_append_normal(&(m->fmtext), m->class);
     802      owl_fmtext_append_normal(&(m->fmtext), owl_message_get_class(m));
    732803      owl_fmtext_append_normal(&(m->fmtext), " / Instance ");
    733       owl_fmtext_append_normal(&(m->fmtext), m->inst);
     804      owl_fmtext_append_normal(&(m->fmtext), owl_message_get_instance(m));
    734805      owl_fmtext_append_normal(&(m->fmtext), " / ");
    735806    }
     
    769840  char *ptr;
    770841
    771   strcpy(buff, m->zsig);
     842  strcpy(buff, owl_message_get_zsig(m));
    772843  ptr=strchr(buff, '\n');
    773844  if (ptr) ptr[0]='\0';
     
    775846
    776847void owl_message_free(owl_message *m) {
     848  int i, j;
     849  owl_pair *p;
     850   
    777851  if (owl_message_is_type_zephyr(m) && owl_message_is_direction_in(m)) {
    778852    ZFreeNotice(&(m->notice));
    779853  }
    780   if (m->sender) owl_free(m->sender);
    781   if (m->recip) owl_free(m->recip);
    782   if (m->class) owl_free(m->class);
    783   if (m->inst) owl_free(m->inst);
    784   if (m->opcode) owl_free(m->opcode);
    785854  if (m->time) owl_free(m->time);
    786   if (m->realm) owl_free(m->realm);
    787   if (m->body) owl_free(m->body);
    788855  if (m->zwriteline) owl_free(m->zwriteline);
     856
     857  /* free all the attributes */
     858  j=owl_list_get_size(&(m->attributes));
     859  for (i=0; i<j; i++) {
     860    p=owl_list_get_element(&(m->attributes), i);
     861    owl_free(owl_pair_get_key(p));
     862    owl_free(owl_pair_get_value(p));
     863    owl_free(p);
     864  }
     865
     866  owl_list_free_simple(&(m->attributes));
    789867 
    790868  owl_fmtext_free(&(m->fmtext));
  • owl.h

    r8f44c6b rd0d65df  
    3939#define OWL_MESSAGE_TYPE_GENERIC    1
    4040#define OWL_MESSAGE_TYPE_ZEPHYR     2
     41#define OWL_MESSAGE_TYPE_AIM        3
     42#define OWL_MESSAGE_TYPE_JABBER     4
     43#define OWL_MESSAGE_TYPE_ICQ        5
     44#define OWL_MESSAGE_TYPE_YAHOO      6
     45#define OWL_MESSAGE_TYPE_MSN        7
    4146
    4247#define OWL_MESSAGE_DIRECTION_NONE  0
     
    225230} owl_zwrite;
    226231
     232typedef struct _owl_pair {
     233  void *key;
     234  void *value;
     235} owl_pair;
     236
    227237typedef struct _owl_message {
    228238  int id;
     
    233243  int delete;
    234244  char hostname[MAXHOSTNAMELEN];
    235   char *sender;
    236   char *recip;
    237   char *class;
    238   char *inst;
    239   char *opcode;
     245  owl_list attributes; /* this is a list of pairs */
    240246  char *time;
    241   char *realm;
    242   char *body;
    243247  char *zwriteline;
    244   char *zsig;
    245248} owl_message;
    246249
Note: See TracChangeset for help on using the changeset viewer.