コード例 #1
0
ファイル: dns_internal.c プロジェクト: selecli/squid
void
idnsALookup(const char *name, IDNSCB * callback, void *data)
{
	unsigned int i;
	int nd = 0;
	idns_query *q;
	if (idnsCachedLookup(name, callback, data))
		return;
	q = cbdataAlloc(idns_query);
	q->tcp_socket = -1;
	q->id = idnsQueryID();

	for (i = 0; i < strlen(name); i++)
	{
		if (name[i] == '.')
		{
			nd++;
		}
	}

	if (Config.onoff.res_defnames && npc > 0 && name[strlen(name) - 1] != '.')
	{
		q->do_searchpath = 1;
	}
	else
	{
		q->do_searchpath = 0;
	}
	strcpy(q->orig, name);
	strcpy(q->name, q->orig);
	if (q->do_searchpath && nd < ndots)
	{
		q->domain = 0;
		strcat(q->name, ".");
		strcat(q->name, searchpath[q->domain].domain);
		debug(78, 3) ("idnsALookup: searchpath used for %s\n",
					  q->name);
	}
	q->sz = rfc1035BuildAQuery(q->name, q->buf, sizeof(q->buf), q->id,
							   &q->query);

	if (q->sz < 0)
	{
		/* problem with query data -- query not sent */
		callback(data, NULL, 0, "Internal error");
		cbdataFree(q);
		return;
	}
	debug(78, 3) ("idnsALookup: buf is %d bytes for %s, id = %#hx\n",
				  (int) q->sz, q->name, q->id);
	q->callback = callback;
	q->callback_data = data;
	cbdataLock(q->callback_data);
	q->start_t = current_time;
	idnsCacheQuery(q);
	idnsSendQuery(q);
}
コード例 #2
0
ファイル: dns_internal.c プロジェクト: UTSASRG/DoubleTake
void
idnsALookup(const char *name, IDNSCB * callback, void *data)
{
    idns_query *q = memAllocate(MEM_IDNS_QUERY);
    q->sz = sizeof(q->buf);
    q->id = rfc1035BuildAQuery(name, q->buf, &q->sz);
    debug(78, 3) ("idnsALookup: buf is %d bytes for %s, id = %#hx\n",
	(int) q->sz, name, q->id);
    q->callback = callback;
    q->callback_data = data;
    cbdataLock(q->callback_data);
    q->start_t = current_time;
    idnsSendQuery(q);
}
コード例 #3
0
ファイル: dns_internal.c プロジェクト: KimTaehee/HappyStream
static void
idnsGrokReply(const char *buf, size_t sz)
{
    int n;
    rfc1035_message *message = NULL;
    idns_query *q;
    n = rfc1035MessageUnpack(buf,
	sz,
	&message);
    if (message == NULL) {
	debug(78, 2) ("idnsGrokReply: Malformed DNS response\n");
	return;
    }
    debug(78, 3) ("idnsGrokReply: ID %#hx, %d answers\n", message->id, n);

    q = idnsFindQuery(message->id);

    if (q == NULL) {
	debug(78, 3) ("idnsGrokReply: Late response\n");
	rfc1035MessageDestroy(message);
	return;
    }
    if (rfc1035QueryCompare(&q->query, message->query) != 0) {
	debug(78, 3) ("idnsGrokReply: Query mismatch (%s != %s)\n", q->query.name, message->query->name);
	rfc1035MessageDestroy(message);
	return;
    }
    dlinkDelete(&q->lru, &lru_list);
    if (message->tc && q->tcp_socket == -1) {
	debug(78, 2) ("idnsGrokReply: Response for %s truncated. Retrying using TCP\n", message->query->name);
	rfc1035MessageDestroy(message);
	idnsRetryTcp(q);
	return;
    }
    idnsRcodeCount(n, q->attempt);
    q->error = NULL;
    if (n < 0) {
	debug(78, 3) ("idnsGrokReply: error %s (%d)\n", rfc1035_error_message, rfc1035_errno);
	q->error = rfc1035_error_message;
	q->rcode = -n;
	if (q->rcode == 2 && ++q->attempt < MAX_ATTEMPT) {
	    /*
	     * RCODE 2 is "Server failure - The name server was
	     * unable to process this query due to a problem with
	     * the name server."
	     */
	    rfc1035MessageDestroy(message);
	    q->start_t = current_time;
	    q->id = idnsQueryID();
	    rfc1035SetQueryID(q->buf, q->id);
	    idnsSendQuery(q);
	    return;
	}
	if (q->rcode == 3 && q->do_searchpath && q->attempt < MAX_ATTEMPT) {
	    strcpy(q->name, q->orig);
	    if (q->domain < npc) {
		strcat(q->name, ".");
		strcat(q->name, searchpath[q->domain].domain);
		debug(78, 3) ("idnsGrokReply: searchpath used for %s\n",
		    q->name);
		q->domain++;
	    } else {
		q->attempt++;
	    }
	    rfc1035MessageDestroy(message);
	    if (q->hash.key) {
		hash_remove_link(idns_lookup_hash, &q->hash);
		q->hash.key = NULL;
	    }
	    q->start_t = current_time;
	    q->id = idnsQueryID();
	    rfc1035SetQueryID(q->buf, q->id);
	    q->sz = rfc1035BuildAQuery(q->name, q->buf, sizeof(q->buf), q->id,
		&q->query);

	    idnsCacheQuery(q);
	    idnsSendQuery(q);
	    return;
	}
    }
    idnsCallback(q, message->answer, n, q->error);
    rfc1035MessageDestroy(message);

    idnsTcpCleanup(q);
    cbdataFree(q);
}