chiark / gitweb /
Add A record parsing.
authorian <ian>
Sun, 8 Nov 1998 12:59:41 +0000 (12:59 +0000)
committerian <ian>
Sun, 8 Nov 1998 12:59:41 +0000 (12:59 +0000)
src/adns.h
src/types.c

index ea4c680..29cf815 100644 (file)
@@ -105,6 +105,7 @@ typedef enum {
   adns_s_norecurse,
   adns_s_serverfaulty,
   adns_s_unknownreply,
+  adns_s_invaliddata,
   adns_s_max_tempfail= 99,
   adns_s_inconsistent, /* PTR gives domain whose A does not match */
   adns_s_cname, /* CNAME found where data eg A expected (not if _qf_loosecname) */
index f427dcd..b2b140d 100644 (file)
@@ -2,30 +2,54 @@
 
 #include "internal.h"
 
-#define TYRRSZ(rrtype,size,func) { (rrtype), (size), (func) }
+static adns_status rp_inaddr(adns_state ads, adns_query qu, int serv,
+                            const byte *dgram, int dglen, int cbyte, int max,
+                            void *store_r) {
+  struct in_addr *dr= store_r;
+  
+  if (max-cbyte != 4) return adns_s_invaliddata;
+  memcpy(dr,dgram+cbyte,4);
+  return adns_s_ok;
+}
+
+static adns_status rmf_null(adns_state ads, adns_query qu, void *data) { }
+
+#define TYPE_SF(size,func,free)    size, rp_#func, rmf_#free
+#define TYPE_SN(size,func)         size, rp_#func, rmf_null
+#define TYPESZ_M(member)           (sizeof(((adns_answer*)0)->rrs.member))
+#define TYPE_MF(member,parse)      TYPE_SF(TYPESZ_M(member),parse,member)
+#define TYPE_MN(member,parse)      TYPE_SN(TYPESZ_M(member),parse)
 
-#define TYRRSZ(sizememb) (sizeof(((adns_answer*)0)->rrs.sizememb))
+/* TYPE_<ms><nf>
+ *  ms is M  specify member name
+ *     or S  specify size explicitly
+ *  nf is F  full memory management, dependent on member name or specified func
+ *        N  no memory management required
+ */
 
 static const typeinfo typeinfos[] = {
   /* Must be in ascending order of rrtype ! */
+  /* rr type code     style     member     size  parser */
   
-  {    adns_r_a,               TYRR(inaddr),       rpf_inaddr           },
-  {    adns_r_ns_raw,          TYRR(str),          rpf_domain_raw       },
-  {    adns_r_cname,           TYRR(str),          rpf_domain_raw       },
-  {    adns_r_soa_raw,         TYRR(soa),          rpf_soa              },
-  {    adns_r_null,            0,                  rpf_null             },
-  {    adns_r_ptr_raw,         TYRR(str),          rpf_domain_raw       },
-  {    adns_r_hinfo,           TYRR(strpair),      rpf_hinfo            },
-  {    adns_r_mx_raw,          TYRR(intstr),       rpf_mx_raw           },
-  {    adns_r_txt,             TYRR(str),          rpf_txt              },
-  {    adns_r_rp_raw,          TYRR(strpair),      rpf_rp               },
-
-  {    adns_r_ns,              TYRR(dmaddr),       rpf_dmaddr           },
-  {    adns_r_ptr,             TYRR(str),          rpf_ptr              },
-  {    adns_r_mx,              TYRR(intdmaddr),    rpf_mx               },
-
-  {    adns_r_soa,             TYRR(soa),          rpf_soa              },
-  {    adns_r_rp,              TYRR(strpair),      rpf_rp               },
+  {  adns_r_a,        TYPE_MN(  inaddr,          inaddr       ) },
+#if 0 /*fixme*/                                               
+  {  adns_r_ns_raw,   TYPE_MF(  str,             domain_raw   ) },
+  {  adns_r_cname,    TYPE_MF(  str,             domain_raw   ) },
+  {  adns_r_soa_raw,  TYPE_MF(  soa,             soa          ) },
+  {  adns_r_null,     TYPE_SN(              0,   null         ) },
+  {  adns_r_ptr_raw,  TYPE_MF(  str,             domain_raw   ) },
+  {  adns_r_hinfo,    TYPE_MF(  strpair,         hinfo        ) },
+  {  adns_r_mx_raw,   TYPE_MF(  intstr,          mx_raw       ) },
+  {  adns_r_txt,      TYPE_MF(  str,             txt          ) },
+  {  adns_r_rp_raw,   TYPE_MF(  strpair,         rp           ) },
+                                                                
+  {  adns_r_ns,       TYPE_MF(  dmaddr,          dmaddr       ) },
+  {  adns_r_ptr,      TYPE_MF(  str,             ptr          ) },
+  {  adns_r_mx,       TYPE_MF(  intdmaddr,       mx           ) },
+                                                                
+  {  adns_r_soa,      TYPE_MF(  soa,             soa          ) },
+  {  adns_r_rp,       TYPE_MF(  strpair,         rp           ) },
+#endif
 };
 
 const typeinfo adns__findtype(adns_rrtype type) {