Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygencheck.c
Go to the documentation of this file.
00001 /* 00002 * check.c 00003 * - consistency checks 00004 */ 00005 /* 00006 * This file is 00007 * Copyright (C) 1997-1999 Ian Jackson <ian@davenant.greenend.org.uk> 00008 * 00009 * It is part of adns, which is 00010 * Copyright (C) 1997-2000 Ian Jackson <ian@davenant.greenend.org.uk> 00011 * Copyright (C) 1999-2000 Tony Finch <dot@dotat.at> 00012 * 00013 * This program is free software; you can redistribute it and/or modify 00014 * it under the terms of the GNU General Public License as published by 00015 * the Free Software Foundation; either version 2, or (at your option) 00016 * any later version. 00017 * 00018 * This program is distributed in the hope that it will be useful, 00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00021 * GNU General Public License for more details. 00022 * 00023 * You should have received a copy of the GNU General Public License 00024 * along with this program; if not, write to the Free Software Foundation, 00025 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00026 */ 00027 00028 #include "internal.h" 00029 00030 void adns_checkconsistency(adns_state ads, adns_query qu) { 00031 adns__consistency(ads,qu,cc_user); 00032 } 00033 00034 /* The original macro. Too gnuish for other compilers */ 00035 #if 0 00036 #define DLIST_CHECK(list, nodevar, part, body) \ 00037 if ((list).head) { \ 00038 assert(! (list).head->part back); \ 00039 for ((nodevar)= (list).head; (nodevar); (nodevar)= (nodevar)->part next) { \ 00040 assert((nodevar)->part next \ 00041 ? (nodevar) == (nodevar)->part next->part back \ 00042 : (nodevar) == (list).tail); \ 00043 body \ 00044 } \ 00045 } 00046 #endif /* 0 */ 00047 00048 #define DLIST_CHECK1(list, nodevar, body) \ 00049 if ((list).head) { \ 00050 assert(! (list).head->back); \ 00051 for ((nodevar)= (list).head; (nodevar); (nodevar)= (nodevar)->next) { \ 00052 assert((nodevar)->next \ 00053 ? (nodevar) == (nodevar)->next->back \ 00054 : (nodevar) == (list).tail); \ 00055 body \ 00056 } \ 00057 } 00058 00059 #define DLIST_CHECK2(list, nodevar, part, body) \ 00060 if ((list).head) { \ 00061 assert(! (list).head->part.back); \ 00062 for ((nodevar)= (list).head; (nodevar); (nodevar)= (nodevar)->part.next) { \ 00063 assert((nodevar)->part.next \ 00064 ? (nodevar) == (nodevar)->part.next->part.back \ 00065 : (nodevar) == (list).tail); \ 00066 body \ 00067 } \ 00068 } 00069 00070 #define DLIST_ASSERTON(node, nodevar, list, part) \ 00071 do { \ 00072 for ((nodevar)= (list).head; \ 00073 (nodevar) != (node); \ 00074 (nodevar)= (nodevar)->part next) { \ 00075 assert((nodevar)); \ 00076 } \ 00077 } while(0) 00078 00079 static void checkc_query_alloc(adns_state ads, adns_query qu) { 00080 allocnode *an; 00081 00082 00083 DLIST_CHECK1(qu->allocations, an, { 00084 }); 00085 } 00086 00087 static void checkc_query(adns_state ads, adns_query qu) { 00088 adns_query child; 00089 00090 assert(qu->udpnextserver < ads->nservers); 00091 assert(!(qu->udpsent & (~0UL << ads->nservers))); 00092 assert(qu->search_pos <= ads->nsearchlist); 00093 if (qu->parent) DLIST_ASSERTON(qu, child, qu->parent->children, siblings.); 00094 } 00095 00096 static void checkc_notcpbuf(adns_state ads) { 00097 assert(!ads->tcpsend.used); 00098 assert(!ads->tcprecv.used); 00099 assert(!ads->tcprecv_skip); 00100 } 00101 00102 static void checkc_global(adns_state ads) { 00103 int i; 00104 00105 assert(ads->udpsocket >= 0); 00106 00107 for (i=0; i<ads->nsortlist; i++) 00108 assert(!(ads->sortlist[i].base.s_addr & ~ads->sortlist[i].mask.s_addr)); 00109 00110 assert(ads->tcpserver >= 0 && ads->tcpserver < ads->nservers); 00111 00112 switch (ads->tcpstate) { 00113 case server_connecting: 00114 assert(ads->tcpsocket >= 0); 00115 checkc_notcpbuf(ads); 00116 break; 00117 case server_disconnected: 00118 case server_broken: 00119 assert(ads->tcpsocket == -1); 00120 checkc_notcpbuf(ads); 00121 break; 00122 case server_ok: 00123 assert(ads->tcpsocket >= 0); 00124 assert(ads->tcprecv_skip <= ads->tcprecv.used); 00125 break; 00126 default: 00127 assert(!"ads->tcpstate value"); 00128 } 00129 00130 assert(ads->searchlist || !ads->nsearchlist); 00131 } 00132 00133 static void checkc_queue_udpw(adns_state ads) { 00134 adns_query qu; 00135 00136 DLIST_CHECK1(ads->udpw, qu, { 00137 assert(qu->state==query_tosend); 00138 assert(qu->retries <= UDPMAXRETRIES); 00139 assert(qu->udpsent); 00140 assert(!qu->children.head && !qu->children.tail); 00141 checkc_query(ads,qu); 00142 checkc_query_alloc(ads,qu); 00143 }); 00144 } 00145 00146 static void checkc_queue_tcpw(adns_state ads) { 00147 adns_query qu; 00148 00149 DLIST_CHECK1(ads->tcpw, qu, { 00150 assert(qu->state==query_tcpw); 00151 assert(!qu->children.head && !qu->children.tail); 00152 assert(qu->retries <= ads->nservers+1); 00153 checkc_query(ads,qu); 00154 checkc_query_alloc(ads,qu); 00155 }); 00156 } 00157 00158 static void checkc_queue_childw(adns_state ads) { 00159 adns_query parent, child; 00160 00161 DLIST_CHECK1(ads->childw, parent, { 00162 assert(parent->state == query_childw); 00163 assert(parent->children.head); 00164 DLIST_CHECK2(parent->children, child, siblings, { 00165 assert(child->parent == parent); 00166 assert(child->state != query_done); 00167 }); 00168 checkc_query(ads,parent); 00169 checkc_query_alloc(ads,parent); 00170 }); 00171 } 00172 00173 static void checkc_queue_output(adns_state ads) { 00174 adns_query qu; 00175 00176 DLIST_CHECK1(ads->output, qu, { 00177 assert(qu->state == query_done); 00178 assert(!qu->children.head && !qu->children.tail); 00179 assert(!qu->parent); 00180 assert(!qu->allocations.head && !qu->allocations.tail); 00181 checkc_query(ads,qu); 00182 }); 00183 } 00184 00185 void adns__consistency(adns_state ads, adns_query qu, consistency_checks cc) { 00186 adns_query search; 00187 00188 switch (cc) { 00189 case cc_user: 00190 break; 00191 case cc_entex: 00192 if (!(ads->iflags & adns_if_checkc_entex)) return; 00193 break; 00194 case cc_freq: 00195 if ((ads->iflags & adns_if_checkc_freq) != adns_if_checkc_freq) return; 00196 break; 00197 default: 00198 abort(); 00199 } 00200 00201 checkc_global(ads); 00202 checkc_queue_udpw(ads); 00203 checkc_queue_tcpw(ads); 00204 checkc_queue_childw(ads); 00205 checkc_queue_output(ads); 00206 00207 if (qu) { 00208 switch (qu->state) { 00209 case query_tosend: 00210 DLIST_ASSERTON(qu, search, ads->udpw, ); 00211 break; 00212 case query_tcpw: 00213 DLIST_ASSERTON(qu, search, ads->tcpw, ); 00214 break; 00215 case query_childw: 00216 DLIST_ASSERTON(qu, search, ads->childw, ); 00217 break; 00218 case query_done: 00219 DLIST_ASSERTON(qu, search, ads->output, ); 00220 break; 00221 default: 00222 assert(!"specific query state"); 00223 } 00224 } 00225 } Generated on Sat May 26 2012 04:32:17 for ReactOS by
1.7.6.1
|