modules/df/defs.c

/* [<][>]
[^][v][top][bottom][index][help] */

FUNCTIONS

This source file includes following functions.
  1. DF_get_filter_names
  2. DF_get_class_names
  3. DF_get_class_aliases
  4. DF_get_class_index
  5. DF_get_class_name
  6. DF_get_class_code
  7. DF_get_class_dbase_code
  8. DF_get_class_sql_table
  9. DF_get_attribute_aliases
  10. DF_get_attribute_name
  11. DF_get_attribute_code
  12. DF_get_attribute_names
  13. DF_get_attribute_index
  14. DF_get_class_template
  15. DF_get_class_template_v
  16. DF_get_server_query
  17. DF_get_server_queries
  18. DF_get_update_query
  19. DF_get_update_query_type
  20. DF_get_insert_query
  21. DF_get_insert_query_type
  22. DF_get_select_query
  23. DF_get_select_query_type
  24. DF_get_dummy_query
  25. DF_get_dummy_query_type
  26. DF_get_attribute_desc
  27. DF_get_attribute_frmt
  28. DF_attributes_to_string
  29. DF_attribute_code2type
  30. DF_attribute_name2type
  31. DF_class_code2type
  32. DF_class_name2type
  33. DF_attrcode_has_radix_lookup

   1 /***************************************
   2   $Revision: 1.15 $
   3 
   4   Definitions module (df)
   5 
   6   Status: NOT REVUED, NOT TESTED
   7 
   8   ******************/ /******************
   9   Filename            : defs.c
  10   Authors             : ottrey@ripe.net
  11                         marek@ripe.net
  12   ******************/ /******************
  13   Copyright (c) 1999                              RIPE NCC
  14  
  15   All Rights Reserved
  16   
  17   Permission to use, copy, modify, and distribute this software and its
  18   documentation for any purpose and without fee is hereby granted,
  19   provided that the above copyright notice appear in all copies and that
  20   both that copyright notice and this permission notice appear in
  21   supporting documentation, and that the name of the author not be
  22   used in advertising or publicity pertaining to distribution of the
  23   software without specific, written prior permission.
  24   
  25   THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  26   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
  27   AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
  28   DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
  29   AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  30   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  31   ***************************************/
  32 #include <stdio.h>
  33 #include <stdlib.h>
  34 #include <stdarg.h>
  35 #include <strings.h>
  36 #include <glib.h>
  37 
  38 /*+ String sizes +*/
  39 #define STR_S   63
  40 #define STR_M   255
  41 #define STR_L   1023
  42 #define STR_XL  4095
  43 #define STR_XXL 16383
  44 
  45 #define  DEFS_IMPL
  46 #include "defs.h"
  47 #include "memwrap.h"
  48 
  49 #include "DF_class_names.def"
  50 #include "DF_class_codes.def"
  51 #include "DF_class_aliases.def"
  52 #include "DF_class_aliases_map.def"
  53 #include "DF_class_dbase_code_map.def"
  54 #include "DF_class_templates.def"
  55 #include "DF_class_templates_v.def"
  56 
  57 #include "DF_attribute_names.def"
  58 #include "DF_attribute_codes.def"
  59 #include "DF_attribute_aliases.def"
  60 #include "DF_attribute_aliases_map.def"
  61 
  62 #include "UD_queries.def"
  63 
  64 
  65 
  66 /* getsubopt requires a vector of pointers to a list of possible options
  67    It's used for parsing the source list.
  68    Therefore a quick 
  69  XXX  !!!!
  70    hack: hardcode it. Will be initialised from the Sources array 
  71    once the config module is defined
  72 */
  73 
  74 
  75 
  76 char * const  Server_query[] = {
  77   "The sources are ...\n",
  78   "The version is ...\n",
  79   NULL
  80 }; /* Server_query */
  81 
  82 char * const  Server_queries[] = {
  83   "sources",
  84   "version",
  85   NULL
  86 }; /* Server_queries */
  87 
  88 /* XXX this also should be generated from XML... */
  89 char * const  Filter_names[] = {
  90   "aut-num",
  91   "domain",
  92   "inet6num",
  93   "inetnum",
  94   "inet-rtr",
  95   "key-cert",
  96   "limerick",
  97   "mntner",
  98   "route",
  99   "origin",
 100   "as-set",
 101   "route-set",   
 102   "members",
 103   "peering-set",
 104   "filter-set",
 105   "rtr-set",
 106   NULL
 107 }; /* Filter_names */
 108 
 109 char * const *DF_get_filter_names(void) {
     /* [<][>][^][v][top][bottom][index][help] */
 110   return Filter_names;
 111 } /* DF_get_filter_names() */
 112 
 113 char * const *DF_get_class_names(void) {
     /* [<][>][^][v][top][bottom][index][help] */
 114   return Class_names;
 115 } /* DF_get_class_names() */
 116 
 117 char * const *DF_get_class_aliases(void) {
     /* [<][>][^][v][top][bottom][index][help] */
 118   return Class_aliases;
 119 } /* DF_get_class_aliases() */
 120 
 121 int DF_get_class_index(int alias_index) {
     /* [<][>][^][v][top][bottom][index][help] */
 122   return Class_aliases_map[alias_index];
 123 } /* DF_get_class_index() */
 124 
 125 char * const DF_get_class_name(int alias_index) {
     /* [<][>][^][v][top][bottom][index][help] */
 126   return Class_names[Class_aliases_map[alias_index]];
 127 } /* DF_get_class_name() */
 128 
 129 char * const DF_get_class_code(C_Type_t index) {
     /* [<][>][^][v][top][bottom][index][help] */
 130   if( index == -1 ) {
 131     return "*";
 132   }
 133   else {
 134     return Class_codes[index];
 135   }
 136 } /* DF_get_class_code() */
 137 
 138 int DF_get_class_dbase_code(int class_index) {
     /* [<][>][^][v][top][bottom][index][help] */
 139   return Class_dbase_code_map[class_index];
 140 } /* DF_get_class_dbase_code() */
 141 
 142 /* Main tables names for object types */
 143 char * const Type2main[] = {
 144 "as_block",
 145 "as_set",
 146 "aut_num",
 147 "domain",
 148 "inet_rtr",
 149 "inet6num",
 150 "inetnum",
 151 "key_cert",
 152 "limerick",
 153 "mntner",
 154 "person_role", /*pn*/
 155 "person_role", /*ro*/
 156 "route",
 157 "route_set",
 158 "filter_set",
 159 "peering_set",
 160 "rtr_set",
 161 NULL
 162 };
 163 
 164 char * const DF_get_class_sql_table(C_Type_t index) {
     /* [<][>][^][v][top][bottom][index][help] */
 165  return Type2main[index];
 166 } /* DF_get_class_sql_table() */ 
 167 
 168 
 169 
 170 char * const *DF_get_attribute_aliases(void) {
     /* [<][>][^][v][top][bottom][index][help] */
 171   return Attribute_aliases;
 172 } /* DF_get_attribute_aliases() */
 173 
 174 const char *DF_get_attribute_name(A_Type_t index) {
     /* [<][>][^][v][top][bottom][index][help] */
 175   return Attribute_names[index];
 176 } /* DF_get_attribute_name() */
 177 
 178 const char *DF_get_attribute_code(A_Type_t index) {
     /* [<][>][^][v][top][bottom][index][help] */
 179   return Attribute_codes[index];
 180 } /* DF_get_attribute_code() */
 181 
 182 char * const *DF_get_attribute_names(void) {
     /* [<][>][^][v][top][bottom][index][help] */
 183   return Attribute_names;
 184 } /* DF_get_attribute_names() */
 185 
 186 int DF_get_attribute_index(int alias_index) {
     /* [<][>][^][v][top][bottom][index][help] */
 187   return Attribute_aliases_map[alias_index];
 188 } /* DF_get_attribute_index() */
 189 
 190 const char *DF_get_class_template(C_Type_t index) {
     /* [<][>][^][v][top][bottom][index][help] */
 191   return Templates[index];
 192 } /* DF_get_class_template() */
 193 
 194 const char *DF_get_class_template_v(C_Type_t index) {
     /* [<][>][^][v][top][bottom][index][help] */
 195   return Templates_v[index];
 196 } /* DF_get_class_template_v() */
 197 
 198 const char *DF_get_server_query(int index) {
     /* [<][>][^][v][top][bottom][index][help] */
 199     return Server_query[index];
 200 } /* DF_get_server_query() */
 201 
 202 char * const *DF_get_server_queries(void) {
     /* [<][>][^][v][top][bottom][index][help] */
 203   return Server_queries;
 204 } /* DF_get_server_queries() */
 205 
 206 const char *DF_get_update_query(A_Type_t index){
     /* [<][>][^][v][top][bottom][index][help] */
 207   return Update[index].qry;
 208 } /* DF_get_update_query() */
 209 
 210 UD_qtype DF_get_update_query_type(A_Type_t index){
     /* [<][>][^][v][top][bottom][index][help] */
 211   return Update[index].qtype;
 212 } /* DF_get_update_query_type() */
 213 
 214 const char *DF_get_insert_query(A_Type_t index){
     /* [<][>][^][v][top][bottom][index][help] */
 215   return Insert[index].qry;
 216 } /* DF_get_insert_query() */
 217   
 218 UD_qtype DF_get_insert_query_type(A_Type_t index){
     /* [<][>][^][v][top][bottom][index][help] */
 219   return Insert[index].qtype;
 220 } /* DF_get_insert_query_type() */
 221     
 222 const char *DF_get_select_query(A_Type_t index){
     /* [<][>][^][v][top][bottom][index][help] */
 223   return Select[index].qry;
 224 } /* DF_get_select_query() */
 225   
 226 UD_qtype DF_get_select_query_type(A_Type_t index){
     /* [<][>][^][v][top][bottom][index][help] */
 227   return Select[index].qtype;
 228 } /* DF_get_select_query_type() */
 229         
 230 const char *DF_get_dummy_query(A_Type_t index){
     /* [<][>][^][v][top][bottom][index][help] */
 231   return Dummy[index].qry;
 232 } /* DF_get_dummy_query() */
 233   
 234 UD_qtype DF_get_dummy_query_type(A_Type_t index){
     /* [<][>][^][v][top][bottom][index][help] */
 235   return Dummy[index].qtype;
 236 } /* DF_get_dummy_query_type() */
 237 
 238 
 239 
 240 const char *DF_get_attribute_desc(A_Type_t index) {
     /* [<][>][^][v][top][bottom][index][help] */
 241 /*
 242   return (char *)Attributes_details[attr_index][0];
 243 */
 244   return NULL;
 245 } /* DF_get_attribute_desc() */
 246 
 247 const char *DF_get_attribute_frmt(A_Type_t index) {
     /* [<][>][^][v][top][bottom][index][help] */
 248 /*
 249   return (char *)Attributes_details[attr_index][1];
 250 */
 251   return NULL;
 252 } /* DF_get_attribute_frmt() */
 253 
 254 /* DF_attributes_to_string() */
 255 /*++++++++++++++++++++++++++++++++++++++
 256   Returns a string of all the attributes.  Only there for debugging and tracing purposes.
 257 
 258   int offset The offset (Ie short or long name).
 259 
 260   More:
 261   +html+ <PRE>
 262   Authors:
 263         ottrey
 264 
 265   +html+ </PRE><DL COMPACT>
 266   +html+ <DT>Online References:
 267   +html+ <DD><UL>
 268   +html+ </UL></DL>
 269 
 270   ++++++++++++++++++++++++++++++++++++++*/
 271 char *DF_attributes_to_string(void) {
     /* [<][>][^][v][top][bottom][index][help] */
 272   int i;
 273   char *str;
 274   char str_buffer[4096];
 275   int str_len;
 276 
 277   strcpy(str_buffer, "{\"");
 278   for (i=0; Attribute_names[i] != NULL; i++) {
 279     strcat(str_buffer, Attribute_names[i]);
 280     strcat(str_buffer, "\", \"");
 281   }
 282   str_len = strlen(str_buffer);
 283   str_buffer[str_len-3] = '}';
 284   str_buffer[str_len-2] = '\0';
 285   str_len--;
 286 
 287   /* str = (char *)calloc(1, str_len); */
 288   dieif( wr_malloc((void **)&str, str_len ) != UT_OK);  
 289   strcpy(str, str_buffer);
 290 
 291   return str;
 292 
 293 } /* DF_attributes_to_string() */
 294 
 295 /* XXX This could be done MUCH more efficiently (with a hash) */
 296 A_Type_t DF_attribute_code2type(const gchar *token) {
     /* [<][>][^][v][top][bottom][index][help] */
 297   A_Type_t result=-1;
 298 
 299   int i;
 300   for (i=0; Attribute_aliases[i] != NULL; i++) {
 301     if (strcmp(Attribute_aliases[i], token) == 0) {
 302       result = Attribute_aliases_map[i];
 303       break;
 304     }
 305   }
 306 
 307   return result;
 308 } /* DF_attribute_code2type() */
 309 
 310 /* XXX This could be done MUCH more efficiently (with a hash) */
 311 A_Type_t DF_attribute_name2type(const gchar *token) {
     /* [<][>][^][v][top][bottom][index][help] */
 312   A_Type_t result=-1;
 313 
 314   int i;
 315   for (i=0; Attribute_aliases[i] != NULL; i++) {
 316     if (strcmp(Attribute_aliases[i], token) == 0) {
 317       result = Attribute_aliases_map[i];
 318       break;
 319     }
 320   }
 321 
 322   return result;
 323 } /* DF_attribute_name2type() */
 324 
 325 /* XXX This could be done MUCH more efficiently (with a hash) */
 326 C_Type_t DF_class_code2type(const gchar *token) {
     /* [<][>][^][v][top][bottom][index][help] */
 327   C_Type_t result=-1;
 328 
 329   int i;
 330   for (i=0; Class_aliases[i] != NULL; i++) {
 331     if (strcmp(Class_aliases[i], token) == 0) {
 332       result = Class_aliases_map[i];
 333       break;
 334     }
 335   }
 336 
 337   return result;
 338 } /* DF_class_code2type() */
 339 
 340 /* XXX This could be done MUCH more efficiently (with a hash) */
 341 C_Type_t DF_class_name2type(const gchar *token) {
     /* [<][>][^][v][top][bottom][index][help] */
 342   C_Type_t result=-1;
 343 
 344   int i;
 345   for (i=0; Class_aliases[i] != NULL; i++) {
 346     if (strcmp(Class_aliases[i], token) == 0) {
 347       result = Class_aliases_map[i];
 348       break;
 349     }
 350   }
 351 
 352   return result;
 353 } /* DF_class_name2type() */
 354 
 355 
 356 /* check in the queries if this attribute can trigger a radix lookup */
 357 int DF_attrcode_has_radix_lookup(A_Type_t attr) 
     /* [<][>][^][v][top][bottom][index][help] */
 358 {
 359   int i;
 360   
 361   for (i=0; Query[i].query != NULL; i++) {
 362     if( Query[i].refer == R_RADIX &&
 363         Query[i].attribute == attr ) {
 364       return 1;
 365     }
 366   }
 367   return 0;
 368 }

/* [<][>][^][v][top][bottom][index][help] */