Changeset 0ff8fb57 for message.c


Ignore:
Timestamp:
Jun 1, 2003, 1:46:49 PM (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:
31e48a3
Parents:
440ce01
Message:
More AIM work.
The auto-prototype building has been re-enabled as well.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • message.c

    r440ce01 r0ff8fb57  
    1414static const char fileIdent[] = "$Id$";
    1515
    16 void owl_message_init(owl_message *m) {
     16void owl_message_init(owl_message *m)
     17{
    1718  time_t t;
    1819
     
    3233}
    3334
    34 void owl_message_set_attribute(owl_message *m, char *attrname, char *attrvalue) {
     35void owl_message_set_attribute(owl_message *m, char *attrname, char *attrvalue)
     36{
    3537  /* add the named attribute to the message.  If an attribute with the
    3638     name already exists, replace the old value with the new value */
     
    5860}
    5961
    60 char *owl_message_get_attribute_value(owl_message *m, char *attrname) {
     62char *owl_message_get_attribute_value(owl_message *m, char *attrname)
     63{
    6164  /* return the value associated with the named attribute, or NULL if
    6265     the attribute does not exist */
     
    7679
    7780
    78 owl_fmtext *owl_message_get_fmtext(owl_message *m) {
     81owl_fmtext *owl_message_get_fmtext(owl_message *m)
     82{
    7983  return(&(m->fmtext));
    8084}
    8185
    82 void owl_message_set_class(owl_message *m, char *class) {
     86void owl_message_set_class(owl_message *m, char *class)
     87{
    8388  owl_message_set_attribute(m, "class", class);
    8489}
    8590
    86 char *owl_message_get_class(owl_message *m) {
     91char *owl_message_get_class(owl_message *m)
     92{
    8793  char *class;
    8894
     
    9298}
    9399
    94 void owl_message_set_instance(owl_message *m, char *inst) {
     100void owl_message_set_instance(owl_message *m, char *inst)
     101{
    95102  owl_message_set_attribute(m, "instance", inst);
    96103}
    97104
    98 char *owl_message_get_instance(owl_message *m) {
     105char *owl_message_get_instance(owl_message *m)
     106{
    99107  char *instance;
    100108
     
    104112}
    105113
    106 void owl_message_set_sender(owl_message *m, char *sender) {
     114void owl_message_set_sender(owl_message *m, char *sender)
     115{
    107116  owl_message_set_attribute(m, "sender", sender);
    108117}
    109118
    110 char *owl_message_get_sender(owl_message *m) {
     119char *owl_message_get_sender(owl_message *m)
     120{
    111121  char *sender;
    112122
     
    116126}
    117127
    118 void owl_message_set_zsig(owl_message *m, char *zsig) {
     128void owl_message_set_zsig(owl_message *m, char *zsig)
     129{
    119130  owl_message_set_attribute(m, "zsig", zsig);
    120131}
    121132
    122 char *owl_message_get_zsig(owl_message *m) {
     133char *owl_message_get_zsig(owl_message *m)
     134{
    123135  char *zsig;
    124136
     
    128140}
    129141
    130 void owl_message_set_recipient(owl_message *m, char *recip) {
     142void owl_message_set_recipient(owl_message *m, char *recip)
     143{
    131144  owl_message_set_attribute(m, "recipient", recip);
    132145}
    133146
    134 char *owl_message_get_recipient(owl_message *m) {
     147char *owl_message_get_recipient(owl_message *m)
     148{
    135149  /* this is stupid for outgoing messages, we need to fix it. */
    136150
    137151  char *recip;
    138      
    139   if (m->type==OWL_MESSAGE_TYPE_ZEPHYR) {
    140     recip=owl_message_get_attribute_value(m, "recipient");
    141   } else if (owl_message_is_direction_out(m)) {
    142     recip=m->zwriteline;
    143   } else {
    144     recip=owl_message_get_attribute_value(m, "recipient");
    145   }
     152
     153  recip=owl_message_get_attribute_value(m, "recipient");
    146154  if (!recip) return("");
    147155  return(recip);
    148156}
    149157
    150 void owl_message_set_realm(owl_message *m, char *realm) {
     158void owl_message_set_realm(owl_message *m, char *realm)
     159{
    151160  owl_message_set_attribute(m, "realm", realm);
    152161}
    153162
    154 char *owl_message_get_realm(owl_message *m) {
     163char *owl_message_get_realm(owl_message *m)
     164{
    155165  char *realm;
    156166 
     
    160170}
    161171
    162 void owl_message_set_body(owl_message *m, char *body) {
     172void owl_message_set_body(owl_message *m, char *body)
     173{
    163174  owl_message_set_attribute(m, "body", body);
    164175}
    165176
    166 char *owl_message_get_body(owl_message *m) {
     177char *owl_message_get_body(owl_message *m)
     178{
    167179  char *body;
    168180
     
    173185
    174186
    175 void owl_message_set_opcode(owl_message *m, char *opcode) {
     187void owl_message_set_opcode(owl_message *m, char *opcode)
     188{
    176189  owl_message_set_attribute(m, "opcode", opcode);
    177190}
    178191
    179 char *owl_message_get_opcode(owl_message *m) {
     192char *owl_message_get_opcode(owl_message *m)
     193{
    180194  char *opcode;
    181195
     
    185199}
    186200
    187 char *owl_message_get_timestr(owl_message *m) {
     201char *owl_message_get_timestr(owl_message *m)
     202{
    188203  return(m->time);
    189204}
    190205
    191 void owl_message_set_type_admin(owl_message *m) {
     206void owl_message_set_type_admin(owl_message *m)
     207{
    192208  m->type=OWL_MESSAGE_TYPE_ADMIN;
    193209}
    194210
    195 void owl_message_set_type_zephyr(owl_message *m) {
     211void owl_message_set_type_zephyr(owl_message *m)
     212{
    196213  m->type=OWL_MESSAGE_TYPE_ZEPHYR;
    197214}
    198215
    199 void owl_message_set_type_aim(owl_message *m) {
     216void owl_message_set_type_aim(owl_message *m)
     217{
    200218  m->type=OWL_MESSAGE_TYPE_AIM;
    201219}
    202220                                               
    203 int owl_message_is_type_admin(owl_message *m) {
     221int owl_message_is_type_admin(owl_message *m)
     222{
    204223  if (m->type==OWL_MESSAGE_TYPE_ADMIN) return(1);
    205224  return(0);
    206225}
    207226
    208 int owl_message_is_type_zephyr(owl_message *m) {
     227int owl_message_is_type_zephyr(owl_message *m)
     228{
    209229  if (m->type==OWL_MESSAGE_TYPE_ZEPHYR) return(1);
    210230  return(0);
    211231}
    212232
    213 int owl_message_is_type_aim(owl_message *m) {
     233int owl_message_is_type_aim(owl_message *m)
     234{
    214235  if (m->type==OWL_MESSAGE_TYPE_AIM) return(1);
    215236  return(0);
    216237}
    217238
    218 int owl_message_is_type_generic(owl_message *m) {
     239int owl_message_is_type_generic(owl_message *m)
     240{
    219241  if (m->type==OWL_MESSAGE_TYPE_GENERIC) return(1);
    220242  return(0);
    221243}
    222244
    223 char *owl_message_get_text(owl_message *m) {
     245char *owl_message_get_text(owl_message *m)
     246{
    224247  return(owl_fmtext_get_text(&(m->fmtext)));
    225248}
    226249
    227 void owl_message_set_direction_in(owl_message *m) {
     250void owl_message_set_direction_in(owl_message *m)
     251{
    228252  m->direction=OWL_MESSAGE_DIRECTION_IN;
    229253}
    230254
    231 void owl_message_set_direction_out(owl_message *m) {
     255void owl_message_set_direction_out(owl_message *m)
     256{
    232257  m->direction=OWL_MESSAGE_DIRECTION_OUT;
    233258}
    234259
    235 void owl_message_set_direction_none(owl_message *m) {
     260void owl_message_set_direction_none(owl_message *m)
     261{
    236262  m->direction=OWL_MESSAGE_DIRECTION_NONE;
    237263}
    238264
    239 int owl_message_is_direction_in(owl_message *m) {
     265int owl_message_is_direction_in(owl_message *m)
     266{
    240267  if (m->direction==OWL_MESSAGE_DIRECTION_IN) return(1);
    241268  return(0);
    242269}
    243270
    244 int owl_message_is_direction_out(owl_message *m) {
     271int owl_message_is_direction_out(owl_message *m)
     272{
    245273  if (m->direction==OWL_MESSAGE_DIRECTION_OUT) return(1);
    246274  return(0);
    247275}
    248276
    249 int owl_message_is_direction_none(owl_message *m) {
     277int owl_message_is_direction_none(owl_message *m)
     278{
    250279  if (m->direction==OWL_MESSAGE_DIRECTION_NONE) return(1);
    251280  return(0);
    252281}
    253282
    254 int owl_message_get_numlines(owl_message *m) {
     283int owl_message_get_numlines(owl_message *m)
     284{
    255285  if (m == NULL) return(0);
    256286  return(owl_fmtext_num_lines(&(m->fmtext)));
    257287}
    258288
    259 void owl_message_mark_delete(owl_message *m) {
     289void owl_message_mark_delete(owl_message *m)
     290{
    260291  if (m == NULL) return;
    261292  m->delete=1;
    262293}
    263294
    264 void owl_message_unmark_delete(owl_message *m) {
     295void owl_message_unmark_delete(owl_message *m)
     296{
    265297  if (m == NULL) return;
    266298  m->delete=0;
    267299}
    268300
    269 char *owl_message_get_zwriteline(owl_message *m) {
     301char *owl_message_get_zwriteline(owl_message *m)
     302{
    270303  return(m->zwriteline);
    271304}
    272305
    273 void owl_message_set_zwriteline(owl_message *m, char *line) {
     306void owl_message_set_zwriteline(owl_message *m, char *line)
     307{
    274308  m->zwriteline=strdup(line);
    275309}
    276310
    277 int owl_message_is_delete(owl_message *m) {
     311int owl_message_is_delete(owl_message *m)
     312{
    278313  if (m == NULL) return(0);
    279314  if (m->delete==1) return(1);
     
    281316}
    282317
    283 ZNotice_t *owl_message_get_notice(owl_message *m) {
     318ZNotice_t *owl_message_get_notice(owl_message *m)
     319{
    284320  return(&(m->notice));
    285321}
    286322
    287 char *owl_message_get_hostname(owl_message *m) {
     323char *owl_message_get_hostname(owl_message *m)
     324{
    288325  return(m->hostname);
    289326}
    290327
    291328
    292 void owl_message_curs_waddstr(owl_message *m, WINDOW *win, int aline, int bline, int acol, int bcol, int color) {
     329void owl_message_curs_waddstr(owl_message *m, WINDOW *win, int aline, int bline, int acol, int bcol, int color)
     330{
    293331  owl_fmtext a, b;
    294332
     
    312350}
    313351
    314 int owl_message_is_personal(owl_message *m) {
    315   if (strcasecmp(owl_message_get_class(m), "message")) return(0);
    316   if (strcasecmp(owl_message_get_instance(m), "personal")) return(0);
    317   if (!strcasecmp(owl_message_get_recipient(m), ZGetSender()) ||
    318       !strcasecmp(owl_message_get_sender(m), ZGetSender())) {
     352int owl_message_is_personal(owl_message *m)
     353{
     354  if (owl_message_is_type_zephyr(m)) {
     355    if (strcasecmp(owl_message_get_class(m), "message")) return(0);
     356    if (strcasecmp(owl_message_get_instance(m), "personal")) return(0);
     357    if (!strcasecmp(owl_message_get_recipient(m), ZGetSender()) ||
     358        !strcasecmp(owl_message_get_sender(m), ZGetSender())) {
     359      return(1);
     360    }
     361  }
     362  return(0);
     363}
     364
     365/* true if the message is only intended for one recipient (me) */
     366int owl_message_is_to_me(owl_message *m)
     367{
     368  if (owl_message_is_type_zephyr(m)) {
     369    if (!strcasecmp(owl_message_get_recipient(m), ZGetSender())) {
     370      return(1);
     371    } else {
     372      return(0);
     373    }
     374  } else if (owl_message_is_type_aim(m)) {
     375    /* right now we don't support chat rooms */
    319376    return(1);
    320   }
    321   return(0);
    322 }
    323 
    324 int owl_message_is_private(owl_message *m) {
    325   if (!strcasecmp(owl_message_get_recipient(m), ZGetSender())) return(1);
    326   return(0);
    327 }
    328 
    329 int owl_message_is_mail(owl_message *m) {
    330   if (!strcasecmp(owl_message_get_class(m), "mail") && owl_message_is_private(m)) {
     377  } else if (owl_message_is_type_admin(m)) {
    331378    return(1);
    332379  }
     
    334381}
    335382
    336 int owl_message_is_ping(owl_message *m) {
    337   if (!strcasecmp(owl_message_get_opcode(m), "ping")) return(1);
    338   return(0);
    339 }
    340 
    341 int owl_message_is_login(owl_message *m) {
    342   if (!strcasecmp(owl_message_get_class(m), "login")) return(1);
    343   return(0);
    344   /* is this good enough? */
    345 }
    346 
    347 int owl_message_is_burningears(owl_message *m) {
     383
     384int owl_message_is_from_me(owl_message *m)
     385{
     386  if (owl_message_is_type_zephyr(m)) {
     387    if (!strcasecmp(owl_message_get_sender(m), ZGetSender())) {
     388      return(1);
     389    } else {
     390      return(0);
     391    }
     392  } else if (owl_message_is_type_aim(m)) {
     393    if (!strcasecmp(owl_message_get_sender(m), owl_global_get_aim_screenname(&g))) {
     394      return(1);
     395    } else {
     396      return(0);
     397    }
     398  } else if (owl_message_is_type_admin(m)) {
     399    return(0);
     400  }
     401  return(0);
     402}
     403
     404int owl_message_is_mail(owl_message *m)
     405{
     406  if (owl_message_is_type_zephyr(m)) {
     407    if (!strcasecmp(owl_message_get_class(m), "mail") && owl_message_is_to_me(m)) {
     408      return(1);
     409    } else {
     410      return(0);
     411    }
     412  }
     413  return(0);
     414}
     415
     416int owl_message_is_ping(owl_message *m)
     417{
     418  if (owl_message_is_type_zephyr(m)) {
     419    if (!strcasecmp(owl_message_get_opcode(m), "ping")) {
     420      return(1);
     421    } else {
     422      return(0);
     423    }
     424  }
     425  return(0);
     426}
     427
     428int owl_message_is_login(owl_message *m)
     429{
     430  if (owl_message_is_type_zephyr(m)) {
     431    if (!strcasecmp(owl_message_get_class(m), "login")) {
     432      return(1);
     433    } else {
     434      return(0);
     435    }
     436  } else if (owl_message_is_type_aim(m)) {
     437    /* deal with this once we can use buddy lists */
     438    return(0);
     439  }
     440       
     441  return(0);
     442}
     443
     444int owl_message_is_burningears(owl_message *m)
     445{
    348446  /* we should add a global to cache the short zsender */
    349447  char sender[LINE], *ptr;
    350448
    351449  /* if the message is from us or to us, it doesn't count */
    352   if (!strcasecmp(ZGetSender(), owl_message_get_sender(m))) return(0);
    353   if (!strcasecmp(ZGetSender(), owl_message_get_recipient(m))) return(0);
    354 
    355   strcpy(sender, ZGetSender());
    356   ptr=strchr(sender, '@');
    357   if (ptr) *ptr='\0';
     450  if (owl_message_is_from_me(m) || owl_message_is_to_me(m)) return(0);
     451
     452  if (owl_message_is_type_zephyr(m)) {
     453    strcpy(sender, ZGetSender());
     454    ptr=strchr(sender, '@');
     455    if (ptr) *ptr='\0';
     456  } else if (owl_message_is_type_aim(m)) {
     457    strcpy(sender, owl_global_get_aim_screenname(&g));
     458  } else {
     459    return(0);
     460  }
    358461
    359462  if (stristr(owl_message_get_body(m), sender)) {
     
    364467
    365468/* caller must free return value. */
    366 char *owl_message_get_cc(owl_message *m) {
     469char *owl_message_get_cc(owl_message *m)
     470{
    367471  char *cur, *out, *end;
    368472
     
    378482}
    379483
    380 int owl_message_get_id(owl_message *m) {
     484int owl_message_get_id(owl_message *m)
     485{
    381486  return(m->id);
    382487}
    383488                                       
    384 int owl_message_search(owl_message *m, char *string) {
     489int owl_message_search(owl_message *m, char *string)
     490{
    385491  /* return 1 if the message contains "string", 0 otherwise.  This is
    386492   * case insensitive because the functions it uses are */
     
    389495}
    390496
    391 void owl_message_create(owl_message *m, char *header, char *text) {
     497void owl_message_create(owl_message *m, char *header, char *text)
     498{
    392499  char *indent;
    393500
     
    409516}
    410517
    411 void owl_message_create_aim(owl_message *m, char *sender, char *recipient, char *text) {
     518void owl_message_create_aim(owl_message *m, char *sender, char *recipient, char *text)
     519{
    412520  char *indent;
    413521
     
    435543}
    436544
    437 void owl_message_create_admin(owl_message *m, char *header, char *text) {
     545void owl_message_create_admin(owl_message *m, char *header, char *text)
     546{
    438547  char *indent;
    439548
     
    460569}
    461570
    462 void owl_message_create_from_znotice(owl_message *m, ZNotice_t *n) {
     571void owl_message_create_from_znotice(owl_message *m, ZNotice_t *n)
     572{
    463573  struct hostent *hent;
    464574  int k;
     
    552662}
    553663
    554 void owl_message_create_from_zwriteline(owl_message *m, char *line, char *body, char *zsig) {
     664void owl_message_create_from_zwriteline(owl_message *m, char *line, char *body, char *zsig)
     665{
    555666  owl_zwrite z;
    556667  int ret;
     
    593704}
    594705
    595 void _owl_message_make_text_from_config(owl_message *m) {
     706void _owl_message_make_text_from_config(owl_message *m)
     707{
    596708  char *body, *indent;
    597709
     
    612724}
    613725
    614 void _owl_message_make_text_from_zwriteline_standard(owl_message *m) {
     726void _owl_message_make_text_from_zwriteline_standard(owl_message *m)
     727{
    615728  char *indent, *text, *zsigbuff, *foo;
    616729
     
    642755}
    643756
    644 void _owl_message_make_text_from_zwriteline_simple(owl_message *m) {
     757void _owl_message_make_text_from_zwriteline_simple(owl_message *m)
     758{
    645759  char *indent, *text, *zsigbuff, *foo;
    646760
     
    672786}
    673787
    674 void _owl_message_make_text_from_notice_standard(owl_message *m) {
     788void _owl_message_make_text_from_notice_standard(owl_message *m)
     789{
    675790  char *body, *indent, *ptr, *zsigbuff, frombuff[LINE];
    676791  ZNotice_t *n;
     
    702817  owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR);
    703818
    704   if (!strcasecmp(owl_message_get_opcode(m), "ping") && owl_message_is_private(m)) {
     819  if (!strcasecmp(owl_message_get_opcode(m), "ping") && owl_message_is_to_me(m)) {
    705820    owl_fmtext_append_bold(&(m->fmtext), "PING");
    706821    owl_fmtext_append_normal(&(m->fmtext), " from ");
     
    773888}
    774889
    775 void _owl_message_make_text_from_notice_simple(owl_message *m) {
     890void _owl_message_make_text_from_notice_simple(owl_message *m)
     891{
    776892  char *body, *indent, *ptr, *zsigbuff, frombuff[LINE];
    777893  ZNotice_t *n;
     
    873989}
    874990
    875 void owl_message_pretty_zsig(owl_message *m, char *buff) {
     991void owl_message_pretty_zsig(owl_message *m, char *buff)
     992{
    876993  /* stick a one line version of the zsig in buff */
    877994  char *ptr;
     
    882999}
    8831000
    884 void owl_message_free(owl_message *m) {
     1001void owl_message_free(owl_message *m)
     1002{
    8851003  int i, j;
    8861004  owl_pair *p;
Note: See TracChangeset for help on using the changeset viewer.