mirror of
https://github.com/shadowsocks/shadowsocks-libev.git
synced 2026-10-21 14:33:55 +00:00
remove res_search res_query
This commit is contained in:
@@ -67,9 +67,6 @@ typedef enum {
|
||||
RESPONSE_ADDRINFO,
|
||||
REQUEST_NAMEINFO,
|
||||
RESPONSE_NAMEINFO,
|
||||
REQUEST_RES_QUERY,
|
||||
REQUEST_RES_SEARCH,
|
||||
RESPONSE_RES,
|
||||
REQUEST_TERMINATE,
|
||||
RESPONSE_DIED
|
||||
} query_type_t;
|
||||
@@ -501,28 +498,6 @@ static int send_nameinfo_reply(int out_fd, unsigned id, int ret, const char *hos
|
||||
return send(out_fd, resp, resp->header.length, MSG_NOSIGNAL);
|
||||
}
|
||||
|
||||
static int send_res_reply(int out_fd, unsigned id, const unsigned char *answer, int ret, int _errno, int _h_errno) {
|
||||
res_response_t data[BUFSIZE/sizeof(res_response_t) + 1];
|
||||
res_response_t *resp = data;
|
||||
|
||||
assert(out_fd >= 0);
|
||||
|
||||
memset(data, 0, sizeof(data));
|
||||
resp->header.type = RESPONSE_RES;
|
||||
resp->header.id = id;
|
||||
resp->header.length = sizeof(res_response_t) + (ret < 0 ? 0 : ret);
|
||||
resp->ret = ret;
|
||||
resp->_errno = _errno;
|
||||
resp->_h_errno = _h_errno;
|
||||
|
||||
assert(sizeof(data) >= resp->header.length);
|
||||
|
||||
if (ret > 0)
|
||||
memcpy((uint8_t *)data + sizeof(res_response_t), answer, ret);
|
||||
|
||||
return send(out_fd, resp, resp->header.length, MSG_NOSIGNAL);
|
||||
}
|
||||
|
||||
static int handle_request(int out_fd, const packet_t *packet, size_t length) {
|
||||
const rheader_t *req;
|
||||
assert(out_fd >= 0);
|
||||
@@ -1032,28 +1007,6 @@ static int handle_response(asyncns_t *asyncns, const packet_t *packet, size_t le
|
||||
break;
|
||||
}
|
||||
|
||||
case RESPONSE_RES: {
|
||||
const res_response_t *res_resp = &packet->res_response;
|
||||
|
||||
assert(length >= sizeof(res_response_t));
|
||||
assert(q->type == REQUEST_RES_QUERY || q->type == REQUEST_RES_SEARCH);
|
||||
|
||||
q->ret = res_resp->ret;
|
||||
q->_errno = res_resp->_errno;
|
||||
q->_h_errno = res_resp->_h_errno;
|
||||
|
||||
if (res_resp->ret >= 0) {
|
||||
if (!(q->serv = malloc(res_resp->ret))) {
|
||||
q->ret = -1;
|
||||
q->_errno = ENOMEM;
|
||||
} else
|
||||
memcpy(q->serv, (const char *)resp + sizeof(res_response_t), res_resp->ret);
|
||||
}
|
||||
|
||||
complete_query(asyncns, q);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
;
|
||||
}
|
||||
@@ -1356,47 +1309,6 @@ fail:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
asyncns_query_t* asyncns_res_query(asyncns_t *asyncns, const char *dname, int class, int type) {
|
||||
return asyncns_res(asyncns, REQUEST_RES_QUERY, dname, class, type);
|
||||
}
|
||||
|
||||
asyncns_query_t* asyncns_res_search(asyncns_t *asyncns, const char *dname, int class, int type) {
|
||||
return asyncns_res(asyncns, REQUEST_RES_SEARCH, dname, class, type);
|
||||
}
|
||||
|
||||
int asyncns_res_done(asyncns_t *asyncns, asyncns_query_t* q, unsigned char **answer) {
|
||||
int ret;
|
||||
assert(asyncns);
|
||||
assert(q);
|
||||
assert(q->asyncns == asyncns);
|
||||
assert(q->type == REQUEST_RES_QUERY || q->type == REQUEST_RES_SEARCH);
|
||||
assert(answer);
|
||||
|
||||
if (asyncns->dead) {
|
||||
errno = ECHILD;
|
||||
return -ECHILD;
|
||||
}
|
||||
|
||||
if (!q->done) {
|
||||
errno = EAGAIN;
|
||||
return -EAGAIN;
|
||||
}
|
||||
|
||||
*answer = (unsigned char *)q->serv;
|
||||
q->serv = NULL;
|
||||
|
||||
ret = q->ret;
|
||||
|
||||
if (ret < 0) {
|
||||
errno = q->_errno;
|
||||
h_errno = q->_h_errno;
|
||||
}
|
||||
|
||||
asyncns_cancel(asyncns, q);
|
||||
|
||||
return ret < 0 ? -errno : ret;
|
||||
}
|
||||
|
||||
asyncns_query_t* asyncns_getnext(asyncns_t *asyncns) {
|
||||
assert(asyncns);
|
||||
return asyncns->done_head;
|
||||
|
||||
@@ -103,27 +103,6 @@ asyncns_query_t* asyncns_getnameinfo(asyncns_t *asyncns, const struct sockaddr *
|
||||
* returned. */
|
||||
int asyncns_getnameinfo_done(asyncns_t *asyncns, asyncns_query_t* q, char *ret_host, size_t hostlen, char *ret_serv, size_t servlen);
|
||||
|
||||
/** Issue a resolver query on the specified session. The arguments are
|
||||
* compatible with the ones of libc's res_query(3). The function returns a new
|
||||
* query object. When the query is completed you may retrieve the results using
|
||||
* asyncns_res_done(). */
|
||||
asyncns_query_t* asyncns_res_query(asyncns_t *asyncns, const char *dname, int class, int type);
|
||||
|
||||
/** Issue an resolver query on the specified session. The arguments are
|
||||
* compatible with the ones of libc's res_search(3). The function returns a new
|
||||
* query object. When the query is completed you may retrieve the results using
|
||||
* asyncns_res_done(). */
|
||||
asyncns_query_t* asyncns_res_search(asyncns_t *asyncns, const char *dname, int class, int type);
|
||||
|
||||
/** Retrieve the results of a preceding asyncns_res_query() or
|
||||
* asyncns_res_search call. The query object q is destroyed by this
|
||||
* call and may not be used any further. Returns a pointer to the
|
||||
* answer of the res_query call. If the query is not completed yet
|
||||
* -EAGAIN is returned, on failure -errno is returned, otherwise the
|
||||
* length of answer is returned. Make sure to free the answer is a
|
||||
* call to asyncns_freeanswer(). */
|
||||
int asyncns_res_done(asyncns_t *asyncns, asyncns_query_t* q, unsigned char **answer);
|
||||
|
||||
/** Return the next completed query object. If no query has been
|
||||
* completed yet, return NULL. Please note that you need to run
|
||||
* asyncns_wait() before this function will return sensible data. */
|
||||
|
||||
Reference in New Issue
Block a user