[348] in BarnOwl Developers

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

[D-O-H] r493 - in trunk: . owl owl/perl/modules

daemon@ATHENA.MIT.EDU (nelhage@MIT.EDU)
Thu Oct 29 18:05:10 2009

Resent-From: nelhage@mit.edu
Resent-To: barnowl-dev-mtg@charon.mit.edu
To: dirty-owl-hackers@mit.edu
From: nelhage@MIT.EDU
Reply-to: dirty-owl-hackers@MIT.EDU
Date: Mon,  8 Jan 2007 16:17:55 -0500 (EST)

Author: nelhage
Date: 2007-01-08 16:17:55 -0500 (Mon, 08 Jan 2007)
New Revision: 493

Modified:
   trunk/
   trunk/owl/functions.c
   trunk/owl/perl/modules/jabber.pl
   trunk/owl/perlconfig.c
   trunk/owl/perlwrap.pm
Log:
 r17864@phanatique:  nelhage | 2007-01-08 15:55:09 -0500
 Adding basic smartnarrow support for jabber, and infrastructure to
 make it extensible.



Property changes on: trunk
___________________________________________________________________
Name: svk:merge
   - bb873fd7-8e23-0410-944a-99ec44c633eb:/branches/owl/filter-rewrite:15925
bb873fd7-8e23-0410-944a-99ec44c633eb:/local/d-o-h/trunk:17863
   + bb873fd7-8e23-0410-944a-99ec44c633eb:/branches/owl/filter-rewrite:15925
bb873fd7-8e23-0410-944a-99ec44c633eb:/local/d-o-h/trunk:17864

Modified: trunk/owl/functions.c
===================================================================
--- trunk/owl/functions.c	2007-01-08 21:17:37 UTC (rev 492)
+++ trunk/owl/functions.c	2007-01-08 21:17:55 UTC (rev 493)
@@ -2834,33 +2834,39 @@
   }
 
   /* narrow personal and login messages to the sender or recip as appropriate */
-  if (owl_message_is_personal(m) || owl_message_is_loginout(m)) {
-    if (owl_message_is_type_zephyr(m)) {
+  if (owl_message_is_type_zephyr(m)) {
+    if (owl_message_is_personal(m) || owl_message_is_loginout(m)) {
       if (owl_message_is_direction_in(m)) {
-	zperson=short_zuser(owl_message_get_sender(m));
+        zperson=short_zuser(owl_message_get_sender(m));
       } else {
-	zperson=short_zuser(owl_message_get_recipient(m));
+        zperson=short_zuser(owl_message_get_recipient(m));
       }
       filtname=owl_function_zuserfilt(zperson);
       owl_free(zperson);
       return(filtname);
     }
-    return(NULL);
-  }
 
-  /* narrow class MESSAGE, instance foo, recip * messages to class, inst */
-  if (!strcasecmp(owl_message_get_class(m), "message") && !owl_message_is_personal(m)) {
-    filtname=owl_function_classinstfilt(owl_message_get_class(m), owl_message_get_instance(m));
+    /* narrow class MESSAGE, instance foo, recip * messages to class, inst */
+    if (!strcasecmp(owl_message_get_class(m), "message") && !owl_message_is_personal(m)) {
+      filtname=owl_function_classinstfilt(owl_message_get_class(m), owl_message_get_instance(m));
+      return(filtname);
+    }
+
+    /* otherwise narrow to the class */
+    if (type==0) {
+      filtname=owl_function_classinstfilt(owl_message_get_class(m), NULL);
+    } else if (type==1) {
+      filtname=owl_function_classinstfilt(owl_message_get_class(m), owl_message_get_instance(m));
+    }
     return(filtname);
   }
 
-  /* otherwise narrow to the class */
-  if (type==0) {
-    filtname=owl_function_classinstfilt(owl_message_get_class(m), NULL);
-  } else if (type==1) {
-    filtname=owl_function_classinstfilt(owl_message_get_class(m), owl_message_get_instance(m));
-  }
-  return(filtname);
+  /* pass it off to perl */
+  char *argv[1];
+  if(type) {
+    argv[0] = "-i";
+  };
+  return owl_perlconfig_message_call_method(m, "smartfilter", type ? 1 : 0, argv);
 }
 
 void owl_function_smartzpunt(int type)

Modified: trunk/owl/perl/modules/jabber.pl
===================================================================
--- trunk/owl/perl/modules/jabber.pl	2007-01-08 21:17:37 UTC (rev 492)
+++ trunk/owl/perl/modules/jabber.pl	2007-01-08 21:17:55 UTC (rev 493)
@@ -1155,4 +1155,35 @@
     return "";
 }
 
+#####################################################################
+#####################################################################
+
+package owl::Message::Jabber;
+
+our @ISA = qw( owl::Message );
+
+sub jtype { shift->{jtype} };
+sub from { shift->{from} };
+sub to { shift->{to} };
+
+sub smartfilter {
+    my $self = shift;
+    my $inst = shift;
+
+    if($self->jtype eq 'chat') {
+        my ($user, $filter, $ftext);
+        if($self->direction eq 'in') {
+            $user = $self->from;
+        } else {
+            $user = $self->to;
+        }
+        $user = Net::Jabber::JID->new($user)->GetJID($inst ? 'full' : 'base');
+        $filter = "jabber-user-$user";
+        $ftext = qq{type ^jabber\$ and ( ( direction ^in\$ and from ^$user ) } .
+                 qq{or ( direction ^out\$ and to ^$user ) ) };
+        owl::filter("$filter $ftext");
+        return $filter;
+    }
+}
+
 1;

Modified: trunk/owl/perlconfig.c
===================================================================
--- trunk/owl/perlconfig.c	2007-01-08 21:17:37 UTC (rev 492)
+++ trunk/owl/perlconfig.c	2007-01-08 21:17:55 UTC (rev 493)
@@ -161,6 +161,64 @@
   return out;
 }
 
+
+/* Calls a method on a perl object representing a message.
+   If the return value is non-null, the caller must free it.
+ */
+char * owl_perlconfig_message_call_method(owl_message *m, char *method, int argc, char ** argv)
+{
+  dSP;
+  unsigned int count, len, i;
+  SV *msgref, *srv;
+  char *out, *preout;
+
+  msgref = owl_perlconfig_message2hashref(m);
+
+  ENTER;
+  SAVETMPS;
+
+  PUSHMARK(SP);
+  XPUSHs(msgref);
+  for(i=0;i<argc;i++) {
+    XPUSHs(sv_2mortal(newSVpv(argv[i], 0)));
+  }
+  PUTBACK;
+
+  count = call_method(method, G_SCALAR|G_KEEPERR|G_EVAL);
+
+  SPAGAIN;
+
+  if(count != 1) {
+    fprintf(stderr, "perl returned wrong count %d\n", count);
+    abort();
+  }
+
+  if (SvTRUE(ERRSV)) {
+    STRLEN n_a;
+    owl_function_error("Error: '%s'", SvPV(ERRSV, n_a));
+    /* and clear the error */
+    sv_setsv (ERRSV, &PL_sv_undef);
+  }
+
+  srv = POPs;
+
+  if (srv) {
+    preout=SvPV(srv, len);
+    out = owl_malloc(strlen(preout)+1);
+    strncpy(out, preout, len);
+    out[len] = '\0';
+  } else {
+    out = NULL;
+  }
+
+  PUTBACK;
+  FREETMPS;
+  LEAVE;
+
+  return out;
+}
+
+
 char *owl_perlconfig_readconfig(void)
 {
   int ret;

Modified: trunk/owl/perlwrap.pm
===================================================================
--- trunk/owl/perlwrap.pm	2007-01-08 21:17:37 UTC (rev 492)
+++ trunk/owl/perlwrap.pm	2007-01-08 21:17:55 UTC (rev 493)
@@ -186,6 +186,10 @@
     }
 }
 
+sub smartfilter {
+    die("smartfilter not supported for this message");
+}
+
 #####################################################################
 #####################################################################
 
@@ -273,13 +277,6 @@
 
 #####################################################################
 #####################################################################
-
-package owl::Message::Jabber;
-
-@ISA = qw( owl::Message );
-
-#####################################################################
-#####################################################################
 ################################################################################
 package owl;
 
@@ -316,7 +313,6 @@
 sub runHook_accumulate($@)
 {
     my $hook = shift;
-    use Data::Dumper;
     my @args = @_;
     return join("\n", map {$_->(@args)} @$hook);
 }


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