amfconfig.c 20 KB

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