Preliminary registration support in SIP.
Added a NAPTR resolver that will become the ENUM router module. git-svn-id: http://voip.null.ro/svn/yate@234 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
parent
a15fd51c3d
commit
8c70574792
|
@ -0,0 +1,87 @@
|
|||
#error Not yet ready!
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/nameser.h>
|
||||
#include <resolv.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
unsigned char buf[2048];
|
||||
|
||||
int dn_string(const unsigned char* end, const unsigned char* src, char *dest, int maxlen)
|
||||
{
|
||||
int n = src[0];
|
||||
maxlen--;
|
||||
if (maxlen > n)
|
||||
maxlen = n;
|
||||
if (dest && (maxlen > 0)) {
|
||||
while ((maxlen-- > 0) && (src < end))
|
||||
*dest++ = *++src;
|
||||
*dest = 0;
|
||||
}
|
||||
return n+1;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int r,i,q,a;
|
||||
unsigned char *p, *e;
|
||||
r = res_init();
|
||||
printf("res_init %d\n",r);
|
||||
r = res_query("0.0.1.2.4.0.0.0.9.9.2.8.8.e164.org",ns_c_in,ns_t_naptr,
|
||||
buf,sizeof(buf));
|
||||
printf("res_query %d\n",r);
|
||||
if ((r < 0) || (r > sizeof(buf)))
|
||||
return 1;
|
||||
p = buf+NS_QFIXEDSZ;
|
||||
NS_GET16(q,p);
|
||||
NS_GET16(a,p);
|
||||
printf("questions: %d, answers: %d\n",q,a);
|
||||
p = buf + NS_HFIXEDSZ;
|
||||
e = buf + r;
|
||||
for (; q > 0; q--) {
|
||||
int n = dn_skipname(p,e);
|
||||
if (n < 0)
|
||||
return 1;
|
||||
p += (n + NS_QFIXEDSZ);
|
||||
}
|
||||
printf("skipped questions\n");
|
||||
for (; a > 0; a--) {
|
||||
int ty,cl,sz;
|
||||
long int tt;
|
||||
char name[NS_MAXLABEL+1];
|
||||
unsigned char* l;
|
||||
int n = dn_expand(buf,e,p,name,sizeof(name));
|
||||
if ((n <= 0) || (n > NS_MAXLABEL))
|
||||
return 1;
|
||||
buf[n] = 0;
|
||||
p += n;
|
||||
NS_GET16(ty,p);
|
||||
NS_GET16(cl,p);
|
||||
NS_GET32(tt,p);
|
||||
NS_GET16(sz,p);
|
||||
printf("found '%s' type %d size %d\n",name,ty,sz);
|
||||
l = p;
|
||||
p += sz;
|
||||
if (ty == ns_t_naptr) {
|
||||
int or,pr;
|
||||
char fla[NS_MAXLABEL+1];
|
||||
char ser[NS_MAXLABEL+1];
|
||||
char reg[NS_MAXLABEL+1];
|
||||
char rep[NS_MAXLABEL+1];
|
||||
NS_GET16(or,l);
|
||||
NS_GET16(pr,l);
|
||||
n = dn_string(e,l,fla,sizeof(fla));
|
||||
l += n;
|
||||
n = dn_string(e,l,ser,sizeof(ser));
|
||||
l += n;
|
||||
n = dn_string(e,l,reg,sizeof(reg));
|
||||
l += n;
|
||||
n = dn_expand(buf,e,l,rep,sizeof(rep));
|
||||
l += n;
|
||||
printf("order=%d pref=%d flags='%s' serv='%s' regexp='%s' replace='%s'\n",
|
||||
or,pr,fla,ser,reg,rep);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -141,6 +141,7 @@ public:
|
|||
void run(void);
|
||||
bool incoming(SIPEvent* e, SIPTransaction* t);
|
||||
void invite(SIPEvent* e, SIPTransaction* t);
|
||||
void regreq(SIPEvent* e, SIPTransaction* t);
|
||||
bool buildParty(SIPMessage* message, const char* host = 0, int port = 0);
|
||||
inline YateSIPEngine* engine() const
|
||||
{ return m_engine; }
|
||||
|
@ -385,6 +386,8 @@ YateSIPEngine::YateSIPEngine(YateSIPEndPoint* ep)
|
|||
addAllowed("INVITE");
|
||||
addAllowed("BYE");
|
||||
addAllowed("CANCEL");
|
||||
if (s_cfg.getBoolValue("general","registrar"))
|
||||
addAllowed("REGISTER");
|
||||
}
|
||||
|
||||
bool YateSIPEngine::buildParty(SIPMessage* message)
|
||||
|
@ -570,6 +573,8 @@ bool YateSIPEndPoint::incoming(SIPEvent* e, SIPTransaction* t)
|
|||
else
|
||||
t->setResponse(481,"Call/Transaction Does Not Exist");
|
||||
}
|
||||
else if (t->getMethod() == "REGISTER")
|
||||
regreq(e,t);
|
||||
else
|
||||
return false;
|
||||
return true;
|
||||
|
@ -639,6 +644,40 @@ void YateSIPEndPoint::invite(SIPEvent* e, SIPTransaction* t)
|
|||
}
|
||||
}
|
||||
|
||||
void YateSIPEndPoint::regreq(SIPEvent* e, SIPTransaction* t)
|
||||
{
|
||||
if (Engine::exiting()) {
|
||||
Debug(DebugWarn,"Dropping request, engine is exiting");
|
||||
e->getTransaction()->setResponse(500, "Server Shutting Down");
|
||||
return;
|
||||
}
|
||||
const HeaderLine* hl = e->getMessage()->getHeader("To");
|
||||
if (!hl) {
|
||||
e->getTransaction()->setResponse(400, "Bad Request");
|
||||
return;
|
||||
}
|
||||
URI addr(*hl);
|
||||
Message *m = new Message("user.register");
|
||||
m->addParam("username",addr.getUser());
|
||||
m->addParam("techno","sip");
|
||||
m->addParam("data","sip/" + addr);
|
||||
bool dereg = false;
|
||||
hl = e->getMessage()->getHeader("Expires");
|
||||
if (hl) {
|
||||
m->addParam("expires",*hl);
|
||||
if (*hl == "0") {
|
||||
*m = "user.unregister";
|
||||
dereg = true;
|
||||
}
|
||||
}
|
||||
// Always OK deregistration attempts
|
||||
if (Engine::dispatch(m) || dereg)
|
||||
e->getTransaction()->setResponse(200, "OK");
|
||||
else
|
||||
e->getTransaction()->setResponse(404, "Not Found");
|
||||
m->destruct();
|
||||
}
|
||||
|
||||
static Mutex s_route;
|
||||
int SipMsgThread::s_count = 0;
|
||||
int SipMsgThread::s_routed = 0;
|
||||
|
|
Loading…
Reference in New Issue