mainconfig.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 main_config *main_config,
  78. int interface_max)
  79. {
  80. unsigned int object_service_handle;
  81. char *value;
  82. char *error_reason = error_string_response;
  83. memset (main_config, 0, sizeof (struct main_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. main_config->logmode |= LOG_MODE_FILE;
  93. } else
  94. if (strcmp (value, "syslog") == 0) {
  95. main_config->logmode |= LOG_MODE_SYSLOG;
  96. } else
  97. if (strcmp (value, "stderr") == 0) {
  98. main_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. main_config->logmode |= LOG_MODE_DEBUG;
  106. } else
  107. if (strcmp (value, "off") == 0) {
  108. main_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. main_config->logmode |= LOG_MODE_TIMESTAMP;
  116. } else
  117. if (strcmp (value, "off") == 0) {
  118. main_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. main_config->logfile = strdup (value);
  125. }
  126. }
  127. if (objdb->object_find (
  128. OBJECT_PARENT_HANDLE,
  129. "aisexec",
  130. strlen ("aisexec"),
  131. &object_service_handle) == 0) {
  132. if (!objdb_get_string (objdb,object_service_handle, "user", &value)) {
  133. main_config->user = strdup(value);
  134. }
  135. if (!objdb_get_string (objdb,object_service_handle, "group", &value)) {
  136. main_config->group = strdup(value);
  137. }
  138. }
  139. /* Default user/group */
  140. if (!main_config->user)
  141. main_config->user = OPENAIS_USER;
  142. if (!main_config->group)
  143. main_config->group = OPENAIS_GROUP;
  144. if ((main_config->logmode & LOG_MODE_FILE) && main_config->logfile == 0) {
  145. error_reason = "logmode set to 'file' but no logfile specified";
  146. goto parse_error;
  147. }
  148. return 0;
  149. parse_error:
  150. sprintf (error_string_response,
  151. "parse error in config: %s.\n",
  152. error_reason);
  153. *error_string = error_string_response;
  154. return (-1);
  155. }