[asterisk-dev] Writing Module for Asterisk

Elkeir ismail E.ismail at gmx.de
Tue Nov 21 00:36:22 MST 2006


Hi,
I have writting an Asterisk module. (see below)
It is my goal to have access to the dates, witch are send in the INVITE-message from UAC,A (user_agent client A) to UAC,B (user_agent client B) including the host numbers for RTP and codecs, in order to send them to a Bandwith Brocker.The Bandwith Brocker decide wether the conversation can take place or not.

Can anyone help me to resolve this problem:
>From my module I have only access to the pointer of an struct ast_channel .

File: apps/app_hello.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/pbx.h"
#include "asterisk/channel.h"
#include "asterisk/logger.h"
#include "asterisk/options.h" /* for verbose vars/consts */

static char *tdesc = "Hello Kitty Example App";

static char *app = "Hello";

static char *synopsis = "Writes Hello Kitty to screen";

static char *descrip = 
"  Hello():  Doesn't take any args, just writes hello\n"
"            kitty to the screen.  Simple stuff.\n";

/* fancy module.h macros for counting who's using this module */
STANDARD_LOCAL_USER;
LOCAL_USER_DECL;

static int hello_exec(struct ast_channel *chan, void *data)
{
	struct localuser *u;

	/* add this channel to the user linked list so if we need to
	 * suddenly unload, we know who to gracefully hangup.  The
	 * contents of this macro reference the chan variable as well
	 * as variables defined by LOCAL_USER_DECL */
	LOCAL_USER_ADD(u);

	/* you need to have run asterisk with at least 2 v's to see
	 * this message.  you can always adjust verbosity with the
	 * command 'set verbosity x' */
	if (option_verbose > 2)
		ast_verbose(VERBOSE_PREFIX_3 "Hello Kitty!\n");

	/* we're no longer going to be the caretaker for this
	 * channel */
	LOCAL_USER_REMOVE(u);
	return 0;
}

int load_module(void)
{
	int res;
	res = ast_register_application(app, hello_exec, synopsis, descrip);
        return res;
}

int unload_module(void)
{
	int res;
	res = ast_unregister_application(app);
	/* if there are any channels still using this module, send
	 * them soft hangup signals. */
	STANDARD_HANGUP_LOCALUSERS;
        return res;
}

char *description(void)
{
	return tdesc;
}

int usecount(void)
{
	int res;
	STANDARD_USECOUNT(res);
	return res;
}

char *key(void)
{
	return ASTERISK_GPL_KEY;
}



-- 
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! 
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer


More information about the asterisk-dev mailing list