当前位置: 技术问答>linux和unix
请教一下这几个qmail函数的作用
来源: 互联网 发布时间:2016-02-13
本文导语: 这三个函数大概是要实现一个什么功能呢? #define DNS_SOFT -1 #define DNS_HARD -2 #define DNS_MEM -3 int dns_cname(sa) stralloc *sa; { int r; int loop; for (loop = 0;loop len) return loop; if (sa->s[sa->len - 1] == ']') return loop;...
这三个函数大概是要实现一个什么功能呢?
#define DNS_SOFT -1
#define DNS_HARD -2
#define DNS_MEM -3
int dns_cname(sa)
stralloc *sa;
{
int r;
int loop;
for (loop = 0;loop len) return loop;
if (sa->s[sa->len - 1] == ']') return loop;
if (sa->s[sa->len - 1] == '.') { --sa->len; continue; }
switch(resolve(sa,T_ANY))
{
case DNS_MEM: return DNS_MEM;
case DNS_SOFT: return DNS_SOFT;
case DNS_HARD: return loop;
default:
while ((r = findname(T_CNAME)) != 2)
{
if (r == DNS_SOFT) return DNS_SOFT;
if (r == 1)
{
if (!stralloc_copys(sa,name)) return DNS_MEM;
break;
}
}
if (r == 2) return loop;
}
}
return DNS_HARD; /* alias loop */
}
=======================================================================
static int dns_ipplus(ia,sa,pref)
ipalloc *ia;
stralloc *sa;
int pref;
{
int r;
struct ip_mx ix;
if (!stralloc_copy(&glue,sa)) return DNS_MEM;
if (!stralloc_0(&glue)) return DNS_MEM;
if (glue.s[0]) {
ix.pref = 0;
if (!glue.s[ip_scan(glue.s,&ix.ip)] || !glue.s[ip_scanbracket(glue.s,&ix.ip)])
{
if (!ipalloc_append(ia,&ix)) return DNS_MEM;
return 0;
}
}
switch(resolve(sa,T_A))
{
case DNS_MEM: return DNS_MEM;
case DNS_SOFT: return DNS_SOFT;
case DNS_HARD: return DNS_HARD;
}
while ((r = findip(T_A)) != 2)
{
ix.ip = ip;
ix.pref = pref;
if (r == DNS_SOFT) return DNS_SOFT;
if (r == 1)
if (!ipalloc_append(ia,&ix)) return DNS_MEM;
}
return 0;
}
=============================================================
这个函数好长啊~
int dns_mxip(ia,sa,random)
ipalloc *ia;
stralloc *sa;
unsigned long random;
{
int r;
struct mx { stralloc sa; unsigned short p; } *mx;
struct ip_mx ix;
int nummx;
int i;
int j;
int flagsoft;
if (!ipalloc_readyplus(ia,0)) return DNS_MEM;
ia->len = 0;
if (!stralloc_copy(&glue,sa)) return DNS_MEM;
if (!stralloc_0(&glue)) return DNS_MEM;
if (glue.s[0]) {
ix.pref = 0;
if (!glue.s[ip_scan(glue.s,&ix.ip)] || !glue.s[ip_scanbracket(glue.s,&ix.ip)])
{
if (!ipalloc_append(ia,&ix)) return DNS_MEM;
return 0;
}
}
switch(resolve(sa,T_MX))
{
case DNS_MEM: return DNS_MEM;
case DNS_SOFT: return DNS_SOFT;
case DNS_HARD: return dns_ip(ia,sa);
}
mx = (struct mx *) alloc(numanswers * sizeof(struct mx));
if (!mx) return DNS_MEM;
nummx = 0;
while ((r = findmx(T_MX)) != 2)
{
if (r == DNS_SOFT) { alloc_free(mx); return DNS_SOFT; }
if (r == 1)
{
mx[nummx].p = pref;
mx[nummx].sa.s = 0;
if (!stralloc_copys(&mx[nummx].sa,name))
{
while (nummx > 0) alloc_free(mx[--nummx].sa.s);
alloc_free(mx); return DNS_MEM;
}
++nummx;
}
}
if (!nummx) return dns_ip(ia,sa); /* e.g., CNAME -> A */
flagsoft = 0;
while (nummx > 0)
{
unsigned long numsame;
i = 0;
numsame = 1;
for (j = 1;j s[sa->len - 1] == '.') { --sa->len; continue; }
switch(resolve(sa,T_ANY)) /*把sa以ns_t_any格式查字典得出得值*/
{
case DNS_MEM: return DNS_MEM;
case DNS_SOFT: return DNS_SOFT;
case DNS_HARD: return loop;
default:
while ((r = findname(T_CNAME)) != 2) /*用findname函数查找ns_t_cname,需要看看具体的findname函数,ns_t_不是全局变量,就是枚举类型*/
{ /*如果返回为2退出*/
if (r == DNS_SOFT) return DNS_SOFT;
if (r == 1)
{
if (!stralloc_copys(sa,name)) return DNS_MEM; /*如果把name拷贝到sa中成功,就返回DNS_MEM否则就返回loop*/
break; /*name应该是全局变量,代码还真麻烦:)*/
}
}
if (r == 2) return loop;
}
}
return DNS_HARD; /* alias loop */ /*如果大于10次了即sa->s[sa->len-1]从0-sa->len都为'.'返回 DNS_HARD*/
}
=====================================================================
/*函数的大概整体意思是在stralloc *sa的指针里查找DNS的三种状态,如果不成功返回或为DNS_HARD返回loop,当findname返回1时候,把name返回给sa指针成功本报告DNS_MEM*/
#define DNS_SOFT -1
#define DNS_HARD -2
#define DNS_MEM -3
int dns_cname(sa)
stralloc *sa;
{
int r;
int loop;
for (loop = 0;loop len) return loop;
if (sa->s[sa->len - 1] == ']') return loop;
if (sa->s[sa->len - 1] == '.') { --sa->len; continue; }
switch(resolve(sa,T_ANY))
{
case DNS_MEM: return DNS_MEM;
case DNS_SOFT: return DNS_SOFT;
case DNS_HARD: return loop;
default:
while ((r = findname(T_CNAME)) != 2)
{
if (r == DNS_SOFT) return DNS_SOFT;
if (r == 1)
{
if (!stralloc_copys(sa,name)) return DNS_MEM;
break;
}
}
if (r == 2) return loop;
}
}
return DNS_HARD; /* alias loop */
}
=======================================================================
static int dns_ipplus(ia,sa,pref)
ipalloc *ia;
stralloc *sa;
int pref;
{
int r;
struct ip_mx ix;
if (!stralloc_copy(&glue,sa)) return DNS_MEM;
if (!stralloc_0(&glue)) return DNS_MEM;
if (glue.s[0]) {
ix.pref = 0;
if (!glue.s[ip_scan(glue.s,&ix.ip)] || !glue.s[ip_scanbracket(glue.s,&ix.ip)])
{
if (!ipalloc_append(ia,&ix)) return DNS_MEM;
return 0;
}
}
switch(resolve(sa,T_A))
{
case DNS_MEM: return DNS_MEM;
case DNS_SOFT: return DNS_SOFT;
case DNS_HARD: return DNS_HARD;
}
while ((r = findip(T_A)) != 2)
{
ix.ip = ip;
ix.pref = pref;
if (r == DNS_SOFT) return DNS_SOFT;
if (r == 1)
if (!ipalloc_append(ia,&ix)) return DNS_MEM;
}
return 0;
}
=============================================================
这个函数好长啊~
int dns_mxip(ia,sa,random)
ipalloc *ia;
stralloc *sa;
unsigned long random;
{
int r;
struct mx { stralloc sa; unsigned short p; } *mx;
struct ip_mx ix;
int nummx;
int i;
int j;
int flagsoft;
if (!ipalloc_readyplus(ia,0)) return DNS_MEM;
ia->len = 0;
if (!stralloc_copy(&glue,sa)) return DNS_MEM;
if (!stralloc_0(&glue)) return DNS_MEM;
if (glue.s[0]) {
ix.pref = 0;
if (!glue.s[ip_scan(glue.s,&ix.ip)] || !glue.s[ip_scanbracket(glue.s,&ix.ip)])
{
if (!ipalloc_append(ia,&ix)) return DNS_MEM;
return 0;
}
}
switch(resolve(sa,T_MX))
{
case DNS_MEM: return DNS_MEM;
case DNS_SOFT: return DNS_SOFT;
case DNS_HARD: return dns_ip(ia,sa);
}
mx = (struct mx *) alloc(numanswers * sizeof(struct mx));
if (!mx) return DNS_MEM;
nummx = 0;
while ((r = findmx(T_MX)) != 2)
{
if (r == DNS_SOFT) { alloc_free(mx); return DNS_SOFT; }
if (r == 1)
{
mx[nummx].p = pref;
mx[nummx].sa.s = 0;
if (!stralloc_copys(&mx[nummx].sa,name))
{
while (nummx > 0) alloc_free(mx[--nummx].sa.s);
alloc_free(mx); return DNS_MEM;
}
++nummx;
}
}
if (!nummx) return dns_ip(ia,sa); /* e.g., CNAME -> A */
flagsoft = 0;
while (nummx > 0)
{
unsigned long numsame;
i = 0;
numsame = 1;
for (j = 1;j s[sa->len - 1] == '.') { --sa->len; continue; }
switch(resolve(sa,T_ANY)) /*把sa以ns_t_any格式查字典得出得值*/
{
case DNS_MEM: return DNS_MEM;
case DNS_SOFT: return DNS_SOFT;
case DNS_HARD: return loop;
default:
while ((r = findname(T_CNAME)) != 2) /*用findname函数查找ns_t_cname,需要看看具体的findname函数,ns_t_不是全局变量,就是枚举类型*/
{ /*如果返回为2退出*/
if (r == DNS_SOFT) return DNS_SOFT;
if (r == 1)
{
if (!stralloc_copys(sa,name)) return DNS_MEM; /*如果把name拷贝到sa中成功,就返回DNS_MEM否则就返回loop*/
break; /*name应该是全局变量,代码还真麻烦:)*/
}
}
if (r == 2) return loop;
}
}
return DNS_HARD; /* alias loop */ /*如果大于10次了即sa->s[sa->len-1]从0-sa->len都为'.'返回 DNS_HARD*/
}
=====================================================================
/*函数的大概整体意思是在stralloc *sa的指针里查找DNS的三种状态,如果不成功返回或为DNS_HARD返回loop,当findname返回1时候,把name返回给sa指针成功本报告DNS_MEM*/