amfconfig.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  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/saAmf.h"
  44. #include "../include/ipc_amf.h"
  45. #include "../include/list.h"
  46. #include "util.h"
  47. #include "amfconfig.h"
  48. #include "mempool.h"
  49. #include "print.h"
  50. #include "totem.h"
  51. DECLARE_LIST_INIT (amf_groupHead);
  52. DECLARE_LIST_INIT (amf_healthcheck_head);
  53. static char error_string_response[512];
  54. typedef enum {
  55. AMF_HEAD,
  56. AMF_GROUP,
  57. AMF_UNIT,
  58. AMF_COMPONENT,
  59. AMF_COMPONENT_CSI_TYPE_NAMES,
  60. AMF_SERVICEINSTANCE,
  61. AMF_SERVICEINSTANCE_CSIDESCRIPTOR,
  62. AMF_SERVICEINSTANCE_CSIDESCRIPTOR_NAMEVALUE,
  63. AMF_HEALTHCHECK
  64. } amf_parse_t;
  65. typedef enum {
  66. MAIN_HEAD,
  67. MAIN_NETWORK,
  68. MAIN_LOGGING,
  69. MAIN_KEY,
  70. MAIN_TIMEOUT,
  71. MAIN_EVENT
  72. } main_parse_t;
  73. void setSaNameT (SaNameT *name, char *str) {
  74. strncpy ((char *)name->value, str, SA_MAX_NAME_LENGTH);
  75. if (strlen ((char *)name->value) > SA_MAX_NAME_LENGTH) {
  76. name->length = SA_MAX_NAME_LENGTH;
  77. } else {
  78. name->length = strlen (str);
  79. }
  80. }
  81. int SaNameTisEqual (SaNameT *str1, char *str2) {
  82. if (str1->length == strlen (str2)) {
  83. return ((strncmp ((char *)str1->value, (char *)str2,
  84. str1->length)) == 0);
  85. } else {
  86. return 0;
  87. }
  88. }
  89. struct amf_healthcheck *find_healthcheck (SaAmfHealthcheckKeyT *key)
  90. {
  91. struct amf_healthcheck *healthcheck;
  92. struct amf_healthcheck *ret_healthcheck = 0;
  93. struct list_head *list;
  94. for (list = amf_healthcheck_head.next;
  95. list != &amf_healthcheck_head;
  96. list = list->next) {
  97. healthcheck = list_entry (list,
  98. struct amf_healthcheck, list);
  99. if (memcmp (key, &healthcheck->key, sizeof (SaAmfHealthcheckKeyT)) == 0) {
  100. ret_healthcheck = healthcheck;
  101. break;
  102. }
  103. }
  104. return (ret_healthcheck);
  105. }
  106. struct amf_comp *find_comp (SaNameT *name)
  107. {
  108. struct list_head *list_group = 0;
  109. struct list_head *list_unit = 0;
  110. struct list_head *AmfComponentList = 0;
  111. struct amf_group *amf_group = 0;
  112. struct amf_unit *amf_unit = 0;
  113. struct amf_comp *AmfComponent = 0;
  114. int found = 0;
  115. /*
  116. * Search all groups
  117. */
  118. for (list_group = amf_groupHead.next;
  119. list_group != &amf_groupHead && found == 0;
  120. list_group = list_group->next) {
  121. amf_group = list_entry (list_group,
  122. struct amf_group, group_list);
  123. /*
  124. * Search all units
  125. */
  126. for (list_unit = amf_group->unit_head.next;
  127. list_unit != &amf_group->unit_head && found == 0;
  128. list_unit = list_unit->next) {
  129. amf_unit = list_entry (list_unit,
  130. struct amf_unit, unit_list);
  131. /*
  132. * Search all components
  133. */
  134. for (AmfComponentList = amf_unit->comp_head.next;
  135. AmfComponentList != &amf_unit->comp_head && found == 0;
  136. AmfComponentList = AmfComponentList->next) {
  137. AmfComponent = list_entry (AmfComponentList,
  138. struct amf_comp, comp_list);
  139. if (name_match (name, &AmfComponent->name)) {
  140. found = 1;
  141. }
  142. }
  143. }
  144. }
  145. if (found) {
  146. return (AmfComponent);
  147. } else {
  148. return (0);
  149. }
  150. }
  151. struct amf_unit *find_unit (SaNameT *name)
  152. {
  153. struct list_head *list_group = 0;
  154. struct list_head *list_unit = 0;
  155. struct amf_group *amf_group = 0;
  156. struct amf_unit *amf_unit = 0;
  157. int found = 0;
  158. /*
  159. * Search all groups
  160. */
  161. for (list_group = amf_groupHead.next;
  162. list_group != &amf_groupHead && found == 0;
  163. list_group = list_group->next) {
  164. amf_group = list_entry (list_group,
  165. struct amf_group, group_list);
  166. /*
  167. * Search all units
  168. */
  169. for (list_unit = amf_group->unit_head.next;
  170. list_unit != &amf_group->unit_head && found == 0;
  171. list_unit = list_unit->next) {
  172. amf_unit = list_entry (list_unit,
  173. struct amf_unit, unit_list);
  174. if (name_match (name, &amf_unit->name)) {
  175. found = 1;
  176. }
  177. }
  178. }
  179. if (found) {
  180. return (amf_unit);
  181. } else {
  182. return (0);
  183. }
  184. }
  185. static char *strstr_rs (const char *haystack, const char *needle)
  186. {
  187. char *end_address;
  188. char *new_needle;
  189. new_needle = (char *)mempool_strdup (needle);
  190. new_needle[strlen(new_needle) - 1] = '\0';
  191. end_address = strstr (haystack, new_needle);
  192. if (end_address) {
  193. end_address += strlen (new_needle);
  194. end_address = strstr (end_address, needle + strlen (new_needle));
  195. }
  196. if (end_address) {
  197. end_address += 1; /* skip past { or = */
  198. do {
  199. if (*end_address == '\t' || *end_address == ' ') {
  200. end_address++;
  201. } else {
  202. break;
  203. }
  204. } while (*end_address != '\0');
  205. }
  206. mempool_free (new_needle);
  207. return (end_address);
  208. }
  209. extern int openais_amf_config_read (char **error_string)
  210. {
  211. char line[255];
  212. FILE *fp;
  213. amf_parse_t current_parse = AMF_HEAD;
  214. int line_number = 0;
  215. char *loc;
  216. int i;
  217. struct amf_group *amf_group = 0;
  218. struct amf_unit *amf_unit = 0;
  219. struct amf_comp *amf_comp = 0;
  220. struct amf_si *amf_si = 0;
  221. struct amf_healthcheck *amf_healthcheck = 0;
  222. struct amf_comp_csi_type_name *csi_type_name = 0;
  223. struct amf_csi *amf_csi = 0;
  224. struct amf_csi_name_value *csi_name_value;
  225. fp = fopen (OPENAIS_CONFDIR "/groups.conf", "r");
  226. if (fp == 0) {
  227. sprintf (error_string_response,
  228. "Can't read %s/groups.conf file reason = (%s).\n",
  229. OPENAIS_CONFDIR, strerror (errno));
  230. *error_string = error_string_response;
  231. return (-1);
  232. }
  233. while (fgets (line, 255, fp)) {
  234. line_number += 1;
  235. line[strlen(line) - 1] = '\0';
  236. /*
  237. * Clear out comments and empty lines
  238. */
  239. if (line[0] == '#' || line[0] == '\0' || line[0] == '\n') {
  240. continue;
  241. }
  242. /*
  243. * Clear out white space and tabs
  244. */
  245. for (i = strlen (line) - 1; i > -1; i--) {
  246. if (line[i] == '\t' || line[i] == ' ') {
  247. line[i] = '\0';
  248. } else {
  249. break;
  250. }
  251. }
  252. switch (current_parse) {
  253. case AMF_HEAD:
  254. if (strstr_rs (line, "group{")) {
  255. amf_group = (struct amf_group *)mempool_malloc (sizeof (struct amf_group));
  256. memset (amf_group, 0, sizeof (struct amf_group));
  257. list_init (&amf_group->group_list);
  258. list_init (&amf_group->unit_head);
  259. list_init (&amf_group->si_head);
  260. list_add (&amf_group->group_list, &amf_groupHead);
  261. memset (amf_group->clccli_path, 0, sizeof (&amf_unit->clccli_path));
  262. memset (amf_group->binary_path, 0, sizeof (&amf_unit->binary_path));
  263. current_parse = AMF_GROUP;
  264. } else
  265. if (strstr_rs (line, "healthcheck{")) {
  266. amf_healthcheck = (struct amf_healthcheck *)mempool_malloc (sizeof (struct amf_healthcheck));
  267. memset (amf_healthcheck, 0, sizeof (struct amf_healthcheck));
  268. list_init (&amf_healthcheck->list);
  269. list_add_tail (&amf_healthcheck->list,
  270. &amf_healthcheck_head);
  271. current_parse = AMF_HEALTHCHECK;
  272. } else {
  273. goto parse_error;
  274. }
  275. break;
  276. case AMF_GROUP:
  277. if ((loc = strstr_rs (line, "name=")) != 0) {
  278. setSaNameT (&amf_group->name, loc);
  279. } else
  280. if ((loc = strstr_rs (line, "model=")) != 0) {
  281. if (strcmp (loc, "2n") == 0) {
  282. amf_group->model = SA_AMF_2N_REDUNDANCY_MODEL;
  283. } else
  284. if (strcmp (loc, "nplusm") == 0) {
  285. amf_group->model = SA_AMF_NPM_REDUNDANCY_MODEL;
  286. } else
  287. if (strcmp (loc, "nway") == 0) {
  288. printf ("nway redundancy model not supported.\n");
  289. goto parse_error;
  290. } else
  291. if (strcmp (loc, "nwayactive") == 0) {
  292. printf ("nway active redundancy model not supported.\n");
  293. goto parse_error;
  294. } else
  295. if (strcmp (loc, "noredundancy") == 0) {
  296. amf_group->model = SA_AMF_NO_REDUNDANCY_MODEL;
  297. } else {
  298. goto parse_error;
  299. }
  300. } else
  301. if ((loc = strstr_rs (line, "preferred-active-units=")) != 0) {
  302. amf_group->preferred_active_units = atoi (loc);
  303. } else
  304. if ((loc = strstr_rs (line, "preferred-standby-units=")) != 0) {
  305. amf_group->preferred_standby_units = atoi (loc);
  306. } else
  307. if ((loc = strstr_rs (line, "maximum-active-instances=")) != 0) {
  308. amf_group->maximum_active_instances = atoi (loc);
  309. } else
  310. if ((loc = strstr_rs (line, "maximum-standby-instances=")) != 0) {
  311. amf_group->maximum_standby_instances = atoi (loc);
  312. } else
  313. if ((loc = strstr_rs (line, "clccli_path=")) != 0) {
  314. strcpy (amf_group->clccli_path, loc);
  315. } else
  316. if ((loc = strstr_rs (line, "binary_path=")) != 0) {
  317. strcpy (amf_group->binary_path, loc);
  318. } else
  319. if ((loc = strstr_rs (line, "component_restart_probation=")) != 0) {
  320. amf_group->component_restart_probation = atoi (loc);
  321. printf ("restart probation %d\n", amf_group->component_restart_probation);
  322. } else
  323. if ((loc = strstr_rs (line, "component_restart_max=")) != 0) {
  324. amf_group->component_restart_max = atoi (loc);
  325. printf ("restart max %d\n", amf_group->component_restart_max);
  326. } else
  327. if ((loc = strstr_rs (line, "unit_restart_probation=")) != 0) {
  328. amf_group->unit_restart_probation = atoi (loc);
  329. printf ("unit restart probation %d\n", amf_group->unit_restart_probation);
  330. } else
  331. if ((loc = strstr_rs (line, "unit_restart_max=")) != 0) {
  332. amf_group->unit_restart_max = atoi (loc);
  333. printf ("unit restart max %d\n", amf_group->unit_restart_max);
  334. } else
  335. if (strstr_rs (line, "unit{")) {
  336. amf_unit = (struct amf_unit *)mempool_malloc (sizeof (struct amf_unit));
  337. memset (amf_unit, 0, sizeof (struct amf_unit));
  338. amf_unit->amf_group = amf_group;
  339. amf_unit->operational_state = SA_AMF_OPERATIONAL_DISABLED;
  340. amf_unit->presence_state = SA_AMF_PRESENCE_UNINSTANTIATED;
  341. list_init (&amf_unit->comp_head);
  342. list_init (&amf_unit->si_head);
  343. amf_unit->escalation_level = ESCALATION_LEVEL_NO_ESCALATION;
  344. amf_unit->restart_count = 0;
  345. list_add_tail (&amf_unit->unit_list, &amf_group->unit_head);
  346. memset (amf_unit->clccli_path, 0, sizeof (&amf_unit->clccli_path));
  347. memset (amf_unit->binary_path, 0, sizeof (&amf_unit->binary_path));
  348. current_parse = AMF_UNIT;
  349. } else
  350. if (strstr_rs (line, "serviceinstance{")) {
  351. amf_si = (struct amf_si *)mempool_malloc (sizeof (struct amf_si));
  352. memset (amf_si, 0, sizeof (struct amf_si));
  353. list_init (&amf_si->csi_head);
  354. list_init (&amf_si->unit_list);
  355. list_init (&amf_si->pg_head);
  356. list_add_tail (&amf_si->si_list, &amf_group->si_head);
  357. amf_si->group = amf_group;
  358. current_parse = AMF_SERVICEINSTANCE;
  359. } else
  360. if (strstr_rs (line, "}")) {
  361. current_parse = AMF_HEAD;
  362. } else {
  363. goto parse_error;
  364. }
  365. break;
  366. case AMF_UNIT:
  367. if ((loc = strstr_rs (line, "name=")) != 0) {
  368. setSaNameT (&amf_unit->name, loc);
  369. } else
  370. if ((loc = strstr_rs (line, "component{")) != 0) {
  371. amf_comp = (struct amf_comp *)mempool_malloc (sizeof (struct amf_comp));
  372. memset (amf_comp, 0, sizeof (struct amf_comp));
  373. amf_comp->unit = amf_unit;
  374. amf_comp->operational_state = SA_AMF_OPERATIONAL_DISABLED;
  375. amf_comp->presence_state = SA_AMF_PRESENCE_UNINSTANTIATED;
  376. list_init (&amf_comp->comp_list);
  377. list_init (&amf_comp->healthcheck_list);
  378. list_init (&amf_comp->csi_type_name_head);
  379. list_add_tail (&amf_comp->comp_list, &amf_unit->comp_head);
  380. memset (amf_comp->clccli_path, 0, sizeof (&amf_comp->clccli_path));
  381. memset (amf_comp->binary_path, 0, sizeof (&amf_unit->binary_path));
  382. memset (amf_comp->binary_name, 0, sizeof (&amf_comp->binary_name));
  383. current_parse = AMF_COMPONENT;
  384. } else
  385. if ((loc = strstr_rs (line, "clccli_path=")) != 0) {
  386. strcpy (amf_unit->clccli_path, loc);
  387. } else
  388. if ((loc = strstr_rs (line, "binary_path=")) != 0) {
  389. strcpy (amf_unit->binary_path, loc);
  390. } else
  391. if (strstr_rs (line, "}")) {
  392. current_parse = AMF_GROUP;
  393. } else {
  394. goto parse_error;
  395. }
  396. break;
  397. case AMF_COMPONENT:
  398. if ((loc = strstr_rs (line, "name=")) != 0) {
  399. setSaNameT (&amf_comp->name, loc);
  400. } else
  401. #ifdef COMPILE_OUT
  402. if ((loc = strstr_rs (line, "model=")) != 0) {
  403. if (strcmp (loc, "x_active_and_y_standby") == 0) {
  404. amf_comp->componentCapabilityModel = SA_AMF_COMPONENT_CAPABILITY_X_ACTIVE_AND_Y_STANDBY;
  405. } else
  406. if (strcmp (loc, "x_active_or_y_standby") == 0) {
  407. amf_comp->componentCapabilityModel = SA_AMF_COMPONENT_CAPABILITY_X_ACTIVE_OR_Y_STANDBY;
  408. } else
  409. if (strcmp (loc, "1_active_or_y_standby") == 0) {
  410. amf_comp->componentCapabilityModel = SA_AMF_COMPONENT_CAPABILITY_1_ACTIVE_OR_Y_STANDBY;
  411. } else
  412. if (strcmp (loc, "1_active_or_1_standby") == 0) {
  413. amf_comp->componentCapabilityModel = SA_AMF_COMPONENT_CAPABILITY_1_ACTIVE_OR_1_STANDBY;
  414. } else
  415. if (strcmp (loc, "x_active") == 0) {
  416. amf_comp->componentCapabilityModel = SA_AMF_COMPONENT_CAPABILITY_X_ACTIVE;
  417. } else
  418. if (strcmp (loc, "1_active") == 0) {
  419. amf_comp->componentCapabilityModel = SA_AMF_COMPONENT_CAPABILITY_1_ACTIVE;
  420. } else
  421. if (strcmp (loc, "no_active") == 0) {
  422. amf_comp->componentCapabilityModel = SA_AMF_COMPONENT_CAPABILITY_NO_ACTIVE;
  423. } else {
  424. goto parse_error;
  425. }
  426. } else
  427. #endif
  428. if ((loc = strstr_rs(line, "comptype=")) != 0) {
  429. if (strstr (line, "sa_aware")) {
  430. amf_comp->comptype = clc_component_sa_aware;
  431. } else
  432. if (strstr (line, "proxied_pre")) {
  433. amf_comp->comptype = clc_component_proxied_pre;
  434. } else
  435. if (strstr (line, "proxied_non_pre")) {
  436. amf_comp->comptype = clc_component_proxied_non_pre;
  437. } else
  438. if (strstr (line, "non_proxied_non_sa_aware")) {
  439. amf_comp->comptype = clc_component_proxied_non_pre;
  440. } else {
  441. goto parse_error;
  442. }
  443. } else
  444. if ((loc = strstr_rs(line, "instantiate=")) != 0) {
  445. strcpy (amf_comp->instantiate_cmd, loc);
  446. } else
  447. if ((loc = strstr_rs(line, "terminate=")) != 0) {
  448. strcpy (amf_comp->terminate_cmd, loc);
  449. } else
  450. if ((loc = strstr_rs(line, "cleanup=")) != 0) {
  451. strcpy (amf_comp->cleanup_cmd, loc);
  452. } else
  453. if ((loc = strstr_rs(line, "am_start=")) != 0) {
  454. strcpy (amf_comp->am_start_cmd, loc);
  455. } else
  456. if ((loc = strstr_rs(line, "am_stop=")) != 0) {
  457. strcpy (amf_comp->am_stop_cmd, loc);
  458. } else
  459. if ((loc = strstr_rs (line, "clccli_path=")) != 0) {
  460. strcpy (amf_comp->clccli_path, loc);
  461. } else
  462. if ((loc = strstr_rs (line, "binary_path=")) != 0) {
  463. strcpy (amf_comp->binary_path, loc);
  464. } else
  465. if ((loc = strstr_rs (line, "bn=")) != 0) {
  466. strcpy (amf_comp->binary_name, loc);
  467. } else
  468. if ((loc = strstr_rs (line, "csi_type_name{")) != 0) {
  469. csi_type_name =
  470. (struct amf_comp_csi_type_name*)mempool_malloc (sizeof(struct amf_comp_csi_type_name));
  471. list_init(&csi_type_name->list);
  472. list_add_tail (&csi_type_name->list, &amf_comp->csi_type_name_head);
  473. current_parse = AMF_COMPONENT_CSI_TYPE_NAMES;
  474. } else
  475. if (strstr_rs (line, "}")) {
  476. current_parse = AMF_UNIT;
  477. } else {
  478. goto parse_error;
  479. }
  480. break;
  481. case AMF_COMPONENT_CSI_TYPE_NAMES:
  482. if ((loc = strstr_rs (line, "name=")) != 0) {
  483. setSaNameT(&csi_type_name->name, loc);
  484. } else
  485. if ((loc = strstr_rs (line, "csi_type_name{")) != 0) {
  486. csi_type_name =
  487. (struct amf_comp_csi_type_name*)mempool_malloc (sizeof(struct amf_comp_csi_type_name));
  488. list_init(&csi_type_name->list);
  489. list_add_tail (&csi_type_name->list, &amf_comp->csi_type_name_head);
  490. current_parse = AMF_COMPONENT_CSI_TYPE_NAMES;
  491. } else
  492. if (strstr_rs (line, "}")) {
  493. current_parse = AMF_COMPONENT;
  494. } else {
  495. goto parse_error;
  496. }
  497. break;
  498. case AMF_SERVICEINSTANCE:
  499. if ((loc = strstr_rs (line, "name=")) != 0) {
  500. setSaNameT (&amf_si->name, loc);
  501. } else
  502. if ((loc = strstr_rs (line, "csi_descriptor{")) != 0) {
  503. amf_csi = (struct amf_csi*)mempool_malloc (sizeof(struct amf_csi));
  504. list_init(&amf_csi->csi_list);
  505. list_init(&amf_csi->name_value_head);
  506. list_add_tail (&amf_csi->csi_list, &amf_si->csi_head);
  507. current_parse = AMF_SERVICEINSTANCE_CSIDESCRIPTOR;
  508. } else
  509. if (strstr_rs (line, "}")) {
  510. current_parse = AMF_GROUP;
  511. } else {
  512. goto parse_error;
  513. }
  514. break;
  515. case AMF_SERVICEINSTANCE_CSIDESCRIPTOR:
  516. if ((loc = strstr_rs (line, "csi_name=")) != 0) {
  517. setSaNameT (&amf_csi->name, loc);
  518. } else
  519. if ((loc = strstr_rs (line, "type_name=")) != 0) {
  520. setSaNameT (&amf_csi->type_name, loc);
  521. } else
  522. if ((loc = strstr_rs (line, "name_value{")) != 0) {
  523. csi_name_value = (struct amf_csi_name_value*)mempool_malloc (sizeof(struct amf_csi_name_value));
  524. list_init(&csi_name_value->csi_name_list);
  525. list_add_tail (&csi_name_value->csi_name_list, &amf_csi->name_value_head);
  526. current_parse = AMF_SERVICEINSTANCE_CSIDESCRIPTOR_NAMEVALUE;
  527. } else
  528. if (strstr_rs (line, "}")) {
  529. current_parse = AMF_SERVICEINSTANCE;
  530. } else {
  531. goto parse_error;
  532. }
  533. break;
  534. case AMF_SERVICEINSTANCE_CSIDESCRIPTOR_NAMEVALUE:
  535. if ((loc = strstr_rs (line, "name=")) != 0) {
  536. strcpy(csi_name_value->name, loc);
  537. } else
  538. if ((loc = strstr_rs (line, "value=")) != 0) {
  539. strcpy(csi_name_value->value, loc);
  540. } else
  541. if (strstr_rs (line, "}")) {
  542. current_parse = AMF_SERVICEINSTANCE_CSIDESCRIPTOR;
  543. } else {
  544. goto parse_error;
  545. }
  546. break;
  547. case AMF_HEALTHCHECK:
  548. if ((loc = strstr_rs (line, "key=")) != 0) {
  549. strcpy ((char *)amf_healthcheck->key.key, loc);
  550. amf_healthcheck->key.keyLen = strlen (loc);
  551. } else
  552. if ((loc = strstr_rs (line, "period=")) != 0) {
  553. amf_healthcheck->period = atoi (loc);
  554. } else
  555. if ((loc = strstr_rs (line, "maximum_duration=")) != 0) {
  556. amf_healthcheck->maximum_duration = atoi (loc);
  557. } else
  558. if (strstr_rs (line, "}")) {
  559. current_parse = AMF_HEAD;
  560. } else {
  561. goto parse_error;
  562. }
  563. break;
  564. default:
  565. printf ("Invalid state\n");
  566. goto parse_error;
  567. break;
  568. }
  569. }
  570. fclose (fp);
  571. return (0);
  572. parse_error:
  573. sprintf (error_string_response,
  574. "parse error at %s/groups.conf:%d.\n", OPENAIS_CONFDIR, line_number);
  575. *error_string = error_string_response;
  576. fclose (fp);
  577. return (-1);
  578. }