/*
 * Asterisk -- A telephony toolkit for Linux.
 *
 * Skeleton Switch application
 * 
 * Copyright (C) 1999, Mark Spencer
 *
 * Mark Spencer <markster@linux-support.net>
 *
 * This program is free software, distributed under the terms of
 * the GNU General Public License
 */

#include <asterisk/file.h>
#include <asterisk/logger.h>
#include <asterisk/channel.h>
#include <asterisk/pbx.h>
#include <asterisk/module.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>

#include <pthread.h>

#define MYMAX_RESULTS 20

static char *desc = "Example Switch";

static char *app = "exampleswitch";

STANDARD_LOCAL_USER;

LOCAL_USER_DECL;

static pthread_mutex_t exswitch_lock = AST_MUTEX_INITIALIZER;

static int skel_exec(struct ast_channel *chan, void *data)
{
	int res=0;
	struct localuser *u;
	if (!data) {
		ast_log(LOG_WARNING, "skel requires an argument (filename)\n");
		return -1;
	}
	LOCAL_USER_ADD(u);
	/* Do our thing here */
	LOCAL_USER_REMOVE(u);
	return res;
}

static int exswitch_exists(struct ast_channel *chan, char *context, char *exten, int priority, char *callerid, char *data)
{
	int res = 0; 
	int ret, i;

        ast_log(LOG_NOTICE, "exswitch_exists %d: con: %s, exten: %s, pri: %d, cid: %s, data: %s\n", res, context, exten, priority, callerid ? callerid : "<unknown>", data);

	return res;
}

static int exswitch_canmatch(struct ast_channel *chan, char *context, char *exten, int priority, char *callerid, char *data)
{

	int res = 0; 
	int ret, i;

        ast_log(LOG_NOTICE, "exswitch_canmatch %d: con: %s, exten: %s, pri: %d, cid: %s, data: %s\n", res, context, exten, priority, callerid ? callerid : "<unknown>", data);

	return res;

}

static int exswitch_exec(struct ast_channel *chan, char *context, char *exten, int priority, char *callerid, int newstack, char *data)
{
	struct ast_app *dial;
	int ret, i;
	int res = 0;

        ast_log(LOG_NOTICE, "exswitch_exec: con: %s, exten: %s, pri: %d, cid: %s, data: %s\n", context, exten, priority, callerid ? callerid : "<unknown>", data);

#if 0
	dial = pbx_findapp("Dial");
	if (dial) {
		pbx_exec(chan, dial, req, newstack);
	} else {
		ast_log(LOG_WARNING, "No dial application registered\n");
	}
#endif

	return res;
}

static struct ast_switch example_switch =
{
	name:			app,
	description:		desc,
	exists:			exswitch_exists,
	canmatch:		exswitch_canmatch, 
	exec:			exswitch_exec,
};


int load_module(void)
{
	int res = 0;
	if (ast_register_switch(&example_switch))
		ast_log(LOG_ERROR, "Unable to register Example Switch\n");


	return res;
}

int unload_module(void)
{
	int res = 0;
	ast_unregister_switch(&example_switch);

	return res;
}

char *description(void)
{
	return desc;
}

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

char *key()
{
	return ASTERISK_GPL_KEY;
}
