1 | /***************************************
2 | $Revision: 1.7 $
3 |
4 | Attributes module (at) - this _should_ eventually get merged in with the
5 | config module.
6 |
7 | Status: NOT REVUED, NOT TESTED
8 |
9 | ******************/ /******************
10 | Filename : attributes.c
11 | Author : ottrey@ripe.net
12 | OSs Tested : Solaris
13 | Related Modules : Used in conjunction with the objects module.
14 | Problems : Keeping consistency between arrays and enums.
15 | To Do : Total re-design.
16 | Comments :
17 | ******************/ /******************
18 | Copyright (c) 1999 RIPE NCC
19 |
20 | All Rights Reserved
21 |
22 | Permission to use, copy, modify, and distribute this software and its
23 | documentation for any purpose and without fee is hereby granted,
24 | provided that the above copyright notice appear in all copies and that
25 | both that copyright notice and this permission notice appear in
26 | supporting documentation, and that the name of the author not be
27 | used in advertising or publicity pertaining to distribution of the
28 | software without specific, written prior permission.
29 |
30 | THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
31 | ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
32 | AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
33 | DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
34 | AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
35 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
36 | ***************************************/
37 | #include <stdlib.h>
38 | #include "attributes.h"
39 |
40 | /*+ String sizes +*/
41 | #define STR_S 63
42 | #define STR_M 255
43 | #define STR_L 1023
44 | #define STR_XL 4095
45 | #define STR_XXL 16383
46 |
47 | /*+ Attributes (short name & long name) +*/
48 | char * const Attributes[] = {
49 | "ac", "admin-c",
50 | "aa", "as-name",
51 | "ad", "address",
52 | "ag", "aggr-mtd",
53 | "ab", "aggr-bndry",
54 | "ah", "author",
55 | "an", "aut-num",
56 | "as", "as-set",
57 | "at", "auth",
58 | "az", "alias",
59 | "ce", "certif",
60 | "ch", "changed",
61 | "cy", "country",
62 | "cn", "cross-nfy",
63 | "co", "components",
64 | "ct", "cross-mnt",
65 | "da", "dom-name",
66 | "de", "descr",
67 | "df", "default",
68 | "dc", "dictionary",
69 | "di", "dom-net",
70 | "dn", "domain",
71 | "dt", "upd-to",
72 | "ec", "export-comps",
73 | "en", "encapsulation",
74 | "em", "e-mail",
75 | "ex", "export",
76 | "fi", "filter",
77 | "fp", "fingerpr",
78 | "fs", "filter-set",
79 | "fx", "fax-no",
80 | "ho", "holes",
81 | "if", "ifaddr",
82 | "ij", "inject",
83 | "in", "inetnum",
84 | "i6", "inet6num",
85 | "ip", "import",
86 | "ir", "inet-rtr",
87 | "is", "rtr-set",
88 | "kc", "key-cert",
89 | "la", "local-as",
90 | "li", "limerick",
91 | "mh", "method",
92 | "mb", "mnt-by",
93 | "ml", "mnt-lower",
94 | "mo", "member-of",
95 | "mr", "mbrs-by-ref",
96 | "ms", "members",
97 | "mt", "mntner",
98 | "mn", "mnt-nfy",
99 | "na", "netname",
100 | "nh", "nic-hdl",
101 | "ns", "nserver",
102 | "ny", "notify",
103 | "or", "origin",
104 | "ow", "owner",
105 | "pe", "peer",
106 | "pg", "peering",
107 | "ph", "phone",
108 | "pl", "protocol",
109 | "pn", "person",
110 | "ps", "peering-set",
111 | "rf", "refer",
112 | "rm", "remarks",
113 | "ro", "role",
114 | "rp", "rp-attribute",
115 | "rs", "route-set",
116 | "rt", "route",
117 | "rz", "rev-srv",
118 | "sd", "sub-dom",
119 | "so", "source",
120 | "st", "status",
121 | "tb", "trouble",
122 | "td", "typedef",
123 | "tc", "tech-c",
124 | "tx", "text",
125 | "wd", "withdrawn",
126 | "zc", "zone-c",
127 | NULL, NULL
128 | }; /* Attributes */
129 |
130 | /*+ Attribute Details - Ie descriptions +*/
131 | const char *Attributes_details[][2] = {
132 | /* ac */ { "An on-site contact (person)", "<NIC-handle>" },
133 | /* aa */ { "A descriptive name associated with an AS.", "Uppercase letters, dashes (\"-\") and digits, no spaces.\n\tMust start with a letter." },
134 | /* ad */ { "Full postal address of a person.", "Free Text." },
135 | /* ag */ { "aggr-mtd", "INSERT aggr-mtd desc here." },
136 | /* ab */ { "aggr-bndry", "INSERT aggr-bndry desc here." },
137 | /* ah */ { "Limerick author.", "<NIC-handle>" },
138 | /* an */ { "The autonomous system number. This must be a uniquely\n\tallocated autonomous system number from an AS registry\n\t(e.g.RIPE NCC, the Inter-NIC, etc).", "\"AS\"<positive integer between 1 and 65535>" },
139 | /* as */ { "as-set", "INSERT as-set desc here." },
140 | /* at */ { "The formal authority for a community. This could be\n\tan organisation, institute, committee, etc.", "Free text (alphanumeric characters, \".\", \"-\", \"\\\")." },
141 | /* az */ { "alias", "INSERT alias desc here." },
142 | /* ce */ { "certif", "INSERT certif desc here." },
143 | /* ch */ { "Who previously changed this object\n\tand when this change was made.", "<RFC822 e-mail address> <DATE>\n\tE-mail address of person updating the object.\n\tDATE in YYYYMMDD or YYMMDD format." },
144 | /* cy */ { "ATB country DESC Name of the country of the admin-c.", "ATB country FRMT 2 letter uppercase ISO 3166 country code." },
145 | /* cn */ { "cross-nfy", "INSERT cross-nfy desc here." },
146 | /* co */ { "components", "INSERT components desc here." },
147 | /* ct */ { "cross-mnt", "INSERT cross-mnt desc here." },
148 | /* da */ { "dom-name", "INSERT dom-name desc here." },
149 | /* de */ { "A short decription of this object.", "All characters possible." },
150 | /* df */ { "default", "INSERT default desc here." },
151 | /* dc */ { "dictionary", "INSERT dictionary desc here." },
152 | /* di */ { "List of IP networks in a domain.", "Dotted quad including trailing 0's." },
153 | /* dn */ { "IP domain name.", "Full qualified domain name without trailing \".\"." },
154 | /* dt */ { "The e-mail address to be notified when an object\n\tATB upd-to DESC protected by a mntner is unsuccessfully updated.", "ATB upd-to FRMT RFC-822 address" },
155 | /* ec */ { "export-comps", "INSERT export-comps desc here." },
156 | /* en */ { "encapsulation", "INSERT encapsulation desc here." },
157 | /* em */ { "The e-mail address of a person or role.", "RFC-822 address." },
158 | /* ex */ { "export", "INSERT export desc here." },
159 | /* fi */ { "filter", "INSERT filter desc here." },
160 | /* fp */ { "fingerpr", "INSERT fingerpr desc here." },
161 | /* fs */ { "filter-set", "INSERT filter-set desc here." },
162 | /* fx */ { "The fax number of a person or role", "+ <Country Code> <Area Code> <Fax Number>" },
163 | /* ho */ { "holes", " INSERT holes desc here." },
164 | /* if */ { "An interface address within an internet router.", "<Interface Address> <Interface Subnet Mask>" },
165 | /* ij */ { "inject", "INSERT inject desc here." },
166 | /* in */ { "A range of IP address space.", "x.x.x.x - x.x.x.x, where 0 =< x =< 255" },
167 | /* i6 */ { "Full IP version 6 address.", "<ip6num>/<prefix length>" },
168 | /* ip */ { "import", "INSERT import desc here." },
169 | /* ir */ { "Fully qualified domain name of an internet router.", "Fully qualified domain name without trailing \".\"" },
170 | /* is */ { "rtr-set", "INSERT rtr-set desc here." },
171 | /* kc */ { "key-cert", "INSERT key-cert desc here." },
172 | /* la */ { "The autonomous system in which a router belongs.", "AS<positive integer between 1 and 65535>." },
173 | /* li */ { "Title of a limerick.", "LIM-<string>, where string can include\n\talphanumeric characters, \"-\" character." },
174 | /* mh */ { "method", "INSERT method desc here." },
175 | /* mb */ { "The identifier of a registered mntner object used for\n\tauthorization and authentication.", "<mntner>" },
176 | /* ml */ { "The identifier of a registered mntner object used for\n\thierarchical authorization and authentication.", "<mntner>" },
177 | /* mo */ { "member-of", " INSERT member-of desc here." },
178 | /* mr */ { "mbrs-by-ref", "INSERT mbrs-by-ref desc here." },
179 | /* ms */ { "members", "INSERT members desc here." },
180 | /* mt */ { "The name of a mntner object. Must be an unique mntner\n\tname, but can be identical to AS names, nic-handles.", "<uppercase letter><uppercase alphanumeric, \"-\">" },
181 | /* mn */ { "The e-mail address to be notified when an object\n\tprotected by a mntner is successfully updated.", "RFC-822 address." },
182 | /* na */ { "The name of a range of IP address space.", "<uppercase letter><uppercase alphanumeric, \"-\">" },
183 | /* nh */ { "The NIC handle of a role or person object.n\tThis can be a RIPE NIC-handle or a NIC-handle\n\tassigned by other regional registries.", "RIPE NIC-handle: <Initials><0-999>-RIPE" },
184 | /* ns */ { "List of nameservers for a domain object; a minimum\n\tof two is mandatory .", "<Fully qualified domain name(s) without trailing \".\">\n\tOR <IP Address(es) of the nameserver(s)>" },
185 | /* ny */ { "The e-mail address to which notifications of changes to\n\tan object should be sent.", "<RFC-822 address>" },
186 | /* or */ { "origin", "INSERT origin desc here." },
187 | /* ow */ { "owner", "INSERT owner desc here." },
188 | /* pe */ { "Details of any (interior or exterior) router peerings.", "<Peer address> <Peer AS> <Routing Protocol> [Local AS]\n\t[Local AS] is optional." },
189 | /* pg */ { "peering", "INSERT peering desc here." },
190 | /* ph */ { "Telephone number", "+ <Country Code><Area Code><Phone Number>\n\t+ <Country Code><Area Code><Phone Number> ext. <number>\n\tOptional: spaces may be used to split up the phone number\n\tinto its constituent components. \".\" characters can a191 | lso\n\tbe used between to separate the digits." },
192 | /* pl */ { "protocol", "INSERT protocol desc here." },
193 | /* pn */ { "The full name of an adminstrative, technical or zone\n\tcontact person specified in another object.\n\tDo not use titles such as\"Dr.\", \"Prof.\", \"Mv.\",\n\t\"Ms.\", \"Mr.\", etc.", "<Personal Name> <Family Name> where each name is\n\tco194 | mposed of alphabetic characters." },
195 | /* ps */ { "peering-set", "INSERT peering-set desc here." },
196 | /* rf */ { "Whois referral for domain objects", "<Type> <host> <port>\n\t<Type> is one of RIPE, Internic or SIMPLE. Specifies whois\n\tquery style.\n\t<host> specifies the host to be queried.\n\t<port> the TCP port number (optional: 43 is the default)"197 | },
198 | /* rm */ { "General remarks. Can include an URL or RFC822\n\taddress (if preceeded by mailto:).", "<free text>" },
199 | /* ro */ { "The full name of a role entity e.g. RIPE DBM.", "Two components, each consisting of alphabetic\n\tcharacters. Note: there is no \"-\" character\n\tbetween the two components of the the name." },
200 | /* rp */ { "rp-attribute", "INSERT rp-attribute desc here." },
201 | /* rs */ { "route-set", "INSERT route-set desc here." },
202 | /* rt */ { "route", "INSERT route desc here." },
203 | /* rz */ { "Domain name server for a range of IP addresses.", "Fully qualified name without trailing \".\"" },
204 | /* sd */ { "List of the sub-domains of a domain", "<Relative domain name to the domain>" },
205 | /* so */ { "Identifier of the database containing\n\tauthoritative data for this object.\n\tUse RIPE for objects in the RIPE Database.", "Uppercase Text." },
206 | /* st */ { "status", "INSERT status desc here." },
207 | /* tb */ { "Information on who to contact when there are problems.", "<Free text>" },
208 | /* td */ { "typedef", "INSERT typedef desc here." },
209 | /* tc */ { "A technical contact.", "<NIC-handle>" },
210 | /* tx */ { "Must be humourous, but not malicious\n\tor insulting. :-)", "Free Text." },
211 | /* wd */ { "withdrawn", "INSERT withdrawn desc here." },
212 | /* zc */ { "NIC-handle of the person with authority over a zone.", "<NIC-handle>" },
213 | { NULL , NULL }
214 | }; /* Attributes_details */
215 |
216 | /*+ Source database mirrors +*/
217 | char * const Sources[] = {
218 | "RIPE",
219 | "RIPE2",
220 | "ARIN",
221 | "APNIC",
222 | NULL
223 | }; /* Sources */
224 |
225 |
226 | /* AT_get_sources() */
227 | /*++++++++++++++++++++++++++++++++++++++
228 | Returns the sources as a list of strings. Used when validating query options.
229 |
230 | More:
231 | +html+ <PRE>
232 | Authors:
233 | ottrey
234 |
235 | +html+ </PRE><DL COMPACT>
236 | +html+ <DT>Online References:
237 | +html+ <DD><UL>
238 | +html+ </UL></DL>
239 |
240 | ++++++++++++++++++++++++++++++++++++++*/
241 | char * const *AT_get_sources(void) {
242 |
243 | return Sources;
244 |
245 | } /* AT_get_sources() */
246 |
247 | /* AT_get_source() */
248 | /*++++++++++++++++++++++++++++++++++++++
249 | Returns the indexed source.
250 |
251 | int index The index of the source in the Sources list.
252 |
253 | More:
254 | +html+ <PRE>
255 | Authors:
256 | ottrey
257 |
258 | +html+ </PRE><DL COMPACT>
259 | +html+ <DT>Online References:
260 | +html+ <DD><UL>
261 | +html+ </UL></DL>
262 |
263 | ++++++++++++++++++++++++++++++++++++++*/
264 | const char *AT_get_source(int index) {
265 |
266 | return Sources[index];
267 |
268 | } /* AT_get_source() */
269 |
270 | /* source_foreach() */
271 | /*++++++++++++++++++++++++++++++++++++++
272 | Function to adds the source string to the created string from the Glist of sources.
273 | It is called via g_list_foreach().
274 |
275 | void *element_data The source name.
276 |
277 | void *result_buf_ptr The string to be populated.
278 |
279 | More:
280 | +html+ <PRE>
281 | Authors:
282 | ottrey
283 |
284 | +html+ </PRE><DL COMPACT>
285 | +html+ <DT>Online References:
286 | +html+ <DD><UL>
287 | +html+ </UL></DL>
288 |
289 | ++++++++++++++++++++++++++++++++++++++*/
290 | static void source_foreach(void *element_data, void *result_buf_ptr) {
291 | char *source = element_data;
292 | char *result_buf = (char *)result_buf_ptr;
293 |
294 | strcat(result_buf, element_data);
295 | strcat(result_buf, ",");
296 |
297 | } /* source_foreach() */
298 |
299 | /* AT_sources_to_string() */
300 | /*++++++++++++++++++++++++++++++++++++++
301 | Creates a string from Sources.
302 |
303 | char * AT_sources_to_string Returns a string of the Sources.
304 |
305 | More:
306 | +html+ <PRE>
307 | Authors:
308 | ottrey
309 |
310 | +html+ </PRE><DL COMPACT>
311 | +html+ <DT>Online References:
312 | +html+ <DD><UL>
313 | +html+ </UL></DL>
314 |
315 | ++++++++++++++++++++++++++++++++++++++*/
316 | char * AT_sources_to_string(void) {
317 | char *result=NULL;
318 | char result_buf[STR_XL];
319 | int result_len;
320 | int i;
321 |
322 | strcpy(result_buf, "{");
323 | for (i=0; Sources[i] != NULL; i++) {
324 | strcat(result_buf, Sources[i]);
325 | strcat(result_buf, ",");
326 | }
327 | result_len = strlen(result_buf);
328 | result_buf[result_len-1] = '}';
329 | result_buf[result_len] = '\0';
330 |
331 | result = (char *)calloc(1, result_len+1);
332 | strcpy(result, result_buf);
333 |
334 | return result;
335 |
336 | } /* AT_sources_to_string() */
337 |
338 | /* AT_sources_list_to_string() */
339 | /*++++++++++++++++++++++++++++++++++++++
340 | Creates a string from the sources in the GList.
341 |
342 | GList *sources_list The GList of sources.
343 |
344 | More:
345 | +html+ <PRE>
346 | Authors:
347 | ottrey
348 |
349 | +html+ </PRE><DL COMPACT>
350 | +html+ <DT>Online References:
351 | +html+ <DD><UL>
352 | +html+ </UL></DL>
353 |
354 | ++++++++++++++++++++++++++++++++++++++*/
355 | char * AT_sources_list_to_string(GList *sources_list) {
356 | char *result=NULL;
357 | char result_buf[STR_XL];
358 | int result_len;
359 |
360 | strcpy(result_buf, "{");
361 | g_list_foreach(sources_list, source_foreach, &result_buf);
362 | result_len = strlen(result_buf);
363 | if (result_len == 1) {
364 | /* If an empty set */
365 | result_buf[1] = '}';
366 | result_buf[2] = '\0';
367 | }
368 | else {
369 | result_buf[result_len-1] = '}';
370 | result_buf[result_len] = '\0';
371 | }
372 |
373 | result = (char *)calloc(1, result_len+1);
374 | strcpy(result, result_buf);
375 |
376 | return result;
377 |
378 | } /* AT_sources_list_to_string() */
379 |
380 | /* AT_get_attributes() */
381 | /*++++++++++++++++++++++++++++++++++++++
382 | Returns the attributes as a list of strings.
383 |
384 | More:
385 | +html+ <PRE>
386 | Authors:
387 | ottrey
388 |
389 | +html+ </PRE><DL COMPACT>
390 | +html+ <DT>Online References:
391 | +html+ <DD><UL>
392 | +html+ </UL></DL>
393 |
394 | ++++++++++++++++++++++++++++++++++++++*/
395 | char * const *AT_get_attributes(void) {
396 |
397 | return Attributes;
398 |
399 | } /* AT_get_sources() */
400 |
401 | /* AT_get_attribute() */
402 | /*++++++++++++++++++++++++++++++++++++++
403 | Returns the indexed attribute. Used when validating query options.
404 |
405 | AT_Type attr_index The index into the Attributes[] array.
406 |
407 | int offset The offset (Ie short or long name).
408 |
409 | More:
410 | +html+ <PRE>
411 | Authors:
412 | ottrey
413 |
414 | +html+ </PRE><DL COMPACT>
415 | +html+ <DT>Online References:
416 | +html+ <DD><UL>
417 | +html+ </UL></DL>
418 |
419 | ++++++++++++++++++++++++++++++++++++++*/
420 | const char *AT_get_attribute(AT_Type attr_index, int offset) {
421 |
422 | return Attributes[attr_index*2+offset];
423 |
424 | } /* AT_get_attribute() */
425 |
426 | /* AT_get_attribute_desc() */
427 | /*++++++++++++++++++++++++++++++++++++++
428 | Returns the attribute description. Used for -t & -v queries.
429 |
430 | AT_Type attr_index The index into the Attributes[] array.
431 |
432 | More:
433 | +html+ <PRE>
434 | Authors:
435 | ottrey
436 |
437 | +html+ </PRE><DL COMPACT>
438 | +html+ <DT>Online References:
439 | +html+ <DD><UL>
440 | +html+ </UL></DL>
441 |
442 | ++++++++++++++++++++++++++++++++++++++*/
443 | const char *AT_get_attribute_desc(AT_Type attr_index) {
444 |
445 | return (char *)Attributes_details[attr_index][0];
446 |
447 | } /* AT_get_attribute_desc() */
448 |
449 | /* AT_get_attribute_frmt() */
450 | /*++++++++++++++++++++++++++++++++++++++
451 | Returns the attribute format. Used for -t & -v queries.
452 |
453 | AT_Type attr_index The index into the Attributes[] array.
454 |
455 | More:
456 | +html+ <PRE>
457 | Authors:
458 | ottrey
459 |
460 | +html+ </PRE><DL COMPACT>
461 | +html+ <DT>Online References:
462 | +html+ <DD><UL>
463 | +html+ </UL></DL>
464 |
465 | ++++++++++++++++++++++++++++++++++++++*/
466 | const char *AT_get_attribute_frmt(AT_Type attr_index) {
467 |
468 | return (char *)Attributes_details[attr_index][1];
469 |
470 | } /* AT_get_attribute_frmt() */
471 |
472 | /* AT_attributes_to_string() */
473 | /*++++++++++++++++++++++++++++++++++++++
474 | Returns a string of all the attributes. Only there for debugging and tracing purposes.
475 |
476 | int offset The offset (Ie short or long name).
477 |
478 | More:
479 | +html+ <PRE>
480 | Authors:
481 | ottrey
482 |
483 | +html+ </PRE><DL COMPACT>
484 | +html+ <DT>Online References:
485 | +html+ <DD><UL>
486 | +html+ </UL></DL>
487 |
488 | ++++++++++++++++++++++++++++++++++++++*/
489 | char *AT_attributes_to_string(int offset) {
490 | int i;
491 | char *str;
492 | char str_buffer[4096];
493 | int str_len;
494 |
495 | strcpy(str_buffer, "{\"");
496 | for (i=0; Attributes[i*2+offset] != NULL; i++) {
497 | strcat(str_buffer, Attributes[i*2+offset]);
498 | strcat(str_buffer, "\", \"");
499 | }
500 | str_len = strlen(str_buffer);
501 | str_buffer[str_len-3] = '}';
502 | str_buffer[str_len-2] = '\0';
503 | str_len--;
504 |
505 | str = (char *)calloc(1, str_len);
506 | strcpy(str, str_buffer);
507 |
508 | return str;
509 |
510 | } /* AT_attributes_to_string() */
511 |