Changeset dd16bdd for perlglue.xs


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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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);
Note: See TracChangeset for help on using the changeset viewer.