amfconfig.c 20 KB

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