Changeset 30678ae for message.c


Ignore:
Timestamp:
Jan 29, 2007, 9:54:41 PM (14 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, barnowl_perlaim, debian, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
29ebcea
Parents:
a8a3433
git-author:
Nelson Elhage <nelhage@mit.edu> (01/29/07 21:54:30)
git-committer:
Nelson Elhage <nelhage@mit.edu> (01/29/07 21:54:41)
Message:
Making message type into a string
File:
1 edited

Legend:

Unmodified
Added
Removed
  • message.c

    r8fa9562 r30678ae  
    1616{
    1717  m->id=owl_global_get_nextmsgid(&g);
    18   m->type=OWL_MESSAGE_TYPE_GENERIC;
    1918  owl_message_set_direction_none(m);
    2019  m->delete=0;
     
    324323void owl_message_set_type_admin(owl_message *m)
    325324{
    326   m->type=OWL_MESSAGE_TYPE_ADMIN;
     325  owl_message_set_attribute(m, "type", "admin");
    327326}
    328327
    329328void owl_message_set_type_loopback(owl_message *m)
    330329{
    331   m->type=OWL_MESSAGE_TYPE_LOOPBACK;
     330  owl_message_set_attribute(m, "type", "loopback");
    332331}
    333332
    334333void owl_message_set_type_zephyr(owl_message *m)
    335334{
    336   m->type=OWL_MESSAGE_TYPE_ZEPHYR;
     335  owl_message_set_attribute(m, "type", "zephyr");
    337336}
    338337
    339338void owl_message_set_type_aim(owl_message *m)
    340339{
    341   m->type=OWL_MESSAGE_TYPE_AIM;
    342 }
    343 
    344 void owl_message_set_type(owl_message *m, int type)
    345 {
    346   m->type=type;
     340  owl_message_set_attribute(m, "type", "aim");
     341}
     342
     343void owl_message_set_type(owl_message *m, char* type)
     344{
     345  owl_message_set_attribute(m, "type", type);
     346}
     347
     348int owl_message_is_type(owl_message *m, char *type) {
     349  char * t = owl_message_get_attribute_value(m, "type");
     350  if(!t) return 0;
     351  return !strcmp(t, type);
    347352}
    348353                                               
    349354int owl_message_is_type_admin(owl_message *m)
    350355{
    351   if (m->type==OWL_MESSAGE_TYPE_ADMIN) return(1);
    352   return(0);
     356  return owl_message_is_type(m, "admin");
    353357}
    354358
    355359int owl_message_is_type_generic(owl_message *m)
    356360{
    357   if (m->type==OWL_MESSAGE_TYPE_GENERIC) return(1);
    358   return(0);
     361  char * t = owl_message_get_attribute_value(m, "type");
     362  return (t == NULL);
    359363}
    360364
    361365int owl_message_is_type_zephyr(owl_message *m)
    362366{
    363   if (m->type==OWL_MESSAGE_TYPE_ZEPHYR) return(1);
    364   return(0);
     367  return owl_message_is_type(m, "zephyr");
    365368}
    366369
    367370int owl_message_is_type_aim(owl_message *m)
    368371{
    369   if (m->type==OWL_MESSAGE_TYPE_AIM) return(1);
    370   return(0);
    371 }
    372 
     372  return owl_message_is_type(m, "aim");
     373}
     374
     375/* XXX TODO: deprecate this */
    373376int owl_message_is_type_jabber(owl_message *m)
    374377{
    375   if (m->type==OWL_MESSAGE_TYPE_JABBER) return(1);
    376 
    377   return(0);
    378 }
    379 
    380 int owl_message_is_type_icq(owl_message *m)
    381 {
    382   if (m->type==OWL_MESSAGE_TYPE_ICQ) return(1);
    383 
    384   return(0);
    385 }
    386 
    387 int owl_message_is_type_yahoo(owl_message *m)
    388 {
    389   if (m->type==OWL_MESSAGE_TYPE_YAHOO) return(1);
    390 
    391   return(0);
    392 }
    393 
    394 int owl_message_is_type_msn(owl_message *m)
    395 {
    396   if (m->type==OWL_MESSAGE_TYPE_MSN) return(1);
    397 
    398   return(0);
     378  return owl_message_is_type(m, "jabber");
    399379}
    400380
    401381int owl_message_is_type_loopback(owl_message *m)
    402382{
    403   if (m->type==OWL_MESSAGE_TYPE_LOOPBACK) return(1);
    404   return(0);
     383  return owl_message_is_type(m, "loopback");
    405384}
    406385
     
    666645
    667646char *owl_message_get_type(owl_message *m) {
    668   switch (m->type) {
    669   case OWL_MESSAGE_TYPE_ADMIN:
    670     return("admin");
    671   case OWL_MESSAGE_TYPE_ZEPHYR:
    672     return("zephyr");
    673   case OWL_MESSAGE_TYPE_GENERIC:
    674     return("generic");
    675   case OWL_MESSAGE_TYPE_AIM:
    676     return("aim");
    677   case OWL_MESSAGE_TYPE_JABBER:
    678     return("jabber");
    679   case OWL_MESSAGE_TYPE_ICQ:
    680     return("icq");
    681   case OWL_MESSAGE_TYPE_YAHOO:
    682     return("yahoo");
    683   case OWL_MESSAGE_TYPE_MSN:
    684     return("msn");
    685   case OWL_MESSAGE_TYPE_LOOPBACK:
    686     return("loopback");
    687   default:
    688     return("unknown");
    689   }
    690 }
    691 
    692 int owl_message_parse_type(char *type) {
    693   if(!strcmp(type, "admin")) {
    694     return OWL_MESSAGE_TYPE_ADMIN;
    695   } else if(!strcmp(type, "zephyr")) {
    696     return OWL_MESSAGE_TYPE_ZEPHYR;
    697   } if(!strcmp(type, "aim")) {
    698     return OWL_MESSAGE_TYPE_AIM;
    699   } else if(!strcmp(type, "jabber")) {
    700     return OWL_MESSAGE_TYPE_JABBER;
    701   } else if(!strcmp(type, "icq")) {
    702     return OWL_MESSAGE_TYPE_ICQ;
    703   } else if(!strcmp(type, "yahoo")) {
    704     return OWL_MESSAGE_TYPE_YAHOO;
    705   } else if(!strcmp(type, "msn")) {
    706     return OWL_MESSAGE_TYPE_MSN;
    707   } else if(!strcmp(type, "loopback")) {
    708     return OWL_MESSAGE_TYPE_LOOPBACK;
    709   } else {
    710     return OWL_MESSAGE_TYPE_GENERIC;
    711   }
     647  char * type = owl_message_get_attribute_value(m, "type");
     648  if(!type) {
     649    return "generic";
     650  }
     651  return type;
    712652}
    713653
Note: See TracChangeset for help on using the changeset viewer.