parse.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. /*
  2. * Copyright (c) 2002-2004 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/ais_types.h"
  43. #include "../include/list.h"
  44. #include "util.h"
  45. #include "parse.h"
  46. #include "mempool.h"
  47. #include "print.h"
  48. DECLARE_LIST_INIT (saAmfGroupHead);
  49. static char error_string_response[512];
  50. typedef enum {
  51. AMF_HEAD,
  52. AMF_GROUP,
  53. AMF_UNIT,
  54. AMF_PROTECTION,
  55. AMF_COMPONENT
  56. } amf_parse_t;
  57. typedef enum {
  58. MAIN_HEAD,
  59. MAIN_NETWORK,
  60. MAIN_LOGGING,
  61. MAIN_KEY,
  62. MAIN_TIMEOUT,
  63. MAIN_EVENT
  64. } main_parse_t;
  65. void setSaNameT (SaNameT *name, char *str) {
  66. strncpy ((char *)name->value, str, SA_MAX_NAME_LENGTH);
  67. if (strlen ((char *)name->value) > SA_MAX_NAME_LENGTH) {
  68. name->length = SA_MAX_NAME_LENGTH;
  69. } else {
  70. name->length = strlen (str);
  71. }
  72. }
  73. int SaNameTisEqual (SaNameT *str1, char *str2) {
  74. if (str1->length == strlen (str2)) {
  75. return ((strncmp ((char *)str1->value, (char *)str2,
  76. str1->length)) == 0);
  77. } else {
  78. return 0;
  79. }
  80. }
  81. struct saAmfComponent *findComponent (SaNameT *name)
  82. {
  83. struct list_head *AmfGroupList = 0;
  84. struct list_head *AmfUnitList = 0;
  85. struct list_head *AmfComponentList = 0;
  86. struct saAmfGroup *saAmfGroup = 0;
  87. struct saAmfUnit *AmfUnit = 0;
  88. struct saAmfComponent *AmfComponent = 0;
  89. int found = 0;
  90. /*
  91. * Search all groups
  92. */
  93. for (AmfGroupList = saAmfGroupHead.next;
  94. AmfGroupList != &saAmfGroupHead && found == 0;
  95. AmfGroupList = AmfGroupList->next) {
  96. saAmfGroup = list_entry (AmfGroupList,
  97. struct saAmfGroup, saAmfGroupList);
  98. /*
  99. * Search all units
  100. */
  101. for (AmfUnitList = saAmfGroup->saAmfUnitHead.next;
  102. AmfUnitList != &saAmfGroup->saAmfUnitHead && found == 0;
  103. AmfUnitList = AmfUnitList->next) {
  104. AmfUnit = list_entry (AmfUnitList,
  105. struct saAmfUnit, saAmfUnitList);
  106. /*
  107. * Search all components
  108. */
  109. for (AmfComponentList = AmfUnit->saAmfComponentHead.next;
  110. AmfComponentList != &AmfUnit->saAmfComponentHead && found == 0;
  111. AmfComponentList = AmfComponentList->next) {
  112. AmfComponent = list_entry (AmfComponentList,
  113. struct saAmfComponent, saAmfComponentList);
  114. if (name_match (name, &AmfComponent->name)) {
  115. found = 1;
  116. }
  117. }
  118. }
  119. }
  120. if (found) {
  121. return (AmfComponent);
  122. } else {
  123. return (0);
  124. }
  125. }
  126. char *
  127. strstr_rs (const char *haystack, const char *needle)
  128. {
  129. char *end_address;
  130. char *new_needle;
  131. new_needle = (char *)mempool_strdup (needle);
  132. new_needle[strlen(new_needle) - 1] = '\0';
  133. end_address = strstr (haystack, new_needle);
  134. if (end_address) {
  135. end_address += strlen (new_needle);
  136. end_address = strstr (end_address, needle + strlen (new_needle));
  137. }
  138. if (end_address) {
  139. end_address += 1; /* skip past { or = */
  140. do {
  141. if (*end_address == '\t' || *end_address == ' ') {
  142. end_address++;
  143. } else {
  144. break;
  145. }
  146. } while (*end_address != '\0');
  147. }
  148. mempool_free (new_needle);
  149. return (end_address);
  150. }
  151. extern int openais_amf_config_read (char **error_string)
  152. {
  153. char line[255];
  154. FILE *fp;
  155. amf_parse_t current_parse = AMF_HEAD;
  156. int line_number = 0;
  157. char *loc;
  158. int i;
  159. struct saAmfGroup *saAmfGroup = 0;
  160. struct saAmfUnit *saAmfUnit = 0;
  161. struct saAmfProtectionGroup *saAmfProtectionGroup = 0;
  162. struct saAmfComponent *saAmfComponent = 0;
  163. struct list_head *findAmfUnitList = 0;
  164. struct list_head *findAmfComponentList = 0;
  165. struct saAmfUnit *findAmfUnit = 0;
  166. struct saAmfComponent *findAmfComponent = 0;
  167. SaNameT componentName;
  168. fp = fopen ("/etc/ais/groups.conf", "r");
  169. if (fp == 0) {
  170. sprintf (error_string_response,
  171. "Can't read /etc/ais/groups.conf file reason = (%s).\n", strerror (errno));
  172. *error_string = error_string_response;
  173. return (-1);
  174. }
  175. while (fgets (line, 255, fp)) {
  176. line_number += 1;
  177. line[strlen(line) - 1] = '\0';
  178. /*
  179. * Clear out white space and tabs
  180. */
  181. for (i = strlen (line) - 1; i > -1; i--) {
  182. if (line[i] == '\t' || line[i] == ' ') {
  183. line[i] = '\0';
  184. } else {
  185. break;
  186. }
  187. }
  188. /*
  189. * Clear out comments and empty lines
  190. */
  191. if (line[0] == '#' || line[0] == '\0') {
  192. continue;
  193. }
  194. switch (current_parse) {
  195. case AMF_HEAD:
  196. if (strstr_rs (line, "group{")) {
  197. saAmfGroup = (struct saAmfGroup *)mempool_malloc (sizeof (struct saAmfGroup));
  198. memset (saAmfGroup, 0, sizeof (struct saAmfGroup));
  199. list_init (&saAmfGroup->saAmfGroupList);
  200. list_init (&saAmfGroup->saAmfUnitHead);
  201. list_init (&saAmfGroup->saAmfProtectionGroupHead);
  202. list_add (&saAmfGroup->saAmfGroupList, &saAmfGroupHead);
  203. current_parse = AMF_GROUP;
  204. } else
  205. if (strcmp (line, "") == 0) {
  206. } else {
  207. goto parse_error;
  208. }
  209. break;
  210. case AMF_GROUP:
  211. if ((loc = strstr_rs (line, "name=")) != 0) {
  212. setSaNameT (&saAmfGroup->name, loc);
  213. } else
  214. if ((loc = strstr_rs (line, "model=")) != 0) {
  215. if (strcmp (loc, "2n") == 0) {
  216. saAmfGroup->model = GROUPCAPABILITYMODEL_2N;
  217. } else
  218. if (strcmp (loc, "nplusm") == 0) {
  219. saAmfGroup->model = GROUPCAPABILITYMODEL_NPLUSM;
  220. } else
  221. if (strcmp (loc, "nway") == 0) {
  222. printf ("nway redundancy model not supported.\n");
  223. goto parse_error;
  224. } else
  225. if (strcmp (loc, "nwayactive") == 0) {
  226. printf ("nway active redundancy model not supported.\n");
  227. goto parse_error;
  228. } else
  229. if (strcmp (loc, "noredundancy") == 0) {
  230. saAmfGroup->model = GROUPCAPABILITYMODEL_NOREDUNDANCY;
  231. } else {
  232. goto parse_error;
  233. }
  234. } else
  235. if ((loc = strstr_rs (line, "active-units=")) != 0) {
  236. saAmfGroup->saAmfActiveUnitsDesired = atoi (loc);
  237. } else
  238. if ((loc = strstr_rs (line, "backup-units=")) != 0) {
  239. saAmfGroup->saAmfStandbyUnitsDesired = atoi (loc);
  240. } else
  241. if (strstr_rs (line, "unit{")) {
  242. saAmfUnit = (struct saAmfUnit *)mempool_malloc (sizeof (struct saAmfUnit));
  243. memset (saAmfUnit, 0, sizeof (struct saAmfUnit));
  244. saAmfUnit->saAmfGroup = saAmfGroup;
  245. list_init (&saAmfUnit->saAmfComponentHead);
  246. list_add (&saAmfUnit->saAmfUnitList, &saAmfGroup->saAmfUnitHead);
  247. current_parse = AMF_UNIT;
  248. } else
  249. if (strstr_rs (line, "protection{")) {
  250. saAmfProtectionGroup = (struct saAmfProtectionGroup *)mempool_malloc (sizeof (struct saAmfProtectionGroup));
  251. memset (saAmfProtectionGroup, 0, sizeof (struct saAmfProtectionGroup));
  252. list_init (&saAmfProtectionGroup->saAmfMembersHead);
  253. list_init (&saAmfProtectionGroup->saAmfProtectionGroupList);
  254. list_add (&saAmfProtectionGroup->saAmfProtectionGroupList, &saAmfGroup->saAmfProtectionGroupHead);
  255. current_parse = AMF_PROTECTION;
  256. } else
  257. if (strstr_rs (line, "}")) {
  258. current_parse = AMF_HEAD;
  259. } else {
  260. goto parse_error;
  261. }
  262. break;
  263. case AMF_UNIT:
  264. if ((loc = strstr_rs (line, "name=")) != 0) {
  265. setSaNameT (&saAmfUnit->name, loc);
  266. } else
  267. if ((loc = strstr_rs (line, "component{")) != 0) {
  268. saAmfComponent = (struct saAmfComponent *)mempool_malloc (sizeof (struct saAmfComponent));
  269. memset (saAmfComponent, 0, sizeof (struct saAmfComponent));
  270. saAmfComponent->saAmfUnit = saAmfUnit;
  271. saAmfComponent->currentReadinessState = SA_AMF_OUT_OF_SERVICE;
  272. saAmfComponent->newReadinessState = SA_AMF_OUT_OF_SERVICE;
  273. saAmfComponent->currentHAState = SA_AMF_QUIESCED;
  274. saAmfComponent->newHAState = SA_AMF_QUIESCED;
  275. saAmfComponent->healthcheckInterval = 100;
  276. list_init (&saAmfComponent->saAmfComponentList);
  277. list_init (&saAmfComponent->saAmfProtectionGroupList);
  278. list_add (&saAmfComponent->saAmfComponentList, &saAmfUnit->saAmfComponentHead);
  279. current_parse = AMF_COMPONENT;
  280. } else
  281. if (strstr_rs (line, "}")) {
  282. current_parse = AMF_GROUP;
  283. } else {
  284. goto parse_error;
  285. }
  286. break;
  287. case AMF_COMPONENT:
  288. if ((loc = strstr_rs (line, "name=")) != 0) {
  289. setSaNameT (&saAmfComponent->name, loc);
  290. } else
  291. if ((loc = strstr_rs (line, "model=")) != 0) {
  292. if (strcmp (loc, "x_active_and_y_standby") == 0) {
  293. saAmfComponent->componentCapabilityModel = SA_AMF_COMPONENT_CAPABILITY_X_ACTIVE_AND_Y_STANDBY;
  294. } else
  295. if (strcmp (loc, "x_active_or_y_standby") == 0) {
  296. saAmfComponent->componentCapabilityModel = SA_AMF_COMPONENT_CAPABILITY_X_ACTIVE_OR_Y_STANDBY;
  297. } else
  298. if (strcmp (loc, "1_active_or_y_standby") == 0) {
  299. saAmfComponent->componentCapabilityModel = SA_AMF_COMPONENT_CAPABILITY_1_ACTIVE_OR_Y_STANDBY;
  300. } else
  301. if (strcmp (loc, "1_active_or_1_standby") == 0) {
  302. saAmfComponent->componentCapabilityModel = SA_AMF_COMPONENT_CAPABILITY_1_ACTIVE_OR_1_STANDBY;
  303. } else
  304. if (strcmp (loc, "x_active") == 0) {
  305. saAmfComponent->componentCapabilityModel = SA_AMF_COMPONENT_CAPABILITY_X_ACTIVE;
  306. } else
  307. if (strcmp (loc, "1_active") == 0) {
  308. saAmfComponent->componentCapabilityModel = SA_AMF_COMPONENT_CAPABILITY_1_ACTIVE;
  309. } else
  310. if (strcmp (loc, "no_active") == 0) {
  311. saAmfComponent->componentCapabilityModel = SA_AMF_COMPONENT_CAPABILITY_NO_ACTIVE;
  312. } else {
  313. goto parse_error;
  314. }
  315. } else
  316. if (strstr_rs (line, "}")) {
  317. current_parse = AMF_UNIT;
  318. } else {
  319. goto parse_error;
  320. }
  321. break;
  322. case AMF_PROTECTION:
  323. if ((loc = strstr_rs (line, "name=")) != 0) {
  324. setSaNameT (&saAmfProtectionGroup->name, loc);
  325. } else
  326. if ((loc = strstr_rs (line, "member=")) != 0) {
  327. for (findAmfUnitList = saAmfGroup->saAmfUnitHead.next;
  328. findAmfUnitList != &saAmfGroup->saAmfUnitHead;
  329. findAmfUnitList = findAmfUnitList->next) {
  330. findAmfUnit = list_entry (findAmfUnitList,
  331. struct saAmfUnit, saAmfUnitList);
  332. for (findAmfComponentList = findAmfUnit->saAmfComponentHead.next;
  333. findAmfComponentList != &findAmfUnit->saAmfComponentHead;
  334. findAmfComponentList = findAmfComponentList->next) {
  335. findAmfComponent = list_entry (findAmfComponentList,
  336. struct saAmfComponent, saAmfComponentList);
  337. if (SaNameTisEqual (&findAmfComponent->name, loc)) {
  338. list_add (&findAmfComponent->saAmfProtectionGroupList,
  339. &saAmfProtectionGroup->saAmfMembersHead);
  340. }
  341. }
  342. /*
  343. * Connect component to protection group
  344. */
  345. setSaNameT (&componentName, loc);
  346. saAmfComponent = findComponent (&componentName);
  347. saAmfComponent->saAmfProtectionGroup = saAmfProtectionGroup;
  348. }
  349. } else
  350. if (strstr_rs (line, "}")) {
  351. current_parse = AMF_GROUP;
  352. } else {
  353. goto parse_error;
  354. }
  355. break;
  356. default:
  357. printf ("Invalid state\n");
  358. goto parse_error;
  359. break;
  360. }
  361. }
  362. fclose (fp);
  363. return (0);
  364. parse_error:
  365. sprintf (error_string_response,
  366. "parse error at /etc/groups.conf:%d.\n", line_number);
  367. *error_string = error_string_response;
  368. fclose (fp);
  369. return (-1);
  370. }
  371. extern int openais_main_config_read (char **error_string,
  372. struct openais_config *openais_config,
  373. int interface_max)
  374. {
  375. FILE *fp;
  376. int line_number = 0;
  377. main_parse_t parse = MAIN_HEAD;
  378. int network_parsed = 0;
  379. int logging_parsed = 0;
  380. int key_parsed = 0;
  381. int timeout_parsed = 0;
  382. int event_parsed = 0;
  383. char *loc;
  384. int i;
  385. int parse_done = 0;
  386. char line[512];
  387. char *error_reason = error_string_response;
  388. memset (openais_config, 0, sizeof (struct openais_config));
  389. openais_config->interfaces = malloc (sizeof (struct totem_interface) * interface_max);
  390. if (openais_config->interfaces == 0) {
  391. parse_done = 1;
  392. *error_string = "Out of memory trying to allocate ethernet interface storage area";
  393. return -1;
  394. }
  395. memset (openais_config->interfaces, 0,
  396. sizeof (struct totem_interface) * interface_max);
  397. openais_config->mcast_addr.sin_family = AF_INET;
  398. fp = fopen ("/etc/ais/openais.conf", "r");
  399. if (fp == 0) {
  400. parse_done = 1;
  401. sprintf (error_reason, "Can't read file reason = (%s)\n", strerror (errno));
  402. *error_string = error_reason;
  403. return -1;
  404. }
  405. while (fgets (line, 255, fp)) {
  406. line_number += 1;
  407. line[strlen(line) - 1] = '\0';
  408. /*
  409. * Clear out white space and tabs
  410. */
  411. for (i = strlen (line) - 1; i > -1; i--) {
  412. if (line[i] == '\t' || line[i] == ' ') {
  413. line[i] = '\0';
  414. } else {
  415. break;
  416. }
  417. }
  418. /*
  419. * Clear out comments and empty lines
  420. */
  421. if (line[0] == '#' || line[0] == '\0') {
  422. continue;
  423. }
  424. line_number += 1;
  425. switch (parse) {
  426. case MAIN_HEAD:
  427. if (network_parsed == 0 && strstr_rs (line, "network{")) {
  428. network_parsed = 1;
  429. parse = MAIN_NETWORK;
  430. } else
  431. if (logging_parsed == 0 && strstr_rs (line, "logging{")) {
  432. logging_parsed = 1;
  433. parse = MAIN_LOGGING;
  434. } else
  435. if (key_parsed == 0 && strstr_rs (line, "key{")) {
  436. key_parsed = 1;
  437. parse = MAIN_KEY;
  438. } else
  439. if (timeout_parsed == 0 && strstr_rs (line, "timeout{")) {
  440. timeout_parsed = 1;
  441. parse = MAIN_TIMEOUT;
  442. } else
  443. if (event_parsed == 0 && strstr_rs (line, "event{")) {
  444. event_parsed = 1;
  445. parse = MAIN_EVENT;
  446. } else {
  447. goto parse_error;
  448. }
  449. break;
  450. case MAIN_NETWORK:
  451. if ((loc = strstr_rs (line, "mcastaddr:"))) {
  452. inet_aton (loc, &openais_config->mcast_addr.sin_addr);
  453. } else
  454. if ((loc = strstr_rs (line, "mcastport:"))) {
  455. openais_config->mcast_addr.sin_port = htons (atoi (loc));
  456. } else
  457. if ((loc = strstr_rs (line, "bindnetaddr:"))) {
  458. if (interface_max == openais_config->interface_count) {
  459. sprintf (error_reason,
  460. "%d is too many interfaces in /etc/ais/network.conf",
  461. openais_config->interface_count);
  462. goto parse_error;
  463. }
  464. inet_aton (loc,
  465. &openais_config->interfaces[openais_config->interface_count].bindnet.sin_addr);
  466. openais_config->interface_count += 1;
  467. } else
  468. if ((loc = strstr_rs (line, "}"))) {
  469. parse = MAIN_HEAD;
  470. } else {
  471. goto parse_error;
  472. }
  473. break;
  474. case MAIN_LOGGING:
  475. if ((loc = strstr_rs (line, "logoutput:"))) {
  476. if (strcmp (loc, "file") == 0) {
  477. openais_config->logmode |= LOG_MODE_FILE;
  478. } else
  479. if (strcmp (loc, "syslog") == 0) {
  480. openais_config->logmode |= LOG_MODE_SYSLOG;
  481. } else
  482. if (strcmp (loc, "stderr") == 0) {
  483. openais_config->logmode |= LOG_MODE_STDERR;
  484. } else {
  485. goto parse_error;
  486. }
  487. } else
  488. if ((loc = strstr_rs (line, "debug:"))) {
  489. if (strcmp (loc, "on") == 0) {
  490. openais_config->logmode |= LOG_MODE_DEBUG;
  491. } else
  492. if (strcmp (loc, "off") == 0) {
  493. openais_config->logmode &= ~LOG_MODE_DEBUG;
  494. } else {
  495. goto parse_error;
  496. }
  497. } else
  498. if ((loc = strstr_rs (line, "timestamp:"))) {
  499. if (strcmp (loc, "on") == 0) {
  500. openais_config->logmode |= LOG_MODE_TIMESTAMP;
  501. } else
  502. if (strcmp (loc, "off") == 0) {
  503. openais_config->logmode &= ~LOG_MODE_TIMESTAMP;
  504. } else {
  505. goto parse_error;
  506. }
  507. } else
  508. if ((loc = strstr_rs (line, "logfile:"))) {
  509. openais_config->logfile = strdup (loc);
  510. } else
  511. if ((loc = strstr_rs (line, "}"))) {
  512. parse = MAIN_HEAD;
  513. } else {
  514. goto parse_error;
  515. }
  516. break;
  517. case MAIN_TIMEOUT:
  518. if ((loc = strstr_rs (line, "token:"))) {
  519. openais_config->timeouts[TOTEM_TOKEN]= atoi(loc);
  520. } else if ((loc = strstr_rs (line, "retransmit:"))) {
  521. openais_config->timeouts[TOTEM_RETRANSMIT_TOKEN] = atoi(loc);
  522. } else if ((loc = strstr_rs (line, "join:"))) {
  523. openais_config->timeouts[TOTEM_JOIN] = atoi(loc);
  524. } else if ((loc = strstr_rs (line, "consensus:"))) {
  525. openais_config->timeouts[TOTEM_CONSENSUS] = atoi(loc);
  526. } else if ((loc = strstr_rs (line, "merge:"))) {
  527. openais_config->timeouts[TOTEM_MERGE] = atoi(loc);
  528. } else if ((loc = strstr_rs (line, "downcheck:"))) {
  529. openais_config->timeouts[TOTEM_DOWNCHECK] = atoi(loc);
  530. } else if ((loc = strstr_rs (line, "fail_recv_const:"))) {
  531. openais_config->timeouts[TOTEM_FAIL_RECV_CONST] = atoi(loc);
  532. } else if ((loc = strstr_rs (line, "}"))) {
  533. parse = MAIN_HEAD;
  534. } else {
  535. goto parse_error;
  536. }
  537. break;
  538. case MAIN_EVENT:
  539. if ((loc = strstr_rs (line, "delivery_queue_size:"))) {
  540. openais_config->evt_delivery_queue_size = atoi(loc);
  541. } else if ((loc = strstr_rs (line, "delivery_queue_resume:"))) {
  542. openais_config->evt_delivery_queue_resume = atoi(loc);
  543. } else if ((loc = strstr_rs (line, "}"))) {
  544. parse = MAIN_HEAD;
  545. } else {
  546. goto parse_error;
  547. }
  548. break;
  549. default:
  550. assert (0 == 1); /* SHOULDN'T HAPPEN */
  551. break;
  552. }
  553. }
  554. /*
  555. * Some error checking of parsed data to make sure its valid
  556. */
  557. parse_done = 1;
  558. if (openais_config->mcast_addr.sin_addr.s_addr == 0) {
  559. error_reason = "No multicast address specified";
  560. goto parse_error;
  561. }
  562. if (openais_config->mcast_addr.sin_port == 0) {
  563. error_reason = "No multicast port specified";
  564. goto parse_error;
  565. }
  566. if (openais_config->interface_count == 0) {
  567. error_reason = "No bindnet specified";
  568. goto parse_error;
  569. }
  570. if ((openais_config->logmode & LOG_MODE_FILE) && openais_config->logfile == 0) {
  571. error_reason = "logmode set to 'file' but no logfile specified";
  572. goto parse_error;
  573. }
  574. if (parse == MAIN_HEAD) {
  575. fclose (fp);
  576. return (0);
  577. } else {
  578. error_reason = "Missing closing brace";
  579. goto parse_error;
  580. }
  581. parse_error:
  582. if (parse_done) {
  583. sprintf (error_string_response,
  584. "parse error in /etc/ais/openais.conf: %s.\n", error_reason);
  585. } else {
  586. sprintf (error_string_response,
  587. "parse error in /etc/ais/openais.conf: %s (line %d).\n",
  588. error_reason, line_number);
  589. }
  590. *error_string = error_string_response;
  591. fclose (fp);
  592. return (-1);
  593. }