[474] in BarnOwl Developers

home help back first fref pref prev next nref lref last post

[D-O-H] r603 - / branches/perl-message/owl

daemon@ATHENA.MIT.EDU (nelhage@MIT.EDU)
Thu Oct 29 18:06:34 2009

Resent-From: nelhage@mit.edu
Resent-To: barnowl-dev-mtg@charon.mit.edu
Date: Sun, 11 Feb 2007 00:11:10 -0500
To: dirty-owl-hackers@mit.edu
From: nelhage@MIT.EDU
Reply-To: dirty-owl-hackers@MIT.EDU

Author: nelhage
Date: 2007-02-11 00:11:10 -0500 (Sun, 11 Feb 2007)
New Revision: 603

Modified:
   /
   branches/perl-message/owl/
   branches/perl-message/owl/functions.c
   branches/perl-message/owl/logging.c
   branches/perl-message/owl/message.c
   branches/perl-message/owl/owl.h
   branches/perl-message/owl/perlconfig.c
   branches/perl-message/owl/stylefunc.c
   branches/perl-message/owl/zephyr.c
Log:
 r18605@phanatique:  nelhage | 2007-02-11 00:11:00 -0500
 Merging hv-backed messages into a branch
  r18517@phanatique:  nelhage | 2007-02-02 20:14:02 -0500
  Branching for owl_message rewrite
  r18518@phanatique:  nelhage | 2007-02-02 20:16:09 -0500
  First stage of making owl_message being backed directly by a perl
  hash.
  r18519@phanatique:  nelhage | 2007-02-02 20:52:13 -0500
  Moving all attributes on a message into the attributes hash.
  r18520@phanatique:  nelhage | 2007-02-03 17:54:20 -0500
  Didn't mean to commit that experiment
  r18521@phanatique:  nelhage | 2007-02-03 18:28:11 -0500
  First pass at removing the ZNotice_t from messages. We're currently
  missing some of the zephyr-specific fields.
  r18522@phanatique:  nelhage | 2007-02-03 18:28:31 -0500
  Actually remove the ZNotice_t from the owl_message struct
  r18523@phanatique:  nelhage | 2007-02-06 01:23:20 -0500
  Don't append a uninitialized string to the info display!
  r18524@phanatique:  nelhage | 2007-02-06 01:26:37 -0500
  * return the correct number of fields
  * get_field returns a malloc'd result
  r18525@phanatique:  nelhage | 2007-02-06 19:50:45 -0500
  Kill some unused variables, and maintain a proper reference count on
  messages passed to perl.
 



Property changes on: 
___________________________________________________________________
Name: svk:merge
   - 6122c8b4-0e12-0410-9533-8bcd7c66c992:/local/dirty-owl-hacks:24493
6aa88b72-b502-0410-8cb4-a5dd0230fb79:/owl-local:1356
bb873fd7-8e23-0410-944a-99ec44c633eb:/local/d-o-h:18603
   + 6122c8b4-0e12-0410-9533-8bcd7c66c992:/local/dirty-owl-hacks:24493
6aa88b72-b502-0410-8cb4-a5dd0230fb79:/owl-local:1356
bb873fd7-8e23-0410-944a-99ec44c633eb:/local/d-o-h:18605


Property changes on: branches/perl-message/owl
___________________________________________________________________
Name: svk:merge
   - 06e3988a-d725-0410-af47-c5dd11e74598:/local/barnowl:1380
8baf6839-b125-0410-9df9-922793c80423:/local/owl:15641
   + 06e3988a-d725-0410-af47-c5dd11e74598:/local/barnowl:1380
8baf6839-b125-0410-9df9-922793c80423:/local/owl:15641
bb873fd7-8e23-0410-944a-99ec44c633eb:/branches/owl/message-rewrite:18525

