mainconfig.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. * Copyright (c) 2002-2005 MontaVista Software, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Steven Dake (sdake@mvista.com)
  7. *
  8. * This software licensed under BSD license, the text of which follows:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. * THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include <stdio.h>
  35. #include <string.h>
  36. #include <stdlib.h>
  37. #include <errno.h>
  38. #include <assert.h>
  39. #include <sys/socket.h>
  40. #include <netinet/in.h>
  41. #include <arpa/inet.h>
  42. #include "../include/saAis.h"
  43. #include "../include/list.h"
  44. #include "util.h"
  45. #include "mainconfig.h"
  46. #include "mempool.h"
  47. #include "print.h"
  48. #include "totem.h"
  49. #include "service.h"
  50. static char error_string_response[512];
  51. typedef enum {
  52. MAIN_HEAD,
  53. MAIN_LOGGING,
  54. MAIN_EVENT,
  55. MAIN_AMF,
  56. MAIN_COMPONENTS
  57. } main_parse_t;
  58. /* This just makes the code below a little neater */
  59. static inline int objdb_get_string(struct objdb_iface_ver0 *objdb, unsigned int object_service_handle,
  60. char *key, char **value)
  61. {
  62. int res;
  63. *value = NULL;
  64. if ( !(res = objdb->object_key_get (object_service_handle,
  65. key,
  66. strlen (key),
  67. (void *)value,
  68. NULL))) {
  69. if (*value)
  70. return 0;
  71. }
  72. return -1;
  73. }
  74. extern int openais_main_config_read (
  75. struct objdb_iface_ver0 *objdb,
  76. char **error_string,
  77. struct openais_config *openais_config,
  78. int interface_max)
  79. {
  80. unsigned int object_service_handle;
  81. char *value;
  82. char *error_reason = error_string_response;
  83. memset (openais_config, 0, sizeof (struct openais_config));
  84. objdb->object_find_reset (OBJECT_PARENT_HANDLE);
  85. if (objdb->object_find (
  86. OBJECT_PARENT_HANDLE,
  87. "logging",
  88. strlen ("logging"),
  89. &object_service_handle) == 0) {
  90. if (!objdb_get_string (objdb,object_service_handle, "logoutput", &value)) {
  91. if (strcmp (value, "file") == 0) {
  92. openais_config->logmode |= LOG_MODE_FILE;
  93. } else
  94. if (strcmp (value, "syslog") == 0) {
  95. openais_config->logmode |= LOG_MODE_SYSLOG;
  96. } else
  97. if (strcmp (value, "stderr") == 0) {
  98. openais_config->logmode |= LOG_MODE_STDERR;
  99. } else {
  100. goto parse_error;
  101. }
  102. }
  103. if (!objdb_get_string (objdb,object_service_handle, "debug", &value)) {
  104. if (strcmp (value, "on") == 0) {
  105. openais_config->logmode |= LOG_MODE_DEBUG;
  106. } else
  107. if (strcmp (value, "off") == 0) {
  108. openais_config->logmode &= ~LOG_MODE_DEBUG;
  109. } else {
  110. goto parse_error;
  111. }
  112. }
  113. if (!objdb_get_string (objdb,object_service_handle, "timestamp", &value)) {
  114. if (strcmp (value, "on") == 0) {
  115. openais_config->logmode |= LOG_MODE_TIMESTAMP;
  116. } else
  117. if (strcmp (value, "off") == 0) {
  118. openais_config->logmode &= ~LOG_MODE_TIMESTAMP;
  119. } else {
  120. goto parse_error;
  121. }
  122. }
  123. if (!objdb_get_string (objdb,object_service_handle, "logfile", &value)) {
  124. openais_config->logfile = strdup (value);
  125. }
  126. }
  127. if (objdb->object_find (
  128. OBJECT_PARENT_HANDLE,
  129. "event",
  130. strlen ("event"),
  131. &object_service_handle) == 0) {
  132. if (!objdb_get_string (objdb,object_service_handle, "delivery_queue_size", &value)) {
  133. openais_config->evt_delivery_queue_size = atoi(value);
  134. }
  135. if (!objdb_get_string (objdb,object_service_handle, "delivery_queue_resume", &value)) {
  136. openais_config->evt_delivery_queue_resume = atoi(value);
  137. }
  138. }
  139. if (objdb->object_find (
  140. OBJECT_PARENT_HANDLE,
  141. "amf",
  142. strlen ("amf"),
  143. &object_service_handle) == 0) {
  144. if (!objdb_get_string (objdb,object_service_handle, "mode", &value)) {
  145. if (strcmp (value, "enabled") == 0) {
  146. openais_config->amf_enabled = 1;
  147. } else
  148. if (strcmp (value, "disabled") == 0) {
  149. openais_config->amf_enabled = 0;
  150. } else {
  151. goto parse_error;
  152. }
  153. }
  154. }
  155. openais_config->user = NULL;
  156. openais_config->group = NULL;
  157. if (objdb->object_find (
  158. OBJECT_PARENT_HANDLE,
  159. "aisexec",
  160. strlen ("aisexec"),
  161. &object_service_handle) == 0) {
  162. if (!objdb_get_string (objdb,object_service_handle, "user", &value)) {
  163. openais_config->user = strdup(value);
  164. }
  165. if (!objdb_get_string (objdb,object_service_handle, "group", &value)) {
  166. openais_config->group = strdup(value);
  167. }
  168. }
  169. /* Default user/group */
  170. if (!openais_config->user)
  171. openais_config->user = OPENAIS_USER;
  172. if (!openais_config->group)
  173. openais_config->group = OPENAIS_GROUP;
  174. if ((openais_config->logmode & LOG_MODE_FILE) && openais_config->logfile == 0) {
  175. error_reason = "logmode set to 'file' but no logfile specified";
  176. goto parse_error;
  177. }
  178. return 0;
  179. parse_error:
  180. sprintf (error_string_response,
  181. "parse error in config: %s.\n",
  182. error_reason);
  183. *error_string = error_string_response;
  184. return (-1);
  185. }