Changeset 25729b2


Ignore:
Timestamp:
Jan 8, 2007, 4:17:55 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:
723f464
Parents:
6beac73
git-author:
Nelson Elhage <nelhage@mit.edu> (01/08/07 15:55:09)
git-committer:
Nelson Elhage <nelhage@mit.edu> (01/08/07 16:17:55)
Message:
Adding basic smartnarrow support for jabber, and infrastructure to
make it extensible.
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • functions.c

    r451becb r25729b2  
    28352835
    28362836  /* narrow personal and login messages to the sender or recip as appropriate */
    2837   if (owl_message_is_personal(m) || owl_message_is_loginout(m)) {
    2838     if (owl_message_is_type_zephyr(m)) {
     2837  if (owl_message_is_type_zephyr(m)) {
     2838    if (owl_message_is_personal(m) || owl_message_is_loginout(m)) {
    28392839      if (owl_message_is_direction_in(m)) {
    2840         zperson=short_zuser(owl_message_get_sender(m));
     2840        zperson=short_zuser(owl_message_get_sender(m));
    28412841      } else {
    2842         zperson=short_zuser(owl_message_get_recipient(m));
     2842        zperson=short_zuser(owl_message_get_recipient(m));
    28432843      }
    28442844      filtname=owl_function_zuserfilt(zperson);
     
    28462846      return(filtname);
    28472847    }
    2848     return(NULL);
    2849   }
    2850 
    2851   /* narrow class MESSAGE, instance foo, recip * messages to class, inst */
    2852   if (!strcasecmp(owl_message_get_class(m), "message") && !owl_message_is_personal(m)) {
    2853     filtname=owl_function_classinstfilt(owl_message_get_class(m), owl_message_get_instance(m));
     2848
     2849    /* narrow class MESSAGE, instance foo, recip * messages to class, inst */
     2850    if (!strcasecmp(owl_message_get_class(m), "message") && !owl_message_is_personal(m)) {
     2851      filtname=owl_function_classinstfilt(owl_message_get_class(m), owl_message_get_instance(m));
     2852      return(filtname);
     2853    }
     2854
     2855    /* otherwise narrow to the class */
     2856    if (type==0) {
     2857      filtname=owl_function_classinstfilt(owl_message_get_class(m), NULL);
     2858    } else if (type==1) {
     2859      filtname=owl_function_classinstfilt(owl_message_get_class(m), owl_message_get_instance(m));
     2860    }
    28542861    return(filtname);
    28552862  }
    28562863
    2857   /* otherwise narrow to the class */
    2858   if (type==0) {
    2859     filtname=owl_function_classinstfilt(owl_message_get_class(m), NULL);
    2860   } else if (type==1) {
    2861     filtname=owl_function_classinstfilt(owl_message_get_class(m), owl_message_get_instance(m));
    2862   }
    2863   return(filtname);
     2864  /* pass it off to perl */
     2865  char *argv[1];
     2866  if(type) {
     2867    argv[0] = "-i";
     2868  };
     2869  return owl_perlconfig_message_call_method(m, "smartfilter", type ? 1 : 0, argv);
    28642870}
    28652871
  • perl/modules/jabber.pl

    r9667006 r25729b2  
    11561156}
    11571157
     1158#####################################################################
     1159#####################################################################
     1160
     1161package owl::Message::Jabber;
     1162
     1163our @ISA = qw( owl::Message );
     1164
     1165sub jtype { shift->{jtype} };
     1166sub from { shift->{from} };
     1167sub to { shift->{to} };
     1168
     1169sub smartfilter {
     1170    my $self = shift;
     1171    my $inst = shift;
     1172
     1173    if($self->jtype eq 'chat') {
     1174        my ($user, $filter, $ftext);
     1175        if($self->direction eq 'in') {
     1176            $user = $self->from;
     1177        } else {
     1178            $user = $self->to;
     1179        }
     1180        $user = Net::Jabber::JID->new($user)->GetJID($inst ? 'full' : 'base');
     1181        $filter = "jabber-user-$user";
     1182        $ftext = qq{type ^jabber\$ and ( ( direction ^in\$ and from ^$user ) } .
     1183                 qq{or ( direction ^out\$ and to ^$user ) ) };
     1184        owl::filter("$filter $ftext");
     1185        return $filter;
     1186    }
     1187}
     1188
    115811891;
  • perlconfig.c

    ra55abb3 r25729b2  
    161161  return out;
    162162}
     163
     164
     165/* Calls a method on a perl object representing a message.
     166   If the return value is non-null, the caller must free it.
     167 */
     168char * owl_perlconfig_message_call_method(owl_message *m, char *method, int argc, char ** argv)
     169{
     170  dSP;
     171  unsigned int count, len, i;
     172  SV *msgref, *srv;
     173  char *out, *preout;
     174
     175  msgref = owl_perlconfig_message2hashref(m);
     176
     177  ENTER;
     178  SAVETMPS;
     179
     180  PUSHMARK(SP);
     181  XPUSHs(msgref);
     182  for(i=0;i<argc;i++) {
     183    XPUSHs(sv_2mortal(newSVpv(argv[i], 0)));
     184  }
     185  PUTBACK;
     186
     187  count = call_method(method, G_SCALAR|G_KEEPERR|G_EVAL);
     188
     189  SPAGAIN;
     190
     191  if(count != 1) {
     192    fprintf(stderr, "perl returned wrong count %d\n", count);
     193    abort();
     194  }
     195
     196  if (SvTRUE(ERRSV)) {
     197    STRLEN n_a;
     198    owl_function_error("Error: '%s'", SvPV(ERRSV, n_a));
     199    /* and clear the error */
     200    sv_setsv (ERRSV, &PL_sv_undef);
     201  }
     202
     203  srv = POPs;
     204
     205  if (srv) {
     206    preout=SvPV(srv, len);
     207    out = owl_malloc(strlen(preout)+1);
     208    strncpy(out, preout, len);
     209    out[len] = '\0';
     210  } else {
     211    out = NULL;
     212  }
     213
     214  PUTBACK;
     215  FREETMPS;
     216  LEAVE;
     217
     218  return out;
     219}
     220
    163221
    164222char *owl_perlconfig_readconfig(void)
  • perlwrap.pm

    r23be736 r25729b2  
    187187}
    188188
     189sub smartfilter {
     190    die("smartfilter not supported for this message");
     191}
     192
    189193#####################################################################
    190194#####################################################################
     
    274278#####################################################################
    275279#####################################################################
    276 
    277 package owl::Message::Jabber;
    278 
    279 @ISA = qw( owl::Message );
    280 
    281 #####################################################################
    282 #####################################################################
    283280################################################################################
    284281package owl;
     
    317314{
    318315    my $hook = shift;
    319     use Data::Dumper;
    320316    my @args = @_;
    321317    return join("\n", map {$_->(@args)} @$hook);
Note: See TracChangeset for help on using the changeset viewer.