forked from Mirrors/freeswitch
60434decf5
mod_enum can be used as a dialplan app, an api call from the console or as a dialplan interface. Dialplan Interface: put enum as the dialplan parameter in an endpoint module i.e. instead of "XML" set it to "enum" or "enum,XML" for fall through. Dialplan App: This example will do a lookup and set the a variable that is the proper dialstring to call all of the possible routes in order of preference according to the lookup and the order of the routes in the enum.conf section. <extension name="tollfree"> <condition field="destination_number" expression="^(18(0{2}|8{2}|7{2}|6{2})\d{7})$"> <action application="enum" data="$1"/> <action application="bridge" data="${enum_auto_route}"/> </condition> </extension> You can also pick an alrernate root: <action application="enum" data="$1 myroot.org"/> API command: at the console you can say: enum <number> [<root>] The root always defaults to the one in the enum.conf section. git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3494 d0543943-73ff-0310-b7d9-9358b9ac24b2
92 lines
2.9 KiB
C
92 lines
2.9 KiB
C
/* $Id: udns_rr_mx.c,v 1.13 2005/04/20 06:44:34 mjt Exp $
|
|
parse/query MX IN records
|
|
|
|
Copyright (C) 2005 Michael Tokarev <mjt@corpit.ru>
|
|
This file is part of UDNS library, an async DNS stub resolver.
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Lesser General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
This library 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
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
License along with this library, in file named COPYING.LGPL; if not,
|
|
write to the Free Software Foundation, Inc., 59 Temple Place,
|
|
Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <assert.h>
|
|
#include "udns.h"
|
|
|
|
int
|
|
dns_parse_mx(dnscc_t *qdn, dnscc_t *pkt, dnscc_t *cur, dnscc_t *end,
|
|
void **result) {
|
|
struct dns_rr_mx *ret;
|
|
struct dns_parse p;
|
|
struct dns_rr rr;
|
|
int r, l;
|
|
char *sp;
|
|
dnsc_t mx[DNS_MAXDN];
|
|
|
|
assert(dns_get16(cur+2) == DNS_C_IN && dns_get16(cur+0) == DNS_T_MX);
|
|
|
|
/* first, validate the answer and count size of the result */
|
|
l = 0;
|
|
dns_initparse(&p, qdn, pkt, cur, end);
|
|
while((r = dns_nextrr(&p, &rr)) > 0) {
|
|
cur = rr.dnsrr_dptr + 2;
|
|
r = dns_getdn(pkt, &cur, end, mx, sizeof(mx));
|
|
if (r <= 0 || cur != rr.dnsrr_dend)
|
|
return DNS_E_PROTOCOL;
|
|
l += dns_dntop_size(mx);
|
|
}
|
|
if (r < 0)
|
|
return DNS_E_PROTOCOL;
|
|
if (!p.dnsp_nrr)
|
|
return DNS_E_NODATA;
|
|
|
|
/* next, allocate and set up result */
|
|
l += dns_stdrr_size(&p);
|
|
ret = malloc(sizeof(*ret) + sizeof(struct dns_mx) * p.dnsp_nrr + l);
|
|
if (!ret)
|
|
return DNS_E_NOMEM;
|
|
ret->dnsmx_nrr = p.dnsp_nrr;
|
|
ret->dnsmx_mx = (struct dns_mx *)(ret+1);
|
|
|
|
/* and 3rd, fill in result, finally */
|
|
sp = (char*)(ret->dnsmx_mx + p.dnsp_nrr);
|
|
for (dns_rewind(&p, qdn), r = 0; dns_nextrr(&p, &rr); ++r) {
|
|
ret->dnsmx_mx[r].name = sp;
|
|
cur = rr.dnsrr_dptr;
|
|
ret->dnsmx_mx[r].priority = dns_get16(cur);
|
|
cur += 2;
|
|
dns_getdn(pkt, &cur, end, mx, sizeof(mx));
|
|
sp += dns_dntop(mx, sp, DNS_MAXNAME);
|
|
}
|
|
dns_stdrr_finish((struct dns_rr_null *)ret, sp, &p);
|
|
*result = ret;
|
|
return 0;
|
|
}
|
|
|
|
struct dns_query *
|
|
dns_submit_mx(struct dns_ctx *ctx, const char *name, int flags,
|
|
dns_query_mx_fn *cbck, void *data) {
|
|
return
|
|
dns_submit_p(ctx, name, DNS_C_IN, DNS_T_MX, flags,
|
|
dns_parse_mx, (dns_query_fn *)cbck, data);
|
|
}
|
|
|
|
struct dns_rr_mx *
|
|
dns_resolve_mx(struct dns_ctx *ctx, const char *name, int flags) {
|
|
return (struct dns_rr_mx *)
|
|
dns_resolve_p(ctx, name, DNS_C_IN, DNS_T_MX, flags, dns_parse_mx);
|
|
}
|