Fixed some parts from the gatekeeper.
git-svn-id: http://yate.null.ro/svn/yate/trunk@108 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
parent
1ae2f0e117
commit
b2f4f71597
|
@ -116,14 +116,6 @@ class YateGatekeeperCall : public H323GatekeeperCall
|
|||
);
|
||||
};
|
||||
|
||||
class TranslateObj : public GenObject
|
||||
{
|
||||
public:
|
||||
H225_TransportAddress_ipAddress ip;
|
||||
PString alias;
|
||||
String e164;
|
||||
};
|
||||
|
||||
class YateGatekeeperServer : public H323GatekeeperServer
|
||||
{
|
||||
PCLASSINFO(YateGatekeeperServer, H323GatekeeperServer);
|
||||
|
@ -136,7 +128,6 @@ class YateGatekeeperServer : public H323GatekeeperServer
|
|||
H323GatekeeperURQ & request );
|
||||
H323GatekeeperCall * CreateCall(const OpalGloballyUniqueID & id,H323GatekeeperCall::Direction dir);
|
||||
BOOL TranslateAliasAddressToSignalAddress(const H225_AliasAddress & alias,H323TransportAddress & address);
|
||||
TranslateObj * findAlias(const PString & alias);
|
||||
virtual BOOL GetUsersPassword(const PString & alias,PString & password) const;
|
||||
|
||||
private:
|
||||
|
@ -550,12 +541,11 @@ bool YateH323EndPoint::Init(void)
|
|||
}
|
||||
}
|
||||
}
|
||||
/* if (s_cfg.getBoolValue("gk","server",true))
|
||||
if (s_cfg.getBoolValue("gk","server",true))
|
||||
{
|
||||
gkServer = new YateGatekeeperServer(*this);
|
||||
gkServer->Init();
|
||||
}
|
||||
*/
|
||||
|
||||
// bool useGk = s_cfg.getBoolean("general","use_gatekeeper");
|
||||
return true;
|
||||
|
@ -1010,17 +1000,6 @@ BOOL YateH323AudioSource::Write(const void *buf, PINDEX len)
|
|||
return true;
|
||||
}
|
||||
|
||||
TranslateObj * YateGatekeeperServer::findAlias(const PString &alias)
|
||||
{
|
||||
ObjList *p = &translate;
|
||||
for (; p; p=p->next()) {
|
||||
TranslateObj *t =
|
||||
static_cast<TranslateObj *>(p->get());
|
||||
if (t && t->alias == alias)
|
||||
return t;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
BOOL YateGatekeeperServer::GetUsersPassword(const PString & alias,PString & password) const
|
||||
{
|
||||
|
@ -1045,100 +1024,75 @@ H323GatekeeperCall * YateGatekeeperServer::CreateCall(const OpalGloballyUniqueID
|
|||
|
||||
H323GatekeeperRequest::Response YateGatekeeperServer::OnRegistration(H323GatekeeperRRQ & request)
|
||||
{
|
||||
// PString request_s = request.GetGatekeeperIdentifier();
|
||||
// request.rrq.HasOptionalField(H225_RegistrationRequest::e_endpointIdentifier);
|
||||
PString alias;
|
||||
PString ips;
|
||||
PString r ;
|
||||
for (int j = 0; j < request.rrq.m_terminalAlias.GetSize(); j++) {
|
||||
alias = H323GetAliasAddressString(request.rrq.m_terminalAlias[j]);
|
||||
r = H323GetAliasAddressE164(request.rrq.m_terminalAlias[j]);
|
||||
// PString c = request.GetEndpointIdentifier();
|
||||
Debug(DebugInfo,"marimea matrici este %d : ",request.rrq.m_callSignalAddress.GetSize());
|
||||
// H225_TransportAddress_ipAddress ip=request.rrq.m_callSignalAddress[0];
|
||||
for (int k=0; k<request.rrq.m_callSignalAddress.GetSize();k++)
|
||||
{
|
||||
H225_TransportAddress_ipAddress ip=request.rrq.m_callSignalAddress[k];
|
||||
ips = String(ip.m_ip[0]) + "." + String(ip.m_ip[1]) + "." + String(ip.m_ip[2]) + "." + String(ip.m_ip[3]) + ":" + String((int)ip.m_port) ;
|
||||
Debug(DebugInfo,"Stringul initial este %s",(const char *)ips);
|
||||
}
|
||||
// Debug(DebugInfo,"ip %d.%d.%d.%d:%u",ip.m_ip[0], ip.m_ip[1], ip.m_ip[2], ip.m_ip[3],ip.m_port.GetValue());
|
||||
|
||||
// Debug(DebugInfo,"end point user id %s and e164 %s",(const char *)s,(const char *)r); //(const char *)request.m_endpointIdentifier); //request_s.GetLength());
|
||||
H225_TransportAddress_ipAddress ip=request.rrq.m_callSignalAddress[0];
|
||||
Message *m = new Message("regist");
|
||||
m->addParam("username",alias);
|
||||
m->addParam("techno","h323");
|
||||
m->addParam("data",ips);
|
||||
Engine::dispatch(m);
|
||||
Debug(DebugInfo,"prefix boo registering %s",m->retValue().c_str());
|
||||
|
||||
TranslateObj *t = new TranslateObj;
|
||||
t->ip = ip;
|
||||
t->alias = alias;
|
||||
t->e164 = m->retValue();
|
||||
translate.append(t);
|
||||
}
|
||||
/* for (int i = 0; i < request.rrq.m_callSignalAddress.GetSize(); i++) {
|
||||
Debug(DebugInfo,"end point identifier %d",request.rrq.m_callSignalAddress[i]); //(const char *)request.m_endpointIdentifier); //request_s.GetLength());
|
||||
}*/
|
||||
|
||||
return H323GatekeeperServer::OnRegistration(request);
|
||||
int i = H323GatekeeperServer::OnRegistration(request);
|
||||
if (i == H323GatekeeperRequest::Confirm)
|
||||
{
|
||||
PString alias,r;
|
||||
String ips;
|
||||
for (int j = 0; j < request.rrq.m_terminalAlias.GetSize(); j++) {
|
||||
alias = H323GetAliasAddressString(request.rrq.m_terminalAlias[j]);
|
||||
r = H323GetAliasAddressE164(request.rrq.m_terminalAlias[j]);
|
||||
H225_TransportAddress_ipAddress ip;
|
||||
if (request.rrq.m_callSignalAddress.GetSize() >0)
|
||||
ip=request.rrq.m_callSignalAddress[0];
|
||||
ips = "h323/" + String(ip.m_ip[0]) + "." + String(ip.m_ip[1]) + "." + String(ip.m_ip[2]) + "." + String(ip.m_ip[3]) + ":" + String((int)ip.m_port);
|
||||
/**
|
||||
* we deal just with the first callSignalAddress, since openh323
|
||||
* don't give a shit for multi hosted boxes.
|
||||
*/
|
||||
Message *m = new Message("regist");
|
||||
m->addParam("username",alias);
|
||||
m->addParam("techno","h323gk");
|
||||
m->addParam("data",ips);
|
||||
if (!Engine::dispatch(m) && !m->retValue().null())
|
||||
return H323GatekeeperRequest::Reject;
|
||||
}
|
||||
} else
|
||||
return (H323Transaction::Response)i;
|
||||
return H323GatekeeperRequest::Confirm;
|
||||
}
|
||||
H323GatekeeperRequest::Response YateGatekeeperServer::OnUnregistration(H323GatekeeperURQ & request )
|
||||
{
|
||||
/* for (int j = 0; j < request.urq.m_terminalAlias.GetSize(); j++) {
|
||||
PString s = H323GetAliasAddressString(request.urq.m_terminalAlias[j]);
|
||||
}*/
|
||||
// PString s = H323GetAliasAddressString(request.urq.m_callSignalAddress[0]);
|
||||
PString s = H323GetAliasAddressString(request.urq.m_endpointAlias[0]);
|
||||
TranslateObj * c = findAlias(s);
|
||||
|
||||
Message *m = new Message("unregist");
|
||||
m->addParam("prefix",c->e164);
|
||||
Debug(DebugInfo,"prefixh323 %s",c->e164.c_str());
|
||||
Engine::dispatch(m);
|
||||
|
||||
//Debug(DebugInfo,"aliasul descarcat este %s",(const char *)c->alias);
|
||||
translate.remove(c);
|
||||
|
||||
return H323GatekeeperServer::OnUnregistration(request);
|
||||
/* We use just the first alias since is the one we need */
|
||||
int i = H323GatekeeperServer::OnUnregistration(request);
|
||||
if (i == H323GatekeeperRequest::Confirm)
|
||||
{
|
||||
for (int j = 0; j < request.urq.m_endpointAlias.GetSize(); j++) {
|
||||
PString alias = H323GetAliasAddressString(request.urq.m_endpointAlias[j]);
|
||||
if (alias.IsEmpty())
|
||||
return H323GatekeeperRequest::Reject;
|
||||
Message *m = new Message("unregist");
|
||||
m->addParam("username",alias);
|
||||
Engine::dispatch(m);
|
||||
}
|
||||
} else
|
||||
return (H323Transaction::Response)i;
|
||||
return H323GatekeeperRequest::Confirm;
|
||||
}
|
||||
|
||||
BOOL YateGatekeeperServer::TranslateAliasAddressToSignalAddress(const H225_AliasAddress & alias,H323TransportAddress & address)
|
||||
{
|
||||
PString aliasString = H323GetAliasAddressString(alias);
|
||||
// TranslateObj *f = new TranslateObj;
|
||||
//f->alias = aliasString;
|
||||
//translate.find()
|
||||
TranslateObj * c = findAlias(aliasString);
|
||||
// c->alias = aliasString;
|
||||
//Debug(DebugInfo,"ip-ul corespondent este %d.%d.%d.%d:%u",c->ip.m_ip[0],c->ip.m_ip[1],c->ip.m_ip[2],c->ip.m_ip[3],c->ip.m_port.GetValue());
|
||||
if (c)
|
||||
{
|
||||
Debug(DebugInfo,"alias-ul este %s si cel gasit este %s",(const char *)aliasString,(const char *)c->alias);
|
||||
// Debug(DebugInfo,"ip-ul corespondent este %d.%d.%d.%d:%u",c->ip.m_ip[0],c->ip.m_ip[1],c->ip.m_ip[2],c->ip.m_ip[3],c->ip.m_port.GetValue());
|
||||
String s = "ip$" + String(c->ip.m_ip[0]) + "." + String(c->ip.m_ip[1]) + "." + String(c->ip.m_ip[2]) + "." + String(c->ip.m_ip[3]) + ":" + String((int)c->ip.m_port) ;
|
||||
Debug(DebugInfo,"Stringul este %s",(const char *)s);
|
||||
/* H323TransportAddress aliasAsTransport = c->aliasaddres;
|
||||
PIPSocket::Address ip;
|
||||
WORD port = H323EndPoint::DefaultTcpPort;
|
||||
if (!aliasAsTransport.GetIpAndPort(ip, port)) {
|
||||
Debug(DebugInfo,"RAS\tCould not translate %s as host name.",(const char *)aliasString);
|
||||
return FALSE;
|
||||
}*/
|
||||
// H225_TransportAddress ceva = c->aliasaddres;
|
||||
// address = H323TransportAddress(ceva);
|
||||
//Debug(DebugInfo,"RAS\tTranslating alias %s to %s, host name",(const char *)aliasString,(const char *)address);
|
||||
// return TRUE;
|
||||
address = s.c_str();
|
||||
return TRUE;
|
||||
|
||||
//if (H323GatekeeperServer::TranslateAliasAddressToSignalAddress(alias, address))
|
||||
}
|
||||
// if (H323GatekeeperServer::TranslateAliasAddressToSignalAddress(alias, address))
|
||||
// return TRUE;
|
||||
|
||||
Message m("route");
|
||||
m.addParam("called",aliasString);
|
||||
Engine::dispatch(m);
|
||||
String s = m.retValue();
|
||||
if (!s.null()){
|
||||
/**
|
||||
* Here we have 2 cases, first is handle when the call have to be send
|
||||
* to endpoint (if the call is to another yate channel, or is h323
|
||||
* proxied), or if has to be send to another gatekeeper we find out
|
||||
* from the techno parameter
|
||||
*/
|
||||
if ((m.getParam("techno")) && (*(m.getParam("techno")) == "h323gk"))
|
||||
address = s.c_str();
|
||||
else {
|
||||
s.clear();
|
||||
s << "ip$" << s_cfg.getValue("gk","interface1") << ":" << s_cfg.getIntValue("ep","port",1720);
|
||||
address = s.c_str();
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,8 +31,10 @@ class RegistHandler : public MessageHandler
|
|||
{
|
||||
public:
|
||||
RegistHandler(const char *name)
|
||||
: MessageHandler(name) { }
|
||||
: MessageHandler(name),m_init(false) { }
|
||||
virtual bool received(Message &msg);
|
||||
bool init();
|
||||
bool m_init;
|
||||
};
|
||||
|
||||
class UnRegistHandler : public MessageHandler
|
||||
|
@ -58,7 +60,8 @@ public:
|
|||
: MessageHandler(name,prio) { }
|
||||
virtual bool received(Message &msg);
|
||||
};
|
||||
|
||||
/**
|
||||
* I can't remeber why i have made this class :)
|
||||
class RegistThread : public Thread
|
||||
{
|
||||
public:
|
||||
|
@ -66,7 +69,7 @@ public:
|
|||
~RegistThread();
|
||||
void run(void);
|
||||
};
|
||||
|
||||
*/
|
||||
class RegistPlugin : public Plugin
|
||||
{
|
||||
public:
|
||||
|
@ -84,15 +87,14 @@ private:
|
|||
bool AuthHandler::received(Message &msg)
|
||||
{
|
||||
// const char *calltime = c_safe(msg.getValue("time"));
|
||||
const char *username = c_safe(msg.getValue("username"));
|
||||
String username = c_safe(msg.getValue("username"));
|
||||
|
||||
Lock lock(dbmutex);
|
||||
if (!conn)
|
||||
return false;
|
||||
|
||||
char buffer[2048];
|
||||
snprintf(buffer,sizeof(buffer),"SELECT password FROM register WHERE username='%s'",username);
|
||||
PGresult *respgsql = PQexec(conn,buffer);
|
||||
String s = "SELECT password FROM register WHERE username='" + username + "'";
|
||||
PGresult *respgsql = PQexec(conn,(const char *)s);
|
||||
if (!respgsql || PQresultStatus(respgsql) != PGRES_TUPLES_OK)
|
||||
{
|
||||
Debug(DebugFail,"Failed to query from database: %s",
|
||||
|
@ -107,20 +109,40 @@ bool AuthHandler::received(Message &msg)
|
|||
return true;
|
||||
};
|
||||
|
||||
bool RegistHandler::init()
|
||||
{
|
||||
/**
|
||||
* We must clear the routing table when loading the new table, to not
|
||||
* leave any garbage there
|
||||
*/
|
||||
String s = "DELETE FROM routepaid";
|
||||
PGresult *respgsql = PQexec(conn,(const char *)s);
|
||||
if (PQresultStatus(respgsql) != PGRES_COMMAND_OK)
|
||||
{
|
||||
Debug(DebugFail,"Failed to clear the routepaid table: %s",
|
||||
PQerrorMessage(conn));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RegistHandler::received(Message &msg)
|
||||
{
|
||||
// const char *calltime = c_safe(msg.getValue("time"));
|
||||
const char *username = c_safe(msg.getValue("username"));
|
||||
const char *techno = c_safe(msg.getValue("techno"));
|
||||
const char *data = c_safe(msg.getValue("data"));
|
||||
if (!m_init)
|
||||
{
|
||||
init();
|
||||
m_init= true;
|
||||
}
|
||||
String username = c_safe(msg.getValue("username"));
|
||||
String techno = c_safe(msg.getValue("techno"));
|
||||
String data = c_safe(msg.getValue("data"));
|
||||
|
||||
Lock lock(dbmutex);
|
||||
if (!conn)
|
||||
return false;
|
||||
|
||||
char buffer[2048];
|
||||
snprintf(buffer,sizeof(buffer),"SELECT credit,price,e164,context FROM register WHERE username='%s'",username);
|
||||
PGresult *respgsql = PQexec(conn,buffer);
|
||||
String c = "SELECT credit,price,e164,context FROM register WHERE username='" + username + "'";
|
||||
PGresult *respgsql = PQexec(conn,(const char *)c);
|
||||
if (!respgsql || PQresultStatus(respgsql) != PGRES_TUPLES_OK)
|
||||
{
|
||||
Debug(DebugFail,"Failed to query from database: %s",
|
||||
|
@ -132,52 +154,45 @@ bool RegistHandler::received(Message &msg)
|
|||
return false;
|
||||
}
|
||||
|
||||
const char *credit = PQgetvalue(respgsql,0,0);
|
||||
const char *price = PQgetvalue(respgsql,0,1);
|
||||
const char *prefix = PQgetvalue(respgsql,0,2);
|
||||
const char *context = PQgetvalue(respgsql,0,3);
|
||||
String price = PQgetvalue(respgsql,0,1);
|
||||
String prefix = PQgetvalue(respgsql,0,2);
|
||||
String context = PQgetvalue(respgsql,0,3);
|
||||
if (price.null())
|
||||
price = 0;
|
||||
if (context.null())
|
||||
context = "default";
|
||||
|
||||
snprintf(buffer,sizeof(buffer),"INSERT INTO routepaid (context,prefix,tehno,data,price) VALUES ('%s','%s','%s','%s',%s);",context,prefix,techno,data,price);
|
||||
c = "INSERT INTO routepaid (context,prefix,tehno,data,price,username) VALUES ('" + context + "','" + prefix + "','" + techno + "','" + data + "'," + price +",'" + username + "')";
|
||||
|
||||
PGresult *respgsql1 = PQexec(conn,buffer);
|
||||
PGresult *respgsql1 = PQexec(conn,(const char *)c);
|
||||
if (!respgsql1 || PQresultStatus(respgsql1) != PGRES_COMMAND_OK)
|
||||
Debug(DebugFail,"Failed to insert in database: %s",
|
||||
PQerrorMessage(conn));
|
||||
msg.retValue() = prefix;
|
||||
Debug(DebugInfo,"prefix in register este %s",prefix);
|
||||
return true;
|
||||
|
||||
};
|
||||
|
||||
bool UnRegistHandler::received(Message &msg)
|
||||
{
|
||||
const char *prefix = c_safe(msg.getValue("prefix"));
|
||||
Debug(DebugInfo,"prefix=%s",prefix);
|
||||
String username = c_safe(msg.getValue("username"));
|
||||
|
||||
Lock lock(dbmutex);
|
||||
if (!conn)
|
||||
return false;
|
||||
|
||||
char buffer[2048];
|
||||
snprintf(buffer,sizeof(buffer),"DELETE from routepaid WHERE prefix='%s'",prefix);
|
||||
PGresult *respgsql = PQexec(conn,buffer);
|
||||
if (!respgsql || PQresultStatus(respgsql) != PGRES_TUPLES_OK)
|
||||
String s = "DELETE from routepaid WHERE username='" + username + "'";
|
||||
PGresult *respgsql = PQexec(conn,(const char *)s);
|
||||
if (PQresultStatus(respgsql) != PGRES_COMMAND_OK)
|
||||
{
|
||||
Debug(DebugFail,"Failed to query from database: %s",
|
||||
PQerrorMessage(conn));
|
||||
return false;
|
||||
}
|
||||
if (PQntuples(respgsql) == 0) {
|
||||
Debug(DebugFail,"No user.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
};
|
||||
|
||||
bool RouteHandler::received(Message &msg)
|
||||
{
|
||||
char buffer[2048];
|
||||
unsigned long long tmr = Time::now();
|
||||
String called(msg.getValue("called"));
|
||||
if (called.null())
|
||||
|
@ -186,11 +201,12 @@ bool RouteHandler::received(Message &msg)
|
|||
if (!conn)
|
||||
return false;
|
||||
s_route_rq++;
|
||||
const char *context = c_safe(msg.getValue("context","default"));
|
||||
snprintf(buffer,sizeof(buffer),"SELECT tehno,data,length (prefix) as lll,price"
|
||||
" from routepaid where prefix= substring('%s',1,length(prefix))"
|
||||
" and context='%s' order by lll desc LIMIT 1",called.c_str(),context);
|
||||
PGresult *respgsql = PQexec(conn,buffer);
|
||||
String context = c_safe(msg.getValue("context","default"));
|
||||
String s = "SELECT tehno,data,length (prefix) as lll,price"
|
||||
" from routepaid where prefix= substring('" + called + "',1,length(prefix))"
|
||||
" and context='" + context + "' order by lll desc LIMIT 1";
|
||||
Debug(DebugInfo,"%s",s.c_str());
|
||||
PGresult *respgsql = PQexec(conn,(const char *)s);
|
||||
if (!respgsql || PQresultStatus(respgsql) != PGRES_TUPLES_OK)
|
||||
{
|
||||
Debug(DebugFail,"Failed to query from database: %s",
|
||||
|
@ -203,9 +219,9 @@ bool RouteHandler::received(Message &msg)
|
|||
s_route_no++;
|
||||
return false;
|
||||
}
|
||||
msg.retValue() = String(PQgetvalue(respgsql,0,0))+"/" + String(PQgetvalue(respgsql,0,1));
|
||||
msg.retValue() = String(PQgetvalue(respgsql,0,1));
|
||||
Debug(DebugInfo,"Routing call to '%s' in context '%s' using '%s' tehnology and data in %llu usec",
|
||||
called.c_str(),context,msg.retValue().c_str(),Time::now()-tmr);
|
||||
called.c_str(),context.c_str(),msg.retValue().c_str(),Time::now()-tmr);
|
||||
s_route_yes++;
|
||||
return true;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue