Changeset dd16bdd


Ignore:
Timestamp:
Oct 27, 2006, 1:19:54 AM (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:
1b6b2f3
Parents:
39c036d
Message:
Initial support for creating and injecting messages into the
display. Note that at the moment, you can easily segfault owl from
perl by injecting messages that don't contain fields owl assumes they
will.
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • message.c

    r8298425 rdd16bdd  
    341341  m->type=OWL_MESSAGE_TYPE_AIM;
    342342}
     343
     344void owl_message_set_type(owl_message *m, int type)
     345{
     346  m->type=type;
     347}
    343348                                               
    344349int owl_message_is_type_admin(owl_message *m)
     
    396401{
    397402  m->direction=OWL_MESSAGE_DIRECTION_NONE;
     403}
     404
     405void owl_message_set_direction(owl_message *m, int direction)
     406{
     407  m->direction=direction;
    398408}
    399409
     
    631641}
    632642
     643int owl_message_parse_type(char *type) {
     644  if(!strcmp(type, "admin")) {
     645    return OWL_MESSAGE_TYPE_ADMIN;
     646  } else if(!strcmp(type, "zephyr")) {
     647    return OWL_MESSAGE_TYPE_ZEPHYR;
     648  } if(!strcmp(type, "aim")) {
     649    return OWL_MESSAGE_TYPE_AIM;
     650  } else if(!strcmp(type, "jabber")) {
     651    return OWL_MESSAGE_TYPE_JABBER;
     652  } else if(!strcmp(type, "icq")) {
     653    return OWL_MESSAGE_TYPE_ICQ;
     654  } else if(!strcmp(type, "yahoo")) {
     655    return OWL_MESSAGE_TYPE_YAHOO;
     656  } else if(!strcmp(type, "msn")) {
     657    return OWL_MESSAGE_TYPE_MSN;
     658  } else if(!strcmp(type, "loopback")) {
     659    return OWL_MESSAGE_TYPE_LOOPBACK;
     660  } else {
     661    return OWL_MESSAGE_TYPE_GENERIC;
     662  }
     663}
     664
    633665char *owl_message_get_direction(owl_message *m) {
    634666  switch (m->direction) {
     
    644676}
    645677
     678int owl_message_parse_direction(char *d) {
     679  if(!strcmp(d, "in")) {
     680    return OWL_MESSAGE_DIRECTION_IN;
     681  } else if(!strcmp(d, "out")) {
     682    return OWL_MESSAGE_DIRECTION_OUT;
     683  } else {
     684    return OWL_MESSAGE_DIRECTION_NONE;
     685  }
     686}
     687
     688
    646689char *owl_message_get_login(owl_message *m) {
    647690  if (owl_message_is_login(m)) {
     
    653696  }
    654697}
     698
    655699
    656700char *owl_message_get_header(owl_message *m) {
  • perlglue.xs

    r6922edd rdd16bdd  
     1/* -*- mode: c; indent-tabs-mode: t; c-basic-offset: 8 -*- */
    12static const char fileIdent[] = "$Id$";
    23
     
    9091                cmd.description = description;
    9192                cmd.validctx = OWL_CTX_ANY;
    92 
    9393                cmd.cmd_aliased_to = NULL;
    9494                cmd.cmd_args_fn = NULL;
     
    9898                cmd.cmd_ctxv_fn = NULL;
    9999                cmd.cmd_ctxi_fn = NULL;
     100                owl_cmddict_add_cmd(owl_global_get_cmddict(&g), &cmd);
    100101
    101                 owl_cmddict_add_cmd(owl_global_get_cmddict(&g), &cmd);
     102void queue_message(msg)
     103        SV *msg
     104        PREINIT:
     105                char * key;
     106                char * val;
     107                owl_message *m;
     108                HV * hash;
     109                HE * ent;
     110                I32 count;
     111                I32 len;
     112        CODE:
     113                if(!SvROK(msg) || SvTYPE(SvRV(msg)) != SVt_PVHV) {
     114                        croak("Usage: owl::queue_message($message)");
     115                }
     116               
     117                hash = (HV*)SvRV(msg);
     118                m = owl_malloc(sizeof(owl_message));
     119                owl_message_init(m);
     120               
     121                count = hv_iterinit(hash);
     122                while((ent = hv_iternext(hash))) {
     123                        key = hv_iterkey(ent, &len);
     124                        val = SvPV_nolen(hv_iterval(hash, ent));
     125                        if(!strcmp(key, "type")) {
     126                                owl_message_set_type(m, owl_message_parse_type(val));
     127                        } else if(!strcmp(key, "direction")) {
     128                                owl_message_set_direction(m, owl_message_parse_direction(val));
     129                        } else {
     130                                owl_message_set_attribute(m, key, val);
     131                        }
     132                }
     133
     134                owl_global_messagequeue_addmsg(&g, m);
  • perlwrap.pm

    r6922edd rdd16bdd  
    6262package owl::Message;
    6363
     64sub new {
     65    my $class = shift;
     66    my %args = (@_);
     67    if($class eq __PACKAGE__ && $args{type}) {
     68        $class = "owl::Message::" . ucfirst $args{type};
     69    }
     70    return bless {%args}, $class;
     71}
     72
    6473sub type        { return shift->{"type"}; }
    6574sub direction   { return shift->{"direction"}; }
     
    8493sub is_admin    { return (shift->{"type"} eq "admin"); }
    8594sub is_generic  { return (shift->{"type"} eq "generic"); }
     95sub is_jabber   { return (shift->{"type"} eq "jabber"); }
    8696
    8797# These are overridden by appropriate message types
     
    251261#####################################################################
    252262
     263package owl::Message::Jabber;
     264
     265@ISA = qw( owl::Message );
     266
     267#####################################################################
     268#####################################################################
     269
    253270# switch to package main when we're done
    254271package main;
Note: See TracChangeset for help on using the changeset viewer.