Changeset 30678ae


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
Files:
4 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
  • owl.h

    r99c7549 r30678ae  
    109109#define OWL_PROTOCOL_MSN            5
    110110
    111 #define OWL_MESSAGE_TYPE_ADMIN      0
    112 #define OWL_MESSAGE_TYPE_GENERIC    1
    113 #define OWL_MESSAGE_TYPE_ZEPHYR     2
    114 #define OWL_MESSAGE_TYPE_AIM        3
    115 #define OWL_MESSAGE_TYPE_JABBER     4
    116 #define OWL_MESSAGE_TYPE_ICQ        5
    117 #define OWL_MESSAGE_TYPE_YAHOO      6
    118 #define OWL_MESSAGE_TYPE_MSN        7
    119 #define OWL_MESSAGE_TYPE_LOOPBACK   8
    120 
    121111#define OWL_MESSAGE_DIRECTION_NONE  0
    122112#define OWL_MESSAGE_DIRECTION_IN    1
     
    334324typedef struct _owl_message {
    335325  int id;
    336   int type;
    337326  int direction;
    338327#ifdef HAVE_LIBZEPHYR
  • perlconfig.c

    r8203afd r30678ae  
    2626}
    2727
    28 SV *owl_perlconfig_message2hashref(owl_message *m)  /*noproto*/
     28SV *owl_perlconfig_message2hashref(owl_message *m)
    2929{
    3030  HV *h;
    3131  SV *hr;
    32   char *ptr, *blessas;
     32  char *ptr, *blessas, *type;
    3333  int i, j;
    3434  owl_pair *pair;
     
    8686  hv_store(h, "private", strlen("private"), newSViv(owl_message_is_private(m)),0);
    8787
    88   if (owl_message_is_type_zephyr(m))       blessas = "BarnOwl::Message::Zephyr";
    89   else if (owl_message_is_type_aim(m))     blessas = "BarnOwl::Message::AIM";
    90   else if (owl_message_is_type_jabber(m))  blessas = "BarnOwl::Message::Jabber";
    91   else if (owl_message_is_type_admin(m))   blessas = "BarnOwl::Message::Admin";
    92   else if (owl_message_is_type_generic(m)) blessas = "BarnOwl::Message::Generic";
    93   else                                     blessas = "BarnOwl::Message";
     88  type = owl_message_get_type(m);
     89  if(!type) type = "generic";
     90  type = owl_strdup(type);
     91  type[0] = toupper(type[0]);
     92  blessas = owl_sprintf("BarnOwl::Message::%s", type);
    9493
    9594  hr = sv_2mortal(newRV_noinc((SV*)h));
    96   return sv_bless(hr, gv_stashpv(blessas,0));
    97 }
    98 
     95  hr = sv_bless(hr, gv_stashpv(blessas,0));
     96  owl_free(type);
     97  owl_free(blessas);
     98  return hr;
     99}
    99100
    100101SV *owl_perlconfig_curmessage2hashref(void) /*noproto*/
     
    110111}
    111112
     113/* XXX TODO: Messages should round-trip properly between
     114   message2hashref and hashref2message. Currently we lose
     115   zephyr-specific properties stored in the ZNotice_t
     116 */
     117owl_message * owl_perlconfig_hashref2message(SV *msg)
     118{
     119  owl_message * m;
     120  HE * ent;
     121  I32 count, len;
     122  char *key,*val;
     123  HV * hash;
     124
     125  hash = (HV*)SvRV(msg);
     126
     127  m = owl_malloc(sizeof(owl_message));
     128  owl_message_init(m);
     129
     130  count = hv_iterinit(hash);
     131  while((ent = hv_iternext(hash))) {
     132    key = hv_iterkey(ent, &len);
     133    val = SvPV_nolen(hv_iterval(hash, ent));
     134    if(!strcmp(key, "type")) {
     135      owl_message_set_type(m, val);
     136    } else if(!strcmp(key, "direction")) {
     137      owl_message_set_direction(m, owl_message_parse_direction(val));
     138    } else if(!strcmp(key, "private")) {
     139      SV * v = hv_iterval(hash, ent);
     140      if(SvTRUE(v)) {
     141        owl_message_set_isprivate(m);
     142      }
     143    } else if (!strcmp(key, "hostname")) {
     144      owl_message_set_hostname(m, val);
     145    } else if (!strcmp(key, "zwriteline")) {
     146      owl_message_set_zwriteline(m, val);
     147    } else if (!strcmp(key, "time")) {
     148      m->timestr = owl_strdup(val);
     149      struct tm tm;
     150      strptime(val, "%a %b %d %T %Y", &tm);
     151      m->time = mktime(&tm);
     152    } else {
     153      owl_message_set_attribute(m, key, val);
     154    }
     155  }
     156  if(owl_message_is_type_admin(m)) {
     157    if(!owl_message_get_attribute_value(m, "adminheader"))
     158      owl_message_set_attribute(m, "adminheader", "");
     159  }
     160  return m;
     161}
    112162
    113163/* Calls in a scalar context, passing it a hash reference.
  • perlglue.xs

    r7f792c1 r30678ae  
    117117        SV *msg
    118118        PREINIT:
    119                 char * key;
    120                 char * val;
    121119                owl_message *m;
    122                 HV * hash;
    123                 HE * ent;
    124                 I32 count;
    125                 I32 len;
    126120        CODE:
    127121        {
     
    130124                }
    131125
    132                 hash = (HV*)SvRV(msg);
    133                 m = owl_malloc(sizeof(owl_message));
    134                 owl_message_init(m);
    135 
    136                 count = hv_iterinit(hash);
    137                 while((ent = hv_iternext(hash))) {
    138                         key = hv_iterkey(ent, &len);
    139                         val = SvPV_nolen(hv_iterval(hash, ent));
    140                         if(!strcmp(key, "type")) {
    141                                 owl_message_set_type(m, owl_message_parse_type(val));
    142                         } else if(!strcmp(key, "direction")) {
    143                                 owl_message_set_direction(m, owl_message_parse_direction(val));
    144                         } else if(!strcmp(key, "private")) {
    145                                 SV * v = hv_iterval(hash, ent);
    146                                 if(SvTRUE(v)) {
    147                                         owl_message_set_isprivate(m);
    148                                 }
    149                         } else if (!strcmp(key, "hostname")) {
    150                                 owl_message_set_hostname(m, val);
    151                         } else if (!strcmp(key, "zwriteline")) {
    152                                 owl_message_set_zwriteline(m, val);
    153                         } else if (!strcmp(key, "time")) {
    154                                 m->timestr = owl_strdup(val);
    155                                 struct tm tm;
    156                                 strptime(val, "%a %b %d %T %Y", &tm);
    157                                 m->time = mktime(&tm);
    158                         } else {
    159                                 owl_message_set_attribute(m, key, val);
    160                         }
    161                 }
    162                 if(owl_message_is_type_admin(m)) {
    163                         if(!owl_message_get_attribute_value(m, "adminheader"))
    164                                 owl_message_set_attribute(m, "adminheader", "");
    165                 }
     126                m = owl_perlconfig_hashref2message(msg);
    166127
    167128                owl_global_messagequeue_addmsg(&g, m);
Note: See TracChangeset for help on using the changeset viewer.