File: binder.cpp

package info (click to toggle)
bayonne 2.3.2-3
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 11,180 kB
  • ctags: 3,662
  • sloc: cpp: 38,791; sh: 9,323; ansic: 1,391; makefile: 485; perl: 471; java: 405; cs: 402; php: 354; python: 293
file content (159 lines) | stat: -rw-r--r-- 3,522 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// Copyright (C) 2005 Open Source Telecom Corp.
//  
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software 
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

#include "engine.h"

using namespace ost;
using namespace std;

BayonneBinder *BayonneBinder::binder = NULL;

unsigned BayonneBinder::Image::gatherPrefix(const char *prefix, const char **list, unsigned max)
{
	unsigned count = 0;
	unsigned key = 0;
	Name *scr;
	unsigned len = strlen(prefix);

	while(count < max && key < SCRIPT_INDEX_SIZE)
	{
		scr = index[key];
		while(scr && count < max)
		{
			if(!strnicmp(scr->name, prefix, len))
				list[count++] = scr->name + len;
			scr = scr->next;
		}
		++key;
	}
	return count;
}

BayonneBinder::BayonneBinder(const char *id) :
ScriptBinder(id)
{
	if(!binder)
		binder = this;
}

bool BayonneBinder::isDestination(const char *dest)
{
	bool rtn = false;
	Image *img = (Image *)useImage();
	if(binder && img)
		rtn = binder->isDestination(img, dest);
	if(img)
		endImage(img);
	return rtn;
}

unsigned BayonneBinder::gatherDestinations(ScriptImage *img, const char **list, unsigned max)
{
	if(binder)
		return binder->destinations((Image *)img, list, max);
	return 0;
}

Script::Name *BayonneBinder::getIncoming(ScriptImage *img, BayonneSession *s, Event *event)
{
	BayonneSpan *span = s->getSpan();
	Name *scr;
	char buf[65];

	if(sla[0])
	{
		scr = img->getScript(sla);
		if(scr)
			return scr;
	}

	if(s->getInterface() == IF_INET)	
		return NULL;

	if(span)
	{
		snprintf(buf, sizeof(buf), "timeslot::span%d", span->getId());
		scr = img->getScript(buf);
		if(scr)
			return scr;
	}

	snprintf(buf, sizeof(buf), "timeslot::%d", s->getTimeslot());
	return img->getScript(buf);
}

BayonneSession *BayonneBinder::session(ScriptInterp *s)
{
	return (BayonneSession *)(s);
}

const char *BayonneBinder::submit(const char **args)
{
	return NULL;
}

ScriptCompiler *BayonneBinder::compiler(void)
{
	ScriptCompiler *img = new ScriptCompiler(server, "/bayonne/server/config");
	if(getUserdata())
		img->loadPrefix("config", "~bayonne/config");

	return img;
}

bool BayonneBinder::scriptEvent(ScriptInterp *interp, const char *evt)
{
	return (session(interp))->stringEvent(evt);
}

bool BayonneBinder::digitEvent(ScriptInterp *interp, const char *evt)
{
	return (session(interp))->digitEvent(evt);
}

ScriptCompiler *BayonneBinder::getCompiler(void)
{
	return binder->compiler();
}

const char *BayonneBinder::submitRequest(const char **args)
{
	return binder->submit(args);
}

void BayonneBinder::makeCall(BayonneSession *s)
{
}

void BayonneBinder::dropCall(BayonneSession *s)
{
}

unsigned BayonneBinder::destinations(Image *img, const char **list, unsigned max)
{
	return img->gatherPrefix("dialed::", list, max);
}

bool BayonneBinder::isDestination(Image *img, const char *check)
{
	char buf[80];
	snprintf(buf, sizeof(buf), "dialed::%s", check);
	if(img->getScript(buf))
		return true;

	return false;
}