[ previous ] [ next ] [ threads ]
 To :  yate@v...
 From :  Maciek Kaminski <maciejka@t...>
 Subject :  rmodule, etc
 Date :  Mon, 30 May 2005 18:55:40 +0200
rmodule.cpp - TCP interface for yate: gives extmodule functionality over 
TCP, - implicit channel, + ability to watch events and insert arbitrary 
callendpoints.
dumbchannel.cpp - dumb channel for rmodule to have something to attach to
 
yaypm.py - Yet Another Yate Python Module, based on Twisted asynchronous 
framework, allows to program in "Twisted style" with defereds and as a 
bonus, with little help of python generators, to "flatten" message 
loops. Works both with rmodule and extmodule. See examples: tw.py 
(rmodule) and tw2.py(extmodule).

Maciek Kaminski
      
P.S. Rmodule is still in development stage.




[general]
; This section controls the behaviour of the Remote Module

; port: int: TCP Port to listen on, 0 to disable module
port=5038

; addr: ipaddress: IP address to bind to
addr=127.0.0.1

; how much time give client to handle message in miliseconds. -1 for no limit
timeout=-1

; header: string: Header string to display on connect
header=YATE (http://YATE.null.ro) ready.




#!/usr/bin/python
# -*- coding: iso-8859-2; -*-

# yaypm Yet Another Yate Python Module, uses Twisted 2.0 (http://twistedmatrix.com/projects/core/)

from twisted.protocols.basic import LineReceiver
from twisted.internet.protocol import Protocol, ClientFactory
from twisted.internet import reactor, protocol, defer
from sys import stdout
import sys, logging, random, time

def escape(str, extra = ""):
    str = str + ""
    s = ""
    n = len(str)
    i = 0
    while i < n:
        c = str[i]
        if( ord(c) < 32 ) or (c == extra):
            c = chr(ord(c) + 64)
            s = s + "%"
        elif( c == "%" ):
            s = s + c
        s = s + c
        i = i + 1
    return s

def unescape(str):
    s = ""
    n = len(str)
    i = 0
    while i < n:
        c = str[i]
        if c == "%":
            i = i + 1
            c = str[i]
            if c != "%":
                c = chr(ord(c) - 64)
        s = s + c
        i = i + 1
    return s


class Message:   
    def __init__(self, type, **arguments):
        self.type = type       
        for k, v in arguments.iteritems():
            self.__dict__[k] = v
        if not self.__dict__.has_key("time"):
            self.time = long(time.time())
        if not self.__dict__.has_key("id"):            
            self.id = str(time.time()) + str(random.randrange(1, 10000, 1))
    def __str__(self):
        result = ""
        for k, v in self.__dict__.iteritems():
            result = result + str(k) + ": '" + str(v) + "'\n"
        return result

  
    def format_attrs(self):
        if self.__dict__.has_key("attrs") and self.attrs != {}:
            result = ""
            for name, value in self.attrs.iteritems():
                result = result + ":" + name + "=" + escape(str(value))
            return result
        else:
            return ""

      
    def format_message_response(self, processed):
        result = "%%%%message::