4
0

parse.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  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 res = 0;
  377. int line_number = 0;
  378. main_parse_t parse = MAIN_HEAD;
  379. int network_parsed = 0;
  380. int logging_parsed = 0;
  381. int key_parsed = 0;
  382. int timeout_parsed = 0;
  383. int event_parsed = 0;
  384. char *loc;
  385. int i;
  386. int parse_done = 0;
  387. char line[512];
  388. char *error_reason = error_string_response;
  389. memset (openais_config, 0, sizeof (struct openais_config));
  390. openais_config->interfaces = malloc (sizeof (struct totem_interface) * interface_max);
  391. if (openais_config->interfaces == 0) {
  392. parse_done = 1;
  393. *error_string = "Out of memory trying to allocate ethernet interface storage area";
  394. return -1;
  395. }
  396. memset (openais_config->interfaces, 0,
  397. sizeof (struct totem_interface) * interface_max);
  398. openais_config->mcast_addr.sin_family = AF_INET;
  399. fp = fopen ("/etc/ais/openais.conf", "r");
  400. if (fp == 0) {
  401. parse_done = 1;
  402. sprintf (error_reason, "Can't read file reason = (%s)\n", strerror (errno));
  403. *error_string = error_reason;
  404. return -1;
  405. }
  406. while (fgets (line, 255, fp)) {
  407. line_number += 1;
  408. line[strlen(line) - 1] = '\0';
  409. /*
  410. * Clear out white space and tabs
  411. */
  412. for (i = strlen (line) - 1; i > -1; i--) {
  413. if (line[i] == '\t' || line[i] == ' ') {
  414. line[i] = '\0';
  415. } else {
  416. break;
  417. }
  418. }
  419. /*
  420. * Clear out comments and empty lines
  421. */
  422. if (line[0] == '#' || line[0] == '\0') {
  423. continue;
  424. }
  425. line_number += 1;
  426. switch (parse) {
  427. case MAIN_HEAD:
  428. if (network_parsed == 0 && strstr_rs (line, "network{")) {
  429. network_parsed = 1;
  430. parse = MAIN_NETWORK;
  431. } else
  432. if (logging_parsed == 0 && strstr_rs (line, "logging{")) {
  433. logging_parsed = 1;
  434. parse = MAIN_LOGGING;
  435. } else
  436. if (key_parsed == 0 && strstr_rs (line, "key{")) {
  437. key_parsed = 1;
  438. parse = MAIN_KEY;
  439. } else
  440. if (timeout_parsed == 0 && strstr_rs (line, "timeout{")) {
  441. timeout_parsed = 1;
  442. parse = MAIN_TIMEOUT;
  443. } else
  444. if (event_parsed == 0 && strstr_rs (line, "event{")) {
  445. event_parsed = 1;
  446. parse = MAIN_EVENT;
  447. } else {
  448. goto parse_error;
  449. }
  450. break;
  451. case MAIN_NETWORK:
  452. if ((loc = strstr_rs (line, "mcastaddr:"))) {
  453. res = inet_aton (loc, &openais_config->mcast_addr.sin_addr);
  454. } else
  455. if ((loc = strstr_rs (line, "mcastport:"))) {
  456. res = openais_config->mcast_addr.sin_port = htons (atoi (loc));
  457. } else
  458. if ((loc = strstr_rs (line, "bindnetaddr:"))) {
  459. if (interface_max == openais_config->interface_count) {
  460. sprintf (error_reason,
  461. "%d is too many interfaces in /etc/ais/network.conf",
  462. openais_config->interface_count);
  463. goto parse_error;
  464. }
  465. res = inet_aton (loc,
  466. &openais_config->interfaces[openais_config->interface_count].bindnet.sin_addr);
  467. openais_config->interface_count += 1;
  468. } else
  469. if ((loc = strstr_rs (line, "}"))) {
  470. parse = MAIN_HEAD;
  471. res = 1; /* any nonzero is ok */
  472. } else {
  473. goto parse_error;
  474. }
  475. if (res == 0) {
  476. sprintf (error_reason, "invalid network address or port number\n");
  477. goto parse_error;
  478. }
  479. break;
  480. case MAIN_LOGGING:
  481. if ((loc = strstr_rs (line, "logoutput:"))) {
  482. if (strcmp (loc, "file") == 0) {
  483. openais_config->logmode |= LOG_MODE_FILE;
  484. } else
  485. if (strcmp (loc, "syslog") == 0) {
  486. openais_config->logmode |= LOG_MODE_SYSLOG;
  487. } else
  488. if (strcmp (loc, "stderr") == 0) {
  489. openais_config->logmode |= LOG_MODE_STDERR;
  490. } else {
  491. goto parse_error;
  492. }
  493. } else
  494. if ((loc = strstr_rs (line, "debug:"))) {
  495. if (strcmp (loc, "on") == 0) {
  496. openais_config->logmode |= LOG_MODE_DEBUG;
  497. } else
  498. if (strcmp (loc, "off") == 0) {
  499. openais_config->logmode &= ~LOG_MODE_DEBUG;
  500. } else {
  501. goto parse_error;
  502. }
  503. } else
  504. if ((loc = strstr_rs (line, "timestamp:"))) {
  505. if (strcmp (loc, "on") == 0) {
  506. openais_config->logmode |= LOG_MODE_TIMESTAMP;
  507. } else
  508. if (strcmp (loc, "off") == 0) {
  509. openais_config->logmode &= ~LOG_MODE_TIMESTAMP;
  510. } else {
  511. goto parse_error;
  512. }
  513. } else
  514. if ((loc = strstr_rs (line, "logfile:"))) {
  515. openais_config->logfile = strdup (loc);
  516. } else
  517. if ((loc = strstr_rs (line, "}"))) {
  518. parse = MAIN_HEAD;
  519. } else {
  520. goto parse_error;
  521. }
  522. break;
  523. case MAIN_TIMEOUT:
  524. if ((loc = strstr_rs (line, "token:"))) {
  525. openais_config->timeouts[TOTEM_TOKEN]= atoi(loc);
  526. } else if ((loc = strstr_rs (line, "token_retransmit:"))) {
  527. openais_config->timeouts[TOTEM_RETRANSMIT_TOKEN] = atoi(loc);
  528. } else if ((loc = strstr_rs (line, "hold:"))) {
  529. openais_config->timeouts[TOTEM_HOLD_TOKEN] = atoi(loc);
  530. } else if ((loc = strstr_rs (line, "retransmits_before_loss:"))) {
  531. openais_config->timeouts[TOTEM_RETRANSMITS_BEFORE_LOSS] = atoi(loc);
  532. } else if ((loc = strstr_rs (line, "join:"))) {
  533. openais_config->timeouts[TOTEM_JOIN] = atoi(loc);
  534. } else if ((loc = strstr_rs (line, "consensus:"))) {
  535. openais_config->timeouts[TOTEM_CONSENSUS] = atoi(loc);
  536. } else if ((loc = strstr_rs (line, "merge:"))) {
  537. openais_config->timeouts[TOTEM_MERGE] = atoi(loc);
  538. } else if ((loc = strstr_rs (line, "downcheck:"))) {
  539. openais_config->timeouts[TOTEM_DOWNCHECK] = atoi(loc);
  540. } else if ((loc = strstr_rs (line, "fail_recv_const:"))) {
  541. openais_config->timeouts[TOTEM_FAIL_RECV_CONST] = atoi(loc);
  542. } else if ((loc = strstr_rs (line, "}"))) {
  543. parse = MAIN_HEAD;
  544. } else {
  545. goto parse_error;
  546. }
  547. break;
  548. case MAIN_EVENT:
  549. if ((loc = strstr_rs (line, "delivery_queue_size:"))) {
  550. openais_config->evt_delivery_queue_size = atoi(loc);
  551. } else if ((loc = strstr_rs (line, "delivery_queue_resume:"))) {
  552. openais_config->evt_delivery_queue_resume = atoi(loc);
  553. } else if ((loc = strstr_rs (line, "}"))) {
  554. parse = MAIN_HEAD;
  555. } else {
  556. goto parse_error;
  557. }
  558. break;
  559. default:
  560. assert (0 == 1); /* SHOULDN'T HAPPEN */
  561. break;
  562. }
  563. }
  564. /*
  565. * Some error checking of parsed data to make sure its valid
  566. */
  567. parse_done = 1;
  568. if (openais_config->mcast_addr.sin_addr.s_addr == 0) {
  569. error_reason = "No multicast address specified";
  570. goto parse_error;
  571. }
  572. if (openais_config->mcast_addr.sin_port == 0) {
  573. error_reason = "No multicast port specified";
  574. goto parse_error;
  575. }
  576. if (openais_config->interface_count == 0) {
  577. error_reason = "No bindnet specified";
  578. goto parse_error;
  579. }
  580. if ((openais_config->logmode & LOG_MODE_FILE) && openais_config->logfile == 0) {
  581. error_reason = "logmode set to 'file' but no logfile specified";
  582. goto parse_error;
  583. }
  584. if (parse == MAIN_HEAD) {
  585. fclose (fp);
  586. return (0);
  587. } else {
  588. error_reason = "Missing closing brace";
  589. goto parse_error;
  590. }
  591. parse_error:
  592. if (parse_done) {
  593. sprintf (error_string_response,
  594. "parse error in /etc/ais/openais.conf: %s.\n", error_reason);
  595. } else {
  596. sprintf (error_string_response,
  597. "parse error in /etc/ais/openais.conf: %s (line %d).\n",
  598. error_reason, line_number);
  599. }
  600. *error_string = error_string_response;
  601. fclose (fp);
  602. return (-1);
  603. }