Modified: branches/perl-message/owl/functions.c
===================================================================
--- branches/perl-message/owl/functions.c	2007-02-11 05:08:44 UTC (rev 602)
+++ branches/perl-message/owl/functions.c	2007-02-11 05:11:10 UTC (rev 603)
@@ -1597,7 +1597,7 @@
     if (owl_message_is_direction_in(m)) {
       char *ptr, tmpbuff[1024];
       int i, j, fields, len;
-
+      /*
       n=owl_message_get_notice(m);
 
       if (!owl_message_is_pseudo(m)) {
@@ -1624,11 +1624,13 @@
 	  owl_fmtext_append_normal(&fm, "ILLEGAL VALUE\n");
 	}
       }
+      */
       owl_fmtext_append_normal(&fm, "  Host      : ");
       owl_fmtext_append_normal(&fm, owl_message_get_hostname(m));
 
       if (!owl_message_is_pseudo(m)) {
-	owl_fmtext_append_normal(&fm, "\n");
+        owl_fmtext_append_normal(&fm, "\n");
+        /*
 	sprintf(buff, "  Port      : %i\n", ntohs(n->z_port));
 	owl_fmtext_append_normal(&fm, buff);
 
@@ -1636,21 +1638,20 @@
 	owl_fmtext_append_normal(&fm, owl_zephyr_get_authstr(n));
 	owl_fmtext_append_normal(&fm, "\n");
 	
-	/* fix this */
 	sprintf(buff, "  Checkd Ath: %i\n", n->z_checked_auth);
 	sprintf(buff, "%s  Multi notc: %s\n", buff, n->z_multinotice);
 	sprintf(buff, "%s  Num other : %i\n", buff, n->z_num_other_fields);
 	sprintf(buff, "%s  Msg Len   : %i\n", buff, n->z_message_len);
 	owl_fmtext_append_normal(&fm, buff);
-	
-	sprintf(buff, "  Fields    : %i\n", owl_zephyr_get_num_fields(n));
+      */	
+	sprintf(buff, "  Fields    : %i\n", owl_message_get_num_fields(m));
 	owl_fmtext_append_normal(&fm, buff);
 	
-	fields=owl_zephyr_get_num_fields(n);
+	fields=owl_message_get_num_fields(m);
 	for (i=0; i<fields; i++) {
 	  sprintf(buff, "  Field %i   : ", i+1);
 	  
-	  ptr=owl_zephyr_get_field(n, i+1);
+	  ptr=owl_message_get_field(m, i+1);
 	  len=strlen(ptr);
 	  if (len<30) {
 	    strncpy(tmpbuff, ptr, len);
@@ -1671,8 +1672,8 @@
 	  strcat(buff, "\n");
 	  owl_fmtext_append_normal(&fm, buff);
 	}
-	owl_fmtext_append_normal(&fm, "  Default Fm:");
-	owl_fmtext_append_normal(&fm, n->z_default_format);
+	/* owl_fmtext_append_normal(&fm, "  Default Fm:");
+           owl_fmtext_append_normal(&fm, n->z_default_format); */
       }
       
     }

Modified: branches/perl-message/owl/logging.c
===================================================================
--- branches/perl-message/owl/logging.c	2007-02-11 05:08:44 UTC (rev 602)
+++ branches/perl-message/owl/logging.c	2007-02-11 05:11:10 UTC (rev 603)
@@ -440,11 +440,8 @@
     if (strcmp(owl_message_get_opcode(m), "")) fprintf(file, " Opcode: %s", owl_message_get_opcode(m));
     fprintf(file, "\n");
     fprintf(file, "Time: %s Host: %s\n", owl_message_get_timestr(m), owl_message_get_hostname(m));
-    ptr=owl_zephyr_get_zsig(owl_message_get_notice(m), &i);
-    buff=owl_malloc(i+10);
-    memcpy(buff, ptr, i);
-    buff[i]='\0';
-    fprintf(file, "From: %s <%s>\n\n", buff, tmp);
+    ptr=owl_message_get_zsig(m);
+    fprintf(file, "From: %s <%s>\n\n", ptr, tmp);
     fprintf(file, "%s\n\n", owl_message_get_body(m));
     owl_free(tmp);
   } else if (owl_message_is_type_aim(m) && !owl_message_is_loginout(m)) {

Modified: branches/perl-message/owl/message.c
===================================================================
--- branches/perl-message/owl/message.c	2007-02-11 05:08:44 UTC (rev 602)
+++ branches/perl-message/owl/message.c	2007-02-11 05:11:10 UTC (rev 603)
@@ -8,6 +8,7 @@
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <time.h>
+#define OWL_PERL
 #include "owl.h"
 
 static const char fileIdent[] = "$Id$";
@@ -15,18 +16,14 @@
 void owl_message_init(owl_message *m)
 {
   m->id=owl_global_get_nextmsgid(&g);
+  m->attributes = newHV();
+
   owl_message_set_direction_none(m);
-  m->delete=0;
-  m->hostname=owl_strdup("");
-  m->zwriteline=strdup("");
+  owl_message_unmark_delete(m);
   m->invalid_format=1;
 
-  owl_list_create(&(m->attributes));
-  
   /* save the time */
-  m->time=time(NULL);
-  m->timestr=owl_strdup(ctime(&(m->time)));
-  m->timestr[strlen(m->timestr)-1]='\0';
+  owl_message_set_time(m, time(NULL));
 
   /* initialize the fmtext */
   owl_fmtext_init_null(&(m->fmtext));
@@ -37,26 +34,8 @@
  */
 void owl_message_set_attribute(owl_message *m, char *attrname, char *attrvalue)
 {
-  int i, j;
-  owl_pair *p;
-
-  /* look for an existing pair with this key, and nuke the entry if
-     found */
-  j=owl_list_get_size(&(m->attributes));
-  for (i=0; i<j; i++) {
-    p=owl_list_get_element(&(m->attributes), i);
-    if (!strcmp(owl_pair_get_key(p), attrname)) {
-      owl_free(owl_pair_get_key(p));
-      owl_free(owl_pair_get_value(p));
-      owl_free(p);
-      owl_list_remove_element(&(m->attributes), i);
-      break;
-    }
-  }
-
-  p=owl_malloc(sizeof(owl_pair));
-  owl_pair_create(p, owl_strdup(attrname), owl_strdup(attrvalue));
-  owl_list_append_element(&(m->attributes), p);
+  SV * val = newSVpv(attrvalue, 0);
+  hv_store(m->attributes, attrname, strlen(attrname), val, 0);
 }
 
 /* return the value associated with the named attribute, or NULL if
@@ -64,40 +43,47 @@
  */
 char *owl_message_get_attribute_value(owl_message *m, char *attrname)
 {
-  int i, j;
-  owl_pair *p;
-
-  j=owl_list_get_size(&(m->attributes));
-  for (i=0; i<j; i++) {
-    p=owl_list_get_element(&(m->attributes), i);
-    if (!strcmp(owl_pair_get_key(p), attrname)) {
-      return(owl_pair_get_value(p));
-    }
+  SV ** val = hv_fetch(m->attributes, attrname, strlen(attrname), 0);
+  if(!val) {
+    return NULL;
   }
 
-  /*
-  owl_function_debugmsg("No attribute %s found for message %i",
-			attrname,
-			owl_message_get_id(m));
-  */
-  return(NULL);
+  return SvPV_nolen(*val);
 }
 
+void owl_message_set_attribute_int(owl_message *m, char *attr, int value)
+{
+  hv_store(m->attributes, attr, strlen(attr), newSViv(value), 0);
+}
+
+int owl_message_get_attribute_int(owl_message *m, char *attr)
+{
+  SV ** val = hv_fetch(m->attributes, attr, strlen(attr), 0);
+  if(!val) return -1;
+  return SvIV(*val);
+}
+
 /* We cheat and indent it for now, since we really want this for
  * the 'info' function.  Later there should just be a generic
  * function to indent fmtext.
  */
 void owl_message_attributes_tofmtext(owl_message *m, owl_fmtext *fm) {
-  int i, j;
-  owl_pair *p;
   char *buff;
+  HE * ent;
+  SV * val;
+  I32 len;
 
   owl_fmtext_init_null(fm);
+  /* XXX: Perl hashes don't maintain an ordering on the keys. Do we care?*/
 
-  j=owl_list_get_size(&(m->attributes));
-  for (i=0; i<j; i++) {
-    p=owl_list_get_element(&(m->attributes), i);
-    buff=owl_sprintf("  %-15.15s: %-35.35s\n", owl_pair_get_key(p), owl_pair_get_value(p));
+  hv_iterinit(m->attributes);
+  while((ent = hv_iternext(m->attributes))) {
+    val = hv_iterval(m->attributes, ent);
+    if(SvROK(val))
+      continue;
+    buff=owl_sprintf("  %-15.15s: %-35.35s\n",
+                     hv_iterkey(ent, &len),
+                     SvPV_nolen(val));
     owl_fmtext_append_normal(fm, buff);
     owl_free(buff);
   }
@@ -302,10 +288,32 @@
   return(1);
 }
 
+/*
+  A note on times: For backwards compatibility with owl, we store the
+  ``timestr'' (ctime) under the ``time'' key in the has, and the
+  numeric time as ``time_t''. Setting the numeric time automatically
+  recomputes the timestr.
+ */
+void owl_message_set_time(owl_message *m, time_t tm) {
+  char * timestr;
+  owl_message_set_attribute_int(m, "time_t", tm);
+  timestr = owl_strdup(ctime(&tm));
+  /* Chop the newline */
+  timestr[strlen(timestr)-1] = 0;
+  owl_message_set_attribute(m, "time", timestr);
+}
+
+time_t owl_message_get_time(owl_message *m) {
+  return owl_message_get_attribute_int(m, "time_t");
+}
+
 char *owl_message_get_timestr(owl_message *m)
 {
-  if (m->timestr) return(m->timestr);
-  return("");
+  char *tmstr;
+
+  tmstr=owl_message_get_attribute_value(m, "time");
+  if (!tmstr) return "";
+  return (tmstr);
 }
 
 /* caller must free the return */
@@ -313,8 +321,9 @@
 {
   struct tm *tmstruct;
   char *out;
+  const time_t tm = owl_message_get_time(m);
 
-  tmstruct=localtime(&(m->time));
+  tmstruct=localtime(&tm);
   out=owl_sprintf("%2.2i:%2.2i", tmstruct->tm_hour, tmstruct->tm_min);
   if (out) return(out);
   return("??:??");
@@ -396,42 +405,46 @@
 
 void owl_message_set_direction_in(owl_message *m)
 {
-  m->direction=OWL_MESSAGE_DIRECTION_IN;
+  owl_message_set_attribute(m, "direction", "in");
 }
 
 void owl_message_set_direction_out(owl_message *m)
 {
-  m->direction=OWL_MESSAGE_DIRECTION_OUT;
+  owl_message_set_attribute(m, "direction", "out");
 }
 
 void owl_message_set_direction_none(owl_message *m)
 {
-  m->direction=OWL_MESSAGE_DIRECTION_NONE;
+  owl_message_set_attribute(m, "direction", "out");
 }
 
-void owl_message_set_direction(owl_message *m, int direction)
+/* void owl_message_set_direction(owl_message *m, int direction)
 {
   m->direction=direction;
-}
+  } */
 
 int owl_message_is_direction_in(owl_message *m)
 {
-  if (m->direction==OWL_MESSAGE_DIRECTION_IN) return(1);
-  return(0);
+  return owl_message_is_direction(m, "in");
 }
 
 int owl_message_is_direction_out(owl_message *m)
 {
-  if (m->direction==OWL_MESSAGE_DIRECTION_OUT) return(1);
-  return(0);
+  return owl_message_is_direction(m, "out");
 }
 
 int owl_message_is_direction_none(owl_message *m)
 {
-  if (m->direction==OWL_MESSAGE_DIRECTION_NONE) return(1);
-  return(0);
+  return owl_message_is_direction(m, "none");
 }
 
+int owl_message_is_direction(owl_message *m, char *wantdir)
+{
+  char * dir = owl_message_get_attribute_value(m, "direction");
+  if(!dir) return 0;
+  return !strcmp(dir, wantdir);
+}
+
 int owl_message_get_numlines(owl_message *m)
 {
   if (m == NULL) return(0);
@@ -442,56 +455,46 @@
 void owl_message_mark_delete(owl_message *m)
 {
   if (m == NULL) return;
-  m->delete=1;
+  owl_message_set_attribute_int(m, "deleted", 1);
 }
 
 void owl_message_unmark_delete(owl_message *m)
 {
   if (m == NULL) return;
-  m->delete=0;
+  owl_message_set_attribute_int(m, "deleted", 0);
 }
 
 char *owl_message_get_zwriteline(owl_message *m)
 {
-  return(m->zwriteline);
+  char *zwriteline;
+
+  zwriteline=owl_message_get_attribute_value(m, "zwriteline");
+  if (!zwriteline) return("");
+  return(zwriteline);
 }
 
 void owl_message_set_zwriteline(owl_message *m, char *line)
 {
-  m->zwriteline=strdup(line);
+  owl_message_set_attribute(m, "zwriteline", line);
 }
 
 int owl_message_is_delete(owl_message *m)
 {
   if (m == NULL) return(0);
-  if (m->delete==1) return(1);
+  if (owl_message_get_attribute_int(m, "deleted")) return(1);
   return(0);
 }
 
-#ifdef HAVE_LIBZEPHYR
-ZNotice_t *owl_message_get_notice(owl_message *m)
-{
-  return(&(m->notice));
-}
-#else
-void *owl_message_get_notice(owl_message *m)
-{
-  return(NULL);
-}
-#endif
-
 void owl_message_set_hostname(owl_message *m, char *hostname)
 {
-  if (m==NULL) return;
-  if (m->hostname!=NULL) {
-    owl_free(m->hostname);
-  }
-  m->hostname=owl_strdup(hostname);
+  owl_message_set_attribute(m, "hostname", hostname);
 }
 
 char *owl_message_get_hostname(owl_message *m)
 {
-  return(m->hostname);
+  char * host = owl_message_get_attribute_value(m, "hostname");
+  if(!host) return "";
+  return host;
 }
 
 void owl_message_curs_waddstr(owl_message *m, WINDOW *win, int aline, int bline, int acol, int bcol, int fgcolor, int bgcolor)
@@ -652,26 +655,20 @@
 }
 
 char *owl_message_get_direction(owl_message *m) {
-  switch (m->direction) {
-  case OWL_MESSAGE_DIRECTION_IN:
-    return("in");
-  case OWL_MESSAGE_DIRECTION_OUT:
-    return("out");
-  case OWL_MESSAGE_DIRECTION_NONE:
-    return("none");
-  default:
-    return("unknown");
-  }
+  char *dir = owl_message_get_attribute_value(m, "direction");
+  if(!dir) return "unknown";
+  return dir;
 }
 
-int owl_message_parse_direction(char *d) {
+int owl_message_valid_direction(char *d) {
   if(!strcmp(d, "in")) {
-    return OWL_MESSAGE_DIRECTION_IN;
+    return 1;
   } else if(!strcmp(d, "out")) {
-    return OWL_MESSAGE_DIRECTION_OUT;
-  } else {
-    return OWL_MESSAGE_DIRECTION_NONE;
+    return 1;
+  } else if(!strcmp(d, "none")) {
+    return 1;
   }
+  return 0;
 }
 
 
@@ -756,23 +753,16 @@
 {
   struct hostent *hent;
   char *ptr, *tmp, *tmp2;
+  char * zsig;
+  int i, j;
 
   owl_message_init(m);
   
   owl_message_set_type_zephyr(m);
   owl_message_set_direction_in(m);
   
-  /* first save the full notice */
-  memcpy(&(m->notice), n, sizeof(ZNotice_t));
-
-  /* a little gross, we'll replace \r's with ' ' for now */
-  owl_zephyr_hackaway_cr(&(m->notice));
-  
   /* save the time, we need to nuke the string saved by message_init */
-  if (m->timestr) owl_free(m->timestr);
-  m->time=n->z_time.tv_sec;
-  m->timestr=owl_strdup(ctime(&(m->time)));
-  m->timestr[strlen(m->timestr)-1]='\0';
+  owl_message_set_time(m, n->z_time.tv_sec);
 
   /* set other info */
   owl_message_set_sender(m, n->z_sender);
@@ -784,8 +774,12 @@
   } else {
     owl_message_set_opcode(m, "");
   }
-  owl_message_set_zsig(m, n->z_message);
 
+  zsig = owl_strdup(n->z_message);
+  owl_text_tr(zsig, '\r', '\n');
+  owl_message_set_zsig(m, zsig);
+  owl_free(zsig);
+
   if ((ptr=strchr(n->z_recipient, '@'))!=NULL) {
     owl_message_set_realm(m, ptr+1);
   } else {
@@ -823,8 +817,6 @@
     owl_message_set_attribute(m, "isauto", "");
   }
 
-  m->zwriteline=strdup("");
-
   /* set the body */
   tmp=owl_zephyr_get_message(n);
   if (owl_global_is_newlinestrip(&g)) {
@@ -836,6 +828,21 @@
   }
   owl_free(tmp);
 
+  /* Save the fields */
+  AV *av_zfields;
+
+  av_zfields = newAV();
+  j=owl_zephyr_get_num_fields(n);
+  for (i=0; i<j; i++) {
+    ptr=owl_zephyr_get_field(n, i+1);
+    av_push(av_zfields, newSVpvn(ptr, strlen(ptr)));
+    owl_free(ptr);
+  }
+  hv_store(m->attributes, "fields", strlen("fields"), newRV_noinc((SV*)av_zfields), 0);
+
+  /* Auth */
+  owl_message_set_attribute(m, "auth", owl_zephyr_get_authstr(n));
+
 #ifdef OWL_ENABLE_ZCRYPT
   /* if zcrypt is enabled try to decrypt the message */
   if (owl_global_is_zcrypt(&g) && !strcasecmp(n->z_opcode, "crypt")) {
@@ -867,15 +874,35 @@
 }
 #endif
 
+int owl_message_get_num_fields(owl_message *m)
+{
+  SV ** ref_fields;
+  AV * fields;
+  ref_fields = hv_fetch(m->attributes, "fields", strlen("fields"), 0);
+  if(!ref_fields) return 0;
+  fields = (AV*)SvRV(*ref_fields);
+  return av_len(fields) + 1;
+}
+
+char * owl_message_get_field(owl_message *m, int n)
+{
+  n--;
+  SV ** ref_fields;
+  AV * fields;
+  SV ** f;
+  ref_fields = hv_fetch(m->attributes, "fields", strlen("fields"), 0);
+  if(!ref_fields) return "";
+  fields = (AV*)SvRV(*ref_fields);
+  f = av_fetch(fields, n, 0);
+  if(!f) return "";
+  return owl_strdup(SvPV_nolen(*f));
+}
+
 /* If 'direction' is '0' it is a login message, '1' is a logout message. */
 void owl_message_create_pseudo_zlogin(owl_message *m, int direction, char *user, char *host, char *time, char *tty)
 {
   char *longuser, *ptr;
 
-#ifdef HAVE_LIBZEPHYR
-  memset(&(m->notice), 0, sizeof(ZNotice_t));
-#endif
-  
   longuser=long_zuser(user);
   
   owl_message_init(m);
@@ -905,8 +932,6 @@
     owl_message_set_realm(m, owl_zephyr_get_realm());
   }
 
-  m->zwriteline=strdup("");
-
   owl_message_set_body(m, "<uninitialized>");
 
   /* save the hostname */
@@ -934,11 +959,11 @@
   owl_message_set_instance(m, owl_zwrite_get_instance(&z));
   if (owl_zwrite_get_numrecips(&z)>0) {
     owl_message_set_recipient(m,
-			      long_zuser(owl_zwrite_get_recip_n(&z, 0))); /* only gets the first user, must fix */
+                              long_zuser(owl_zwrite_get_recip_n(&z, 0))); /* only gets the first user, must fix */
   }
   owl_message_set_opcode(m, owl_zwrite_get_opcode(&z));
   owl_message_set_realm(m, owl_zwrite_get_realm(&z)); /* also a hack, but not here */
-  m->zwriteline=owl_strdup(line);
+  owl_message_set_zwriteline(m, line);
   owl_message_set_body(m, body);
   owl_message_set_zsig(m, zsig);
   
@@ -968,26 +993,6 @@
 
 void owl_message_free(owl_message *m)
 {
-  int i, j;
-  owl_pair *p;
-#ifdef HAVE_LIBZEPHYR    
-  if (owl_message_is_type_zephyr(m) && owl_message_is_direction_in(m)) {
-    ZFreeNotice(&(m->notice));
-  }
-#endif
-  if (m->timestr) owl_free(m->timestr);
-  if (m->zwriteline) owl_free(m->zwriteline);
-
-  /* free all the attributes */
-  j=owl_list_get_size(&(m->attributes));
-  for (i=0; i<j; i++) {
-    p=owl_list_get_element(&(m->attributes), i);
-    owl_free(owl_pair_get_key(p));
-    owl_free(owl_pair_get_value(p));
-    owl_free(p);
-  }
-
-  owl_list_free_simple(&(m->attributes));
- 
+  SvREFCNT_dec(m->attributes);
   owl_fmtext_free(&(m->fmtext));
 }

Modified: branches/perl-message/owl/owl.h
===================================================================
--- branches/perl-message/owl/owl.h	2007-02-11 05:08:44 UTC (rev 602)
+++ branches/perl-message/owl/owl.h	2007-02-11 05:11:10 UTC (rev 603)
@@ -61,11 +61,14 @@
 
 /* Perl and curses don't play nice. */
 #ifdef OWL_PERL
+/* Squelch a warning because both perl and libfaim define bool*/
+#undef bool
 typedef void WINDOW;
 #include <perl.h>
 #include "XSUB.h"
 #else
 typedef void SV;
+typedef void HV;
 #endif
 
 static const char owl_h_fileIdent[] = "$Id$";
@@ -323,18 +326,9 @@
 
 typedef struct _owl_message {
   int id;
-  int direction;
-#ifdef HAVE_LIBZEPHYR
-  ZNotice_t notice;
-#endif
   owl_fmtext fmtext;              /* this is now only a CACHED copy */
   int invalid_format;             /* indicates whether fmtext needs to be regenerated */
-  int delete;
-  char *hostname;
-  owl_list attributes;            /* this is a list of pairs */
-  char *timestr;
-  time_t time;
-  char *zwriteline;
+  HV * attributes;
 } owl_message;
 
 typedef struct _owl_style {

Modified: branches/perl-message/owl/perlconfig.c
===================================================================
--- branches/perl-message/owl/perlconfig.c	2007-02-11 05:08:44 UTC (rev 602)
+++ branches/perl-message/owl/perlconfig.c	2007-02-11 05:11:10 UTC (rev 603)
@@ -29,61 +29,12 @@
 {
   HV *h;
   SV *hr;
-  char *ptr, *blessas, *type;
-  int i, j;
-  owl_pair *pair;
+  char *blessas, *type;
 
   if (!m) return &PL_sv_undef;
-  h = newHV();
+  h = m->attributes;
 
-#define MSG2H(h,field) hv_store(h, #field, strlen(#field), \
-			      newSVpv(owl_message_get_##field(m),0), 0)
-
-  if (owl_message_is_type_zephyr(m)
-      && owl_message_is_direction_in(m)) {
-    /* Handle zephyr-specific fields... */
-    AV *av_zfields;
-
-    av_zfields = newAV();
-    j=owl_zephyr_get_num_fields(owl_message_get_notice(m));
-    for (i=0; i<j; i++) {
-      ptr=owl_zephyr_get_field(owl_message_get_notice(m), i+1);
-      av_push(av_zfields, newSVpvn(ptr, strlen(ptr)));
-      owl_free(ptr);
-    }
-    hv_store(h, "fields", strlen("fields"), newRV_noinc((SV*)av_zfields), 0);
-
-    hv_store(h, "auth", strlen("auth"), 
-	     newSVpv(owl_zephyr_get_authstr(owl_message_get_notice(m)),0),0);
-  }
-
-  j=owl_list_get_size(&(m->attributes));
-  for(i=0; i<j; i++) {
-    pair=owl_list_get_element(&(m->attributes), i);
-    hv_store(h, owl_pair_get_key(pair), strlen(owl_pair_get_key(pair)),
-	     newSVpv(owl_pair_get_value(pair),0),0);
-  }
-  
-  MSG2H(h, type);
-  MSG2H(h, direction);
-  MSG2H(h, class);
-  MSG2H(h, instance);
-  MSG2H(h, sender);
-  MSG2H(h, realm);
-  MSG2H(h, recipient);
-  MSG2H(h, opcode);
-  MSG2H(h, hostname);
-  MSG2H(h, body);
-  MSG2H(h, login);
-  MSG2H(h, zsig);
-  MSG2H(h, zwriteline);
-  if (owl_message_get_header(m)) {
-    MSG2H(h, header); 
-  }
-  hv_store(h, "time", strlen("time"), newSVpv(owl_message_get_timestr(m),0),0);
   hv_store(h, "id", strlen("id"), newSViv(owl_message_get_id(m)),0);
-  hv_store(h, "deleted", strlen("deleted"), newSViv(owl_message_is_delete(m)),0);
-  hv_store(h, "private", strlen("private"), newSViv(owl_message_is_private(m)),0);
 
   type = owl_message_get_type(m);
   if(!type || !*type) type = "generic";
@@ -91,7 +42,7 @@
   type[0] = toupper(type[0]);
   blessas = owl_sprintf("BarnOwl::Message::%s", type);
 
-  hr = sv_2mortal(newRV_noinc((SV*)h));
+  hr = sv_2mortal(newRV_inc((SV*)h));
   hr = sv_bless(hr, gv_stashpv(blessas,0));
   owl_free(type);
   owl_free(blessas);
@@ -134,7 +85,9 @@
     if(!strcmp(key, "type")) {
       owl_message_set_type(m, val);
     } else if(!strcmp(key, "direction")) {
-      owl_message_set_direction(m, owl_message_parse_direction(val));
+      if(!owl_message_valid_direction(val)) {
+        croak("Invalid direction: %s", val);
+      }
     } else if(!strcmp(key, "private")) {
       SV * v = hv_iterval(hash, ent);
       if(SvTRUE(v)) {
@@ -145,10 +98,9 @@
     } else if (!strcmp(key, "zwriteline")) {
       owl_message_set_zwriteline(m, val);
     } else if (!strcmp(key, "time")) {
-      m->timestr = owl_strdup(val);
       struct tm tm;
       strptime(val, "%a %b %d %T %Y", &tm);
-      m->time = mktime(&tm);
+      owl_message_set_time(m, mktime(&tm));
     } else {
       owl_message_set_attribute(m, key, val);
     }
@@ -165,7 +117,8 @@
 char *owl_perlconfig_call_with_message(char *subname, owl_message *m)
 {
   dSP ;
-  int count, len;
+  int count;
+  U32 len;
   SV *msgref, *srv;
   char *out, *preout;
   
@@ -174,6 +127,7 @@
   
   PUSHMARK(SP) ;
   msgref = owl_perlconfig_message2hashref(m);
+  SvREFCNT_inc(msgref);
   XPUSHs(msgref);
   PUTBACK ;
   
@@ -228,6 +182,7 @@
   SAVETMPS;
 
   PUSHMARK(SP);
+  SvREFCNT_inc(msgref);
   XPUSHs(msgref);
   for(i=0;i<argc;i++) {
     XPUSHs(sv_2mortal(newSVpv(argv[i], 0)));

Modified: branches/perl-message/owl/stylefunc.c
===================================================================
--- branches/perl-message/owl/stylefunc.c	2007-02-11 05:08:44 UTC (rev 602)
+++ branches/perl-message/owl/stylefunc.c	2007-02-11 05:11:10 UTC (rev 603)
@@ -69,13 +69,11 @@
 {
 #ifdef HAVE_LIBZEPHYR
   char *ptr, *zsigbuff, frombuff[LINE];
-  ZNotice_t *n;
 #endif
 
   if (owl_message_is_type_zephyr(m) && owl_message_is_direction_in(m)) {
 #ifdef HAVE_LIBZEPHYR
-    n=owl_message_get_notice(m);
-  
+
     /* edit the from addr for printing */
     strcpy(frombuff, owl_message_get_sender(m));
     ptr=strchr(frombuff, '@');
@@ -225,15 +223,12 @@
   char *shorttimestr;
 #ifdef HAVE_LIBZEPHYR
   char *ptr, *zsigbuff, frombuff[LINE];
-  ZNotice_t *n;
 #endif
 
   shorttimestr=owl_message_get_shorttimestr(m);
 
   if (owl_message_is_type_zephyr(m) && owl_message_is_direction_in(m)) {
 #ifdef HAVE_LIBZEPHYR
-    n=owl_message_get_notice(m);
-
     /* edit the from addr for printing */
     strcpy(frombuff, owl_message_get_sender(m));
     ptr=strchr(frombuff, '@');
@@ -401,17 +396,12 @@
   char *tmp;
   char *baseformat="%s %-13.13s %-11.11s %-12.12s ";
   char *sender, *recip;
-#ifdef HAVE_LIBZEPHYR
-  ZNotice_t *n;
-#endif
 
   sender=short_zuser(owl_message_get_sender(m));
   recip=short_zuser(owl_message_get_recipient(m));
   
   if (owl_message_is_type_zephyr(m)) {
 #ifdef HAVE_LIBZEPHYR
-    n=owl_message_get_notice(m);
-    
     owl_fmtext_append_spaces(fm, OWL_TAB);
 
     if (owl_message_is_loginout(m)) {
@@ -526,6 +516,7 @@
 
 }
 
+#if 0
 void owl_stylefunc_vt(owl_fmtext *fm, owl_message *m)
 {
 #ifdef HAVE_LIBZEPHYR
@@ -727,3 +718,5 @@
 
   }
 }
+
+#endif

Modified: branches/perl-message/owl/zephyr.c
===================================================================
--- branches/perl-message/owl/zephyr.c	2007-02-11 05:08:44 UTC (rev 602)
+++ branches/perl-message/owl/zephyr.c	2007-02-11 05:11:10 UTC (rev 603)
@@ -580,20 +580,6 @@
 #endif
 }
 
-#ifdef HAVE_LIBZEPHYR
-void owl_zephyr_hackaway_cr(ZNotice_t *n)
-{
-  /* replace \r's with ' '.  Gross-ish */
-  int i;
-
-  for (i=0; i<n->z_message_len; i++) {
-    if (n->z_message[i]=='\r') {
-      n->z_message[i]=' ';
-    }
-  }
-}
-#endif
-
 void owl_zephyr_zlocate(char *user, char *out, int auth)
 {
 #ifdef HAVE_LIBZEPHYR


home help back first fref pref prev next nref lref last post