1 /* -*- Mode: c; c-basic-offset: 2 -*-
2  *
3  * raptor_option.c - Class options
4  *
5  * Copyright (C) 2004-2010, David Beckett http://www.dajobe.org/
6  * Copyright (C) 2004-2005, University of Bristol, UK http://www.bristol.ac.uk/
7  *
8  * This package is Free Software and part of Redland http://librdf.org/
9  *
10  * It is licensed under the following three licenses as alternatives:
11  *   1. GNU Lesser General Public License (LGPL) V2.1 or any newer version
12  *   2. GNU General Public License (GPL) V2 or any newer version
13  *   3. Apache License, V2.0 or any newer version
14  *
15  * You may not use this file except in compliance with at least one of
16  * the above three licenses.
17  *
18  * See LICENSE.html or LICENSE.txt at the top of this package for the
19  * complete terms and further detail along with the license texts for
20  * the licenses in COPYING.LIB, COPYING and LICENSE-2.0.txt respectively.
21  *
22  *
23  */
24 
25 
26 #ifdef HAVE_CONFIG_H
27 #include <raptor_config.h>
28 #endif
29 
30 #include <stdio.h>
31 #include <string.h>
32 #include <ctype.h>
33 #include <stdarg.h>
34 
35 /* Raptor includes */
36 #include "raptor2.h"
37 #include "raptor_internal.h"
38 
39 
40 static const struct
41 {
42   raptor_option option;
43   raptor_option_area area;
44   raptor_option_value_type value_type;
45   const char *name;
46   const char *label;
47 } raptor_options_list[RAPTOR_OPTION_LAST + 1] = {
48   { RAPTOR_OPTION_SCANNING,
49     RAPTOR_OPTION_AREA_PARSER,
50     RAPTOR_OPTION_VALUE_TYPE_BOOL,
51     "scanForRDF",
52     "RDF/XML parser scans for rdf:RDF in XML content"
53   },
54   { RAPTOR_OPTION_ALLOW_NON_NS_ATTRIBUTES,
55     RAPTOR_OPTION_AREA_PARSER,
56     RAPTOR_OPTION_VALUE_TYPE_BOOL,
57     "allowNonNsAttributes",
58     "RDF/XML parser allows bare 'name' rather than namespaced 'rdf:name'"
59   },
60   { RAPTOR_OPTION_ALLOW_OTHER_PARSETYPES,
61     RAPTOR_OPTION_AREA_PARSER,
62     RAPTOR_OPTION_VALUE_TYPE_BOOL,
63     "allowOtherParsetypes",
64     "RDF/XML parser allows user-defined rdf:parseType values"
65   },
66   { RAPTOR_OPTION_ALLOW_BAGID,
67     RAPTOR_OPTION_AREA_PARSER,
68     RAPTOR_OPTION_VALUE_TYPE_BOOL,
69     "allowBagID",
70     "RDF/XML parser allows rdf:bagID"
71   },
72   { RAPTOR_OPTION_ALLOW_RDF_TYPE_RDF_LIST,
73     RAPTOR_OPTION_AREA_PARSER,
74     RAPTOR_OPTION_VALUE_TYPE_BOOL,
75     "allowRDFtypeRDFlist",
76     "RDF/XML parser generates the collection rdf:type rdf:List triple"
77   },
78   { RAPTOR_OPTION_NORMALIZE_LANGUAGE,
79     (raptor_option_area)(RAPTOR_OPTION_AREA_PARSER | RAPTOR_OPTION_AREA_SAX2),
80     RAPTOR_OPTION_VALUE_TYPE_BOOL,
81     "normalizeLanguage",
82     "RDF/XML parser normalizes xml:lang values to lowercase"
83   },
84   { RAPTOR_OPTION_NON_NFC_FATAL,
85     RAPTOR_OPTION_AREA_PARSER,
86     RAPTOR_OPTION_VALUE_TYPE_BOOL,
87     "nonNFCfatal",
88     "RDF/XML parser makes non-NFC literals a fatal error"
89   },
90   { RAPTOR_OPTION_WARN_OTHER_PARSETYPES,
91     RAPTOR_OPTION_AREA_PARSER,
92     RAPTOR_OPTION_VALUE_TYPE_BOOL,
93     "warnOtherParseTypes",
94     "RDF/XML parser warns about unknown rdf:parseType values"
95   },
96   { RAPTOR_OPTION_CHECK_RDF_ID,
97     RAPTOR_OPTION_AREA_PARSER,
98     RAPTOR_OPTION_VALUE_TYPE_BOOL,
99     "checkRdfID",
100     "RDF/XML parser checks rdf:ID values for duplicates"
101   },
102   { RAPTOR_OPTION_RELATIVE_URIS,
103     RAPTOR_OPTION_AREA_SERIALIZER,
104     RAPTOR_OPTION_VALUE_TYPE_BOOL,
105     "relativeURIs",
106     "Serializers write relative URIs wherever possible."
107   },
108   { RAPTOR_OPTION_WRITER_AUTO_INDENT,
109     (raptor_option_area)(RAPTOR_OPTION_AREA_XML_WRITER | RAPTOR_OPTION_AREA_TURTLE_WRITER),
110     RAPTOR_OPTION_VALUE_TYPE_BOOL,
111     "autoIndent",
112     "Turtle and XML Writer automatically indent elements."
113   },
114   { RAPTOR_OPTION_WRITER_AUTO_EMPTY,
115     (raptor_option_area)(RAPTOR_OPTION_AREA_XML_WRITER | RAPTOR_OPTION_AREA_TURTLE_WRITER),
116     RAPTOR_OPTION_VALUE_TYPE_BOOL,
117     "autoEmpty",
118     "Turtle and XML Writer automatically detect and abbreviate empty elements."
119   },
120   { RAPTOR_OPTION_WRITER_INDENT_WIDTH,
121     (raptor_option_area)(RAPTOR_OPTION_AREA_XML_WRITER | RAPTOR_OPTION_AREA_TURTLE_WRITER),
122     RAPTOR_OPTION_VALUE_TYPE_BOOL,
123     "indentWidth",
124     "Turtle and XML Writer use as number of spaces to indent."
125   },
126   { RAPTOR_OPTION_WRITER_XML_VERSION,
127     (raptor_option_area)(RAPTOR_OPTION_AREA_SERIALIZER | RAPTOR_OPTION_AREA_XML_WRITER),
128     RAPTOR_OPTION_VALUE_TYPE_INT,
129     "xmlVersion",
130     "Serializers and XML Writer use as XML version to write."
131   },
132   { RAPTOR_OPTION_WRITER_XML_DECLARATION,
133     (raptor_option_area)(RAPTOR_OPTION_AREA_SERIALIZER | RAPTOR_OPTION_AREA_XML_WRITER),
134     RAPTOR_OPTION_VALUE_TYPE_BOOL,
135     "xmlDeclaration",
136     "Serializers and XML Writer write XML declaration."
137   },
138   { RAPTOR_OPTION_NO_NET,
139     (raptor_option_area)(RAPTOR_OPTION_AREA_PARSER | RAPTOR_OPTION_AREA_SAX2),
140     RAPTOR_OPTION_VALUE_TYPE_BOOL,
141     "noNet",
142     "Parsers and SAX2 XML Parser deny internal network requests."
143   },
144   { RAPTOR_OPTION_RESOURCE_BORDER,
145     RAPTOR_OPTION_AREA_SERIALIZER,
146     RAPTOR_OPTION_VALUE_TYPE_STRING,
147     "resourceBorder",
148     "DOT serializer resource border color"
149   },
150   { RAPTOR_OPTION_LITERAL_BORDER,
151     RAPTOR_OPTION_AREA_SERIALIZER,
152     RAPTOR_OPTION_VALUE_TYPE_STRING,
153     "literalBorder",
154     "DOT serializer literal border color"
155   },
156   { RAPTOR_OPTION_BNODE_BORDER,
157     RAPTOR_OPTION_AREA_SERIALIZER,
158     RAPTOR_OPTION_VALUE_TYPE_STRING,
159     "bnodeBorder",
160     "DOT serializer blank node border color"
161   },
162   { RAPTOR_OPTION_RESOURCE_FILL,
163     RAPTOR_OPTION_AREA_SERIALIZER,
164     RAPTOR_OPTION_VALUE_TYPE_STRING,
165     "resourceFill",
166     "DOT serializer resource fill color"
167   },
168   { RAPTOR_OPTION_LITERAL_FILL,
169     RAPTOR_OPTION_AREA_SERIALIZER,
170     RAPTOR_OPTION_VALUE_TYPE_STRING,
171     "literalFill",
172     "DOT serializer literal fill color"
173   },
174   { RAPTOR_OPTION_BNODE_FILL,
175     RAPTOR_OPTION_AREA_SERIALIZER,
176     RAPTOR_OPTION_VALUE_TYPE_STRING,
177     "bnodeFill",
178     "DOT serializer blank node fill color"
179   },
180   { RAPTOR_OPTION_HTML_TAG_SOUP,
181     RAPTOR_OPTION_AREA_PARSER,
182     RAPTOR_OPTION_VALUE_TYPE_BOOL,
183     "htmlTagSoup",
184     "GRDDL parser uses a lax HTML parser"
185   },
186   { RAPTOR_OPTION_MICROFORMATS,
187     RAPTOR_OPTION_AREA_PARSER,
188     RAPTOR_OPTION_VALUE_TYPE_BOOL,
189     "microformats",
190     "GRDDL parser looks for microformats"
191   },
192   { RAPTOR_OPTION_HTML_LINK,
193     RAPTOR_OPTION_AREA_PARSER,
194     RAPTOR_OPTION_VALUE_TYPE_BOOL,
195     "htmlLink",
196     "GRDDL parser looks for <link type=\"application/rdf+xml\">"
197   },
198   { RAPTOR_OPTION_WWW_TIMEOUT,
199     RAPTOR_OPTION_AREA_PARSER,
200     RAPTOR_OPTION_VALUE_TYPE_INT,
201     "wwwTimeout",
202     "Parser WWW request retrieval timeout"
203   },
204   { RAPTOR_OPTION_WRITE_BASE_URI,
205     RAPTOR_OPTION_AREA_SERIALIZER,
206     RAPTOR_OPTION_VALUE_TYPE_BOOL,
207     "writeBaseURI",
208     "Serializers write a base URI directive @base / xml:base"
209   },
210   { RAPTOR_OPTION_WWW_HTTP_CACHE_CONTROL,
211     RAPTOR_OPTION_AREA_PARSER,
212     RAPTOR_OPTION_VALUE_TYPE_STRING,
213     "wwwHttpCacheControl",
214     "Parser WWW request HTTP Cache-Control: header value"
215   },
216   { RAPTOR_OPTION_WWW_HTTP_USER_AGENT,
217     RAPTOR_OPTION_AREA_PARSER,
218     RAPTOR_OPTION_VALUE_TYPE_STRING,
219     "wwwHttpUserAgent",
220     "Parser WWW request HTTP User-Agent: header value"
221   },
222   { RAPTOR_OPTION_JSON_CALLBACK,
223     RAPTOR_OPTION_AREA_SERIALIZER,
224     RAPTOR_OPTION_VALUE_TYPE_STRING,
225     "jsonCallback",
226     "JSON serializer callback function name"
227   },
228   { RAPTOR_OPTION_JSON_EXTRA_DATA,
229     RAPTOR_OPTION_AREA_SERIALIZER,
230     RAPTOR_OPTION_VALUE_TYPE_STRING,
231     "jsonExtraData",
232     "JSON serializer callback data parameter"
233   },
234   { RAPTOR_OPTION_RSS_TRIPLES,
235     RAPTOR_OPTION_AREA_SERIALIZER,
236     RAPTOR_OPTION_VALUE_TYPE_STRING,
237     "rssTriples",
238     "Atom and RSS serializers write extra RDF triples"
239   },
240   { RAPTOR_OPTION_ATOM_ENTRY_URI,
241     RAPTOR_OPTION_AREA_SERIALIZER,
242     RAPTOR_OPTION_VALUE_TYPE_URI,
243     "atomEntryUri",
244     "Atom serializer writes an atom:entry with this URI (otherwise atom:feed)"
245   },
246   { RAPTOR_OPTION_PREFIX_ELEMENTS,
247     RAPTOR_OPTION_AREA_SERIALIZER,
248     RAPTOR_OPTION_VALUE_TYPE_BOOL,
249     "prefixElements",
250     "Atom and RSS serializers write namespace-prefixed elements"
251   },
252   { RAPTOR_OPTION_STRICT,
253     RAPTOR_OPTION_AREA_PARSER,
254     RAPTOR_OPTION_VALUE_TYPE_BOOL,
255     "strict",
256     "Operate in strict conformance mode (otherwise lax)"
257   },
258   { RAPTOR_OPTION_WWW_CERT_FILENAME,
259     RAPTOR_OPTION_AREA_PARSER,
260     RAPTOR_OPTION_VALUE_TYPE_STRING,
261     "wwwCertFilename",
262     "SSL client certificate filename"
263   },
264   { RAPTOR_OPTION_WWW_CERT_TYPE,
265     RAPTOR_OPTION_AREA_PARSER,
266     RAPTOR_OPTION_VALUE_TYPE_STRING,
267     "wwwCertType",
268     "SSL client certificate type"
269   },
270   { RAPTOR_OPTION_WWW_CERT_PASSPHRASE,
271     RAPTOR_OPTION_AREA_PARSER,
272     RAPTOR_OPTION_VALUE_TYPE_STRING,
273     "wwwCertPassphrase",
274     "SSL client certificate passphrase"
275   },
276   { RAPTOR_OPTION_NO_FILE,
277     (raptor_option_area)(RAPTOR_OPTION_AREA_PARSER | RAPTOR_OPTION_AREA_SAX2),
278     RAPTOR_OPTION_VALUE_TYPE_BOOL,
279     "noFile",
280     "Parsers and SAX2 deny internal file requests."
281   },
282   { RAPTOR_OPTION_WWW_SSL_VERIFY_PEER,
283     RAPTOR_OPTION_AREA_PARSER,
284     RAPTOR_OPTION_VALUE_TYPE_INT,
285     "wwwSslVerifyPeer",
286     "SSL verify peer certficate"
287   },
288   { RAPTOR_OPTION_WWW_SSL_VERIFY_HOST,
289     RAPTOR_OPTION_AREA_PARSER,
290     RAPTOR_OPTION_VALUE_TYPE_INT,
291     "wwwSslVerifyHost",
292     "SSL verify host matching"
293   },
294   { RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES,
295     (raptor_option_area)(RAPTOR_OPTION_AREA_PARSER | RAPTOR_OPTION_AREA_SAX2),
296     RAPTOR_OPTION_VALUE_TYPE_BOOL,
297     "loadExternalEntities",
298     "Parsers and SAX2 should load external entities."
299   }
300 };
301 
302 
303 static const char * const raptor_option_uri_prefix = "http://feature.librdf.org/raptor-";
304 /* NOTE: this is strlen(raptor_option_uri_prefix) */
305 static const int raptor_option_uri_prefix_len = 33;
306 
307 
308 static raptor_option_area
raptor_option_get_option_area_for_domain(raptor_domain domain)309 raptor_option_get_option_area_for_domain(raptor_domain domain)
310 {
311   raptor_option_area area = RAPTOR_OPTION_AREA_NONE;
312 
313   if(domain == RAPTOR_DOMAIN_PARSER)
314     area = RAPTOR_OPTION_AREA_PARSER;
315   else if(domain == RAPTOR_DOMAIN_SERIALIZER)
316     area = RAPTOR_OPTION_AREA_SERIALIZER;
317   else if(domain == RAPTOR_DOMAIN_SAX2)
318     area = RAPTOR_OPTION_AREA_SAX2;
319   else if(domain == RAPTOR_DOMAIN_XML_WRITER)
320     area = RAPTOR_OPTION_AREA_XML_WRITER;
321   else if(domain == RAPTOR_DOMAIN_TURTLE_WRITER)
322     area = RAPTOR_OPTION_AREA_TURTLE_WRITER;
323 
324   return area;
325 }
326 
327 
328 /**
329  * raptor_free_option_description:
330  * @option_description: option description
331  *
332  * Destructor - free an option description object.
333  */
334 void
raptor_free_option_description(raptor_option_description * option_description)335 raptor_free_option_description(raptor_option_description* option_description)
336 {
337   if(!option_description)
338     return;
339 
340   /* these are shared strings pointing to static data in raptor_options_list[] */
341   /* RAPTOR_FREE(char*, option_description->name); */
342   /* RAPTOR_FREE(char*, option_description->label); */
343 
344   if(option_description->uri)
345     raptor_free_uri(option_description->uri);
346 
347   RAPTOR_FREE(raptor_option_description, option_description);
348 }
349 
350 
351 /**
352  * raptor_world_get_option_description:
353  * @world: raptor world object
354  * @domain: domain
355  * @option: option enumeration (0+)
356  *
357  * Get a description of an option for a domain.
358  *
359  * The returned description must be freed with
360  * raptor_free_option_description().
361  *
362  * Return value: option description or NULL on failure or if option is unknown
363  **/
364 raptor_option_description*
raptor_world_get_option_description(raptor_world * world,const raptor_domain domain,const raptor_option option)365 raptor_world_get_option_description(raptor_world* world,
366                                     const raptor_domain domain,
367                                     const raptor_option option)
368 {
369   raptor_option_area area;
370   raptor_option_description *option_description = NULL;
371   raptor_uri *base_uri = NULL;
372   int i;
373 
374   RAPTOR_ASSERT_OBJECT_POINTER_RETURN_VALUE(world, raptor_world, NULL);
375 
376   raptor_world_open(world);
377 
378   area = raptor_option_get_option_area_for_domain(domain);
379   if(area == RAPTOR_OPTION_AREA_NONE)
380     return NULL;
381 
382   for(i = 0; i <= RAPTOR_OPTION_LAST; i++) {
383     if(raptor_options_list[i].option == option &&
384        (raptor_options_list[i].area & area))
385       break;
386   }
387 
388   if(i > RAPTOR_OPTION_LAST)
389     return NULL;
390 
391   option_description = RAPTOR_CALLOC(raptor_option_description*, 1,
392                                      sizeof(*option_description));
393   if(!option_description)
394     return NULL;
395 
396   option_description->domain = domain;
397   option_description->option = option;
398   option_description->value_type = raptor_options_list[i].value_type;
399   option_description->name = raptor_options_list[i].name;
400   option_description->name_len = strlen(option_description->name);
401   option_description->label = raptor_options_list[i].label;
402 
403   base_uri = raptor_new_uri_from_counted_string(world,
404                                                 (const unsigned char*)raptor_option_uri_prefix,
405                                                 raptor_option_uri_prefix_len);
406   if(!base_uri) {
407     raptor_free_option_description(option_description);
408     return NULL;
409   }
410 
411   option_description->uri = raptor_new_uri_from_uri_local_name(world,
412                                                                base_uri,
413                                                                (const unsigned char*)raptor_options_list[i].name);
414   raptor_free_uri(base_uri);
415   if(!option_description->uri) {
416     raptor_free_option_description(option_description);
417     return NULL;
418   }
419 
420   return option_description;
421 }
422 
423 
424 
425 int
raptor_option_is_valid_for_area(const raptor_option option,raptor_option_area area)426 raptor_option_is_valid_for_area(const raptor_option option,
427                                 raptor_option_area area)
428 {
429   if(option > RAPTOR_OPTION_LAST)
430     return 0;
431   return (raptor_options_list[option].area & area) != 0;
432 }
433 
434 
435 int
raptor_option_value_is_numeric(const raptor_option option)436 raptor_option_value_is_numeric(const raptor_option option)
437 {
438   raptor_option_value_type t = raptor_options_list[option].value_type;
439 
440   return t == RAPTOR_OPTION_VALUE_TYPE_BOOL ||
441          t == RAPTOR_OPTION_VALUE_TYPE_INT;
442 }
443 
444 
445 /**
446  * raptor_world_get_option_from_uri:
447  * @world: raptor_world instance
448  * @uri: option URI
449  *
450  * Get an option ID from a URI
451  *
452  * Option URIs are the concatenation of the string
453  * "http://feature.librdf.org/raptor-" plus the short name.
454  *
455  * They are automatically returned for any option described with
456  * raptor_world_get_option_description().
457  *
458  * Return value: < 0 if the option is unknown or on error
459  **/
460 raptor_option
raptor_world_get_option_from_uri(raptor_world * world,raptor_uri * uri)461 raptor_world_get_option_from_uri(raptor_world* world, raptor_uri *uri)
462 {
463   unsigned char *uri_string;
464   int i;
465   raptor_option option = (raptor_option)-1;
466 
467   if(!uri)
468     return option;
469 
470   RAPTOR_ASSERT_OBJECT_POINTER_RETURN_VALUE(world, raptor_world, (raptor_option)-1);
471 
472   raptor_world_open(world);
473 
474   uri_string = raptor_uri_as_string(uri);
475   if(strncmp((const char*)uri_string, raptor_option_uri_prefix,
476              raptor_option_uri_prefix_len))
477     return option;
478 
479   uri_string += raptor_option_uri_prefix_len;
480 
481   for(i = 0; i <= RAPTOR_OPTION_LAST; i++)
482     if(!strcmp(raptor_options_list[i].name, (const char*)uri_string)) {
483       option = (raptor_option)i;
484       break;
485     }
486 
487   return option;
488 }
489 
490 
491 /**
492  * raptor_option_get_count:
493  *
494  * Get the count of options defined.
495  *
496  * This is prefered to the compile time-only symbol #RAPTOR_OPTION_LAST
497  * and returns a count of the number of options which is
498  * #RAPTOR_OPTION_LAST + 1.
499  *
500  * Return value: count of options in the #raptor_option enumeration
501  **/
502 unsigned int
raptor_option_get_count(void)503 raptor_option_get_count(void)
504 {
505   return RAPTOR_OPTION_LAST + 1;
506 }
507 
508 
509 const char* const
510 raptor_option_value_type_labels[RAPTOR_OPTION_VALUE_TYPE_URI + 1] = {
511   "boolean",
512   "integer",
513   "string",
514   "uri"
515 };
516 
517 
518 /**
519  * raptor_option_get_value_type_label:
520  * @type: value type
521  *
522  * Get a label for a value type
523  *
524  * Return value: label for type or NULL for invalid type
525  */
526 const char*
raptor_option_get_value_type_label(const raptor_option_value_type type)527 raptor_option_get_value_type_label(const raptor_option_value_type type)
528 {
529   if(type > RAPTOR_OPTION_VALUE_TYPE_LAST)
530     return NULL;
531   return raptor_option_value_type_labels[type];
532 }
533 
534 
535 int
raptor_object_options_copy_state(raptor_object_options * to,raptor_object_options * from)536 raptor_object_options_copy_state(raptor_object_options* to,
537                                  raptor_object_options* from)
538 {
539   int rc = 0;
540   int i;
541 
542   to->area = from->area;
543   for(i = 0; !rc && i <= RAPTOR_OPTION_LAST; i++) {
544     if(raptor_option_value_is_numeric((raptor_option)i))
545       to->options[i].integer = from->options[i].integer;
546     else {
547       /* non-numeric values may need allocations */
548       char* string = from->options[i].string;
549       if(string) {
550         size_t len = strlen(string);
551         to->options[i].string = RAPTOR_MALLOC(char*, len + 1);
552         if(to->options[i].string)
553           memcpy(to->options[i].string, string, len + 1);
554         else
555           rc = 1;
556       }
557     }
558   }
559 
560   return rc;
561 }
562 
563 
564 void
raptor_object_options_init(raptor_object_options * options,raptor_option_area area)565 raptor_object_options_init(raptor_object_options* options,
566                            raptor_option_area area)
567 {
568   int i;
569 
570   options->area = area;
571 
572   for(i = 0; i <= RAPTOR_OPTION_LAST; i++) {
573     if(raptor_option_value_is_numeric((raptor_option)i))
574       options->options[i].integer = 0;
575     else
576       options->options[i].string = NULL;
577   }
578 
579   /* Initialise default options that are not 0 or NULL */
580 
581   /* Emit @base directive or equivalent */
582   options->options[RAPTOR_OPTION_WRITE_BASE_URI].integer = 1;
583 
584   /* Emit relative URIs where possible */
585   options->options[RAPTOR_OPTION_RELATIVE_URIS].integer = 1;
586 
587   /* XML 1.0 output */
588   options->options[RAPTOR_OPTION_WRITER_XML_VERSION].integer = 10;
589 
590   /* Write XML declaration */
591   options->options[RAPTOR_OPTION_WRITER_XML_DECLARATION].integer = 1;
592 
593   /* Indent 2 spaces */
594   options->options[RAPTOR_OPTION_WRITER_INDENT_WIDTH].integer = 2;
595 
596   /* lax (no strict) parsing */
597   options->options[RAPTOR_OPTION_STRICT].integer = 0;
598 
599   /* SSL verify peers */
600   options->options[RAPTOR_OPTION_WWW_SSL_VERIFY_PEER].integer = 1;
601 
602   /* SSL fully verify hosts */
603   options->options[RAPTOR_OPTION_WWW_SSL_VERIFY_HOST].integer = 2;
604 
605 }
606 
607 
608 void
raptor_object_options_clear(raptor_object_options * options)609 raptor_object_options_clear(raptor_object_options* options)
610 {
611   int i;
612 
613   for(i = 0; i <= RAPTOR_OPTION_LAST; i++) {
614     if(raptor_option_value_is_numeric((raptor_option)i))
615       continue;
616 
617     if(options->options[i].string)
618       RAPTOR_FREE(char*, options->options[i].string);
619   }
620 }
621 
622 
623 /*
624  * raptor_object_options_get_option:
625  * @options: options object
626  * @option: option to get value
627  * @string_p: pointer to where to store string value
628  * @integer_p: pointer to where to store integer value
629  *
630  * INTERNAL - get option value
631  *
632  * Any string value returned in *@string_p is shared and must be
633  * copied by the caller.
634  *
635  * The allowed options vary by the area field of @options.
636  *
637  * Return value: option value or < 0 for an illegal option
638  **/
639 int
raptor_object_options_get_option(raptor_object_options * options,raptor_option option,char ** string_p,int * integer_p)640 raptor_object_options_get_option(raptor_object_options* options,
641                                  raptor_option option,
642                                  char** string_p, int* integer_p)
643 {
644   if(!raptor_option_is_valid_for_area(option, options->area))
645     return 1;
646 
647   if(raptor_option_value_is_numeric(option)) {
648     /* numeric options */
649     int value = options->options[(int)option].integer;
650     if(integer_p)
651       *integer_p = value;
652   } else {
653     /* non-numeric options */
654     char* string = options->options[(int)option].string;
655     if(string_p)
656       *string_p = string;
657   }
658 
659   return 0;
660 }
661 
662 
663 /*
664  * raptor_object_options_set_option:
665  * @options: options object
666  * @option: option to set
667  * @string: string option value (or NULL)
668  * @integer: integer option value
669  *
670  * INTERNAL - set option
671  *
672  * If @string is not NULL and the option type is numeric, the string
673  * value is converted to an integer and used in preference to @integer.
674  *
675  * If @string is NULL and the option type is not numeric, an error is
676  * returned.
677  *
678  * The @string values used are copied.
679  *
680  * The allowed options vary by the area field of @options.
681  *
682  * Return value: non 0 on failure or if the option is unknown
683  **/
684 int
raptor_object_options_set_option(raptor_object_options * options,raptor_option option,const char * string,int integer)685 raptor_object_options_set_option(raptor_object_options *options,
686                                  raptor_option option,
687                                  const char* string, int integer)
688 {
689   if(!raptor_option_is_valid_for_area(option, options->area))
690     return 1;
691 
692   if(raptor_option_value_is_numeric(option)) {
693     /* numeric options */
694     if(string)
695       integer = atoi((const char*)string);
696 
697     options->options[(int)option].integer = integer;
698     return 0;
699   } else {
700     /* non-numeric options */
701     char *string_copy;
702     size_t len = 0;
703 
704     if(string)
705       len = strlen((const char*)string);
706     string_copy = RAPTOR_MALLOC(char*, len + 1);
707     if(!string_copy)
708       return 1;
709 
710     if(len)
711       memcpy(string_copy, string, len);
712     string_copy[len] = '\0';
713 
714     options->options[(int)option].string = string_copy;
715   }
716 
717   return 0;
718 }
719