mirror of
https://github.com/moparisthebest/curl
synced 2024-12-22 08:08:50 -05:00
Avoid inline C99ism, and move c-ares routines for managing doubly-linked lists.
This commit is contained in:
parent
ccf083e26d
commit
b03abddb28
@ -6,7 +6,7 @@ ares_timeout.c ares_destroy.c ares_mkquery.c ares_version.c \
|
|||||||
ares_expand_name.c ares_parse_a_reply.c windows_port.c \
|
ares_expand_name.c ares_parse_a_reply.c windows_port.c \
|
||||||
ares_expand_string.c ares_parse_ptr_reply.c ares_parse_aaaa_reply.c \
|
ares_expand_string.c ares_parse_ptr_reply.c ares_parse_aaaa_reply.c \
|
||||||
ares_getnameinfo.c inet_net_pton.c bitncmp.c inet_ntop.c \
|
ares_getnameinfo.c inet_net_pton.c bitncmp.c inet_ntop.c \
|
||||||
ares_parse_ns_reply.c
|
ares_parse_ns_reply.c ares_llist.c
|
||||||
|
|
||||||
HHEADERS = ares.h ares_private.h setup.h ares_dns.h ares_version.h \
|
HHEADERS = ares.h ares_private.h setup.h ares_dns.h ares_version.h \
|
||||||
nameser.h inet_net_pton.h inet_ntop.h ares_ipv6.h bitncmp.h \
|
nameser.h inet_net_pton.h inet_ntop.h ares_ipv6.h bitncmp.h \
|
||||||
|
@ -60,6 +60,7 @@ OBJECTS = $(OBJ_DIR)\ares_fds.obj \
|
|||||||
$(OBJ_DIR)\ares_strerror.obj \
|
$(OBJ_DIR)\ares_strerror.obj \
|
||||||
$(OBJ_DIR)\ares_cancel.obj \
|
$(OBJ_DIR)\ares_cancel.obj \
|
||||||
$(OBJ_DIR)\ares_init.obj \
|
$(OBJ_DIR)\ares_init.obj \
|
||||||
|
$(OBJ_DIR)\ares_llist.obj \
|
||||||
$(OBJ_DIR)\ares_timeout.obj \
|
$(OBJ_DIR)\ares_timeout.obj \
|
||||||
$(OBJ_DIR)\ares_destroy.obj \
|
$(OBJ_DIR)\ares_destroy.obj \
|
||||||
$(OBJ_DIR)\ares_mkquery.obj \
|
$(OBJ_DIR)\ares_mkquery.obj \
|
||||||
@ -231,3 +232,6 @@ $(OBJ_DIR)\inet_ntop.obj: inet_ntop.c setup.h setup_once.h nameser.h \
|
|||||||
ares_ipv6.h inet_ntop.h
|
ares_ipv6.h inet_ntop.h
|
||||||
|
|
||||||
$(OBJ_DIR)\ares_getopt.obj: ares_getopt.c ares_getopt.h
|
$(OBJ_DIR)\ares_getopt.obj: ares_getopt.c ares_getopt.h
|
||||||
|
|
||||||
|
$(OBJ_DIR)\ares_llist.obj: ares_llist.c setup.h setup_once.h ares.h \
|
||||||
|
ares_private.h ares_llist.h
|
||||||
|
87
ares/ares_llist.c
Normal file
87
ares/ares_llist.c
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
/* Copyright 1998 by the Massachusetts Institute of Technology.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this
|
||||||
|
* software and its documentation for any purpose and without
|
||||||
|
* fee is hereby granted, provided that the above copyright
|
||||||
|
* notice appear in all copies and that both that copyright
|
||||||
|
* notice and this permission notice appear in supporting
|
||||||
|
* documentation, and that the name of M.I.T. not be used in
|
||||||
|
* advertising or publicity pertaining to distribution of the
|
||||||
|
* software without specific, written prior permission.
|
||||||
|
* M.I.T. makes no representations about the suitability of
|
||||||
|
* this software for any purpose. It is provided "as is"
|
||||||
|
* without express or implied warranty.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "setup.h"
|
||||||
|
|
||||||
|
#include "ares.h"
|
||||||
|
#include "ares_private.h"
|
||||||
|
|
||||||
|
/* Routines for managing doubly-linked circular linked lists with a
|
||||||
|
* dummy head.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Initialize a new head node */
|
||||||
|
void ares__init_list_head(struct list_node* head) {
|
||||||
|
head->prev = head;
|
||||||
|
head->next = head;
|
||||||
|
head->data = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Initialize a list node */
|
||||||
|
void ares__init_list_node(struct list_node* node, void* d) {
|
||||||
|
node->prev = NULL;
|
||||||
|
node->next = NULL;
|
||||||
|
node->data = d;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Returns true iff the given list is empty */
|
||||||
|
int ares__is_list_empty(struct list_node* head) {
|
||||||
|
return ((head->next == head) && (head->prev == head));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Inserts new_node before old_node */
|
||||||
|
void ares__insert_in_list(struct list_node* new_node,
|
||||||
|
struct list_node* old_node) {
|
||||||
|
new_node->next = old_node;
|
||||||
|
new_node->prev = old_node->prev;
|
||||||
|
old_node->prev->next = new_node;
|
||||||
|
old_node->prev = new_node;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Removes the node from the list it's in, if any */
|
||||||
|
void ares__remove_from_list(struct list_node* node) {
|
||||||
|
if (node->next != NULL) {
|
||||||
|
node->prev->next = node->next;
|
||||||
|
node->next->prev = node->prev;
|
||||||
|
node->prev = NULL;
|
||||||
|
node->next = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Swap the contents of two lists */
|
||||||
|
void ares__swap_lists(struct list_node* head_a,
|
||||||
|
struct list_node* head_b) {
|
||||||
|
int is_a_empty = ares__is_list_empty(head_a);
|
||||||
|
int is_b_empty = ares__is_list_empty(head_b);
|
||||||
|
struct list_node old_a = *head_a;
|
||||||
|
struct list_node old_b = *head_b;
|
||||||
|
|
||||||
|
if (is_a_empty) {
|
||||||
|
ares__init_list_head(head_b);
|
||||||
|
} else {
|
||||||
|
*head_b = old_a;
|
||||||
|
old_a.next->prev = head_b;
|
||||||
|
old_a.prev->next = head_b;
|
||||||
|
}
|
||||||
|
if (is_b_empty) {
|
||||||
|
ares__init_list_head(head_a);
|
||||||
|
} else {
|
||||||
|
*head_a = old_b;
|
||||||
|
old_b.next->prev = head_a;
|
||||||
|
old_b.prev->next = head_a;
|
||||||
|
}
|
||||||
|
}
|
43
ares/ares_llist.h
Normal file
43
ares/ares_llist.h
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
#ifndef __ARES_LLIST_H
|
||||||
|
#define __ARES_LLIST_H
|
||||||
|
|
||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
/* Copyright 1998 by the Massachusetts Institute of Technology.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this
|
||||||
|
* software and its documentation for any purpose and without
|
||||||
|
* fee is hereby granted, provided that the above copyright
|
||||||
|
* notice appear in all copies and that both that copyright
|
||||||
|
* notice and this permission notice appear in supporting
|
||||||
|
* documentation, and that the name of M.I.T. not be used in
|
||||||
|
* advertising or publicity pertaining to distribution of the
|
||||||
|
* software without specific, written prior permission.
|
||||||
|
* M.I.T. makes no representations about the suitability of
|
||||||
|
* this software for any purpose. It is provided "as is"
|
||||||
|
* without express or implied warranty.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/* Node definition for circular, doubly-linked list */
|
||||||
|
struct list_node {
|
||||||
|
struct list_node *prev;
|
||||||
|
struct list_node *next;
|
||||||
|
void* data;
|
||||||
|
};
|
||||||
|
|
||||||
|
void ares__init_list_head(struct list_node* head);
|
||||||
|
|
||||||
|
void ares__init_list_node(struct list_node* node, void* d);
|
||||||
|
|
||||||
|
int ares__is_list_empty(struct list_node* head);
|
||||||
|
|
||||||
|
void ares__insert_in_list(struct list_node* new_node,
|
||||||
|
struct list_node* old_node);
|
||||||
|
|
||||||
|
void ares__remove_from_list(struct list_node* node);
|
||||||
|
|
||||||
|
void ares__swap_lists(struct list_node* head_a,
|
||||||
|
struct list_node* head_b);
|
||||||
|
|
||||||
|
#endif /* __ARES_LLIST_H */
|
@ -83,16 +83,10 @@
|
|||||||
#define ARES_ID_KEY_LEN 31
|
#define ARES_ID_KEY_LEN 31
|
||||||
|
|
||||||
#include "ares_ipv6.h"
|
#include "ares_ipv6.h"
|
||||||
|
#include "ares_llist.h"
|
||||||
|
|
||||||
struct query;
|
struct query;
|
||||||
|
|
||||||
/* Node definition for circular, doubly-linked list */
|
|
||||||
struct list_node {
|
|
||||||
struct list_node *prev;
|
|
||||||
struct list_node *next;
|
|
||||||
void* data;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct send_request {
|
struct send_request {
|
||||||
/* Remaining data to send */
|
/* Remaining data to send */
|
||||||
const unsigned char *data;
|
const unsigned char *data;
|
||||||
@ -265,73 +259,6 @@ int ares__read_line(FILE *fp, char **buf, int *bufsize);
|
|||||||
void ares__free_query(struct query *query);
|
void ares__free_query(struct query *query);
|
||||||
short ares__generate_new_id(rc4_key* key);
|
short ares__generate_new_id(rc4_key* key);
|
||||||
|
|
||||||
|
|
||||||
/* Routines for managing doubly-linked circular linked lists with a
|
|
||||||
* dummy head.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Initialize a new head node */
|
|
||||||
static inline void ares__init_list_head(struct list_node* head) {
|
|
||||||
head->prev = head;
|
|
||||||
head->next = head;
|
|
||||||
head->data = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Initialize a list node */
|
|
||||||
static inline void ares__init_list_node(struct list_node* node, void* d) {
|
|
||||||
node->prev = NULL;
|
|
||||||
node->next = NULL;
|
|
||||||
node->data = d;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Returns true iff the given list is empty */
|
|
||||||
static inline int ares__is_list_empty(struct list_node* head) {
|
|
||||||
return ((head->next == head) && (head->prev == head));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Inserts new_node before old_node */
|
|
||||||
static inline void ares__insert_in_list(struct list_node* new_node,
|
|
||||||
struct list_node* old_node) {
|
|
||||||
new_node->next = old_node;
|
|
||||||
new_node->prev = old_node->prev;
|
|
||||||
old_node->prev->next = new_node;
|
|
||||||
old_node->prev = new_node;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Removes the node from the list it's in, if any */
|
|
||||||
static inline void ares__remove_from_list(struct list_node* node) {
|
|
||||||
if (node->next != NULL) {
|
|
||||||
node->prev->next = node->next;
|
|
||||||
node->next->prev = node->prev;
|
|
||||||
node->prev = NULL;
|
|
||||||
node->next = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Swap the contents of two lists */
|
|
||||||
static inline void ares__swap_lists(struct list_node* head_a,
|
|
||||||
struct list_node* head_b) {
|
|
||||||
int is_a_empty = ares__is_list_empty(head_a);
|
|
||||||
int is_b_empty = ares__is_list_empty(head_b);
|
|
||||||
struct list_node old_a = *head_a;
|
|
||||||
struct list_node old_b = *head_b;
|
|
||||||
|
|
||||||
if (is_a_empty) {
|
|
||||||
ares__init_list_head(head_b);
|
|
||||||
} else {
|
|
||||||
*head_b = old_a;
|
|
||||||
old_a.next->prev = head_b;
|
|
||||||
old_a.prev->next = head_b;
|
|
||||||
}
|
|
||||||
if (is_b_empty) {
|
|
||||||
ares__init_list_head(head_a);
|
|
||||||
} else {
|
|
||||||
*head_a = old_b;
|
|
||||||
old_b.next->prev = head_a;
|
|
||||||
old_b.prev->next = head_a;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#define ARES_SWAP_BYTE(a,b) \
|
#define ARES_SWAP_BYTE(a,b) \
|
||||||
{ unsigned char swapByte = *(a); *(a) = *(b); *(b) = swapByte; }
|
{ unsigned char swapByte = *(a); *(a) = *(b); *(b) = swapByte; }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user