amfconfig.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  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. char *filename;
  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 = NULL;
  225. filename = getenv("OPENAIS_AMF_CONFIG_FILE");
  226. if (!filename)
  227. filename = "etc/ais/groups.conf";
  228. fp = fopen (filename, "r");
  229. if (fp == 0) {
  230. sprintf (error_string_response,
  231. "Can't read %s file reason = (%s).\n",
  232. filename, strerror (errno));
  233. *error_string = error_string_response;
  234. return (-1);
  235. }
  236. while (fgets (line, 255, fp)) {
  237. line_number += 1;
  238. line[strlen(line) - 1] = '\0';
  239. /*
  240. * Clear out comments and empty lines
  241. */
  242. if (line[0] == '#' || line[0] == '\0' || line[0] == '\n') {
  243. continue;
  244. }
  245. /*
  246. * Clear out white space and tabs
  247. */
  248. for (i = strlen (line) - 1; i > -1; i--) {
  249. if (line[i] == '\t' || line[i] == ' ') {
  250. line[i] = '\0';
  251. } else {
  252. break;
  253. }
  254. }
  255. switch (current_parse) {
  256. case AMF_HEAD:
  257. if (strstr_rs (line, "group{")) {
  258. amf_group = (struct amf_group *)mempool_malloc (sizeof (struct amf_group));
  259. memset (amf_group, 0, sizeof (struct amf_group));
  260. list_init (&amf_group->group_list);
  261. list_init (&amf_group->unit_head);
  262. list_init (&amf_group->si_head);
  263. list_add (&amf_group->group_list, &amf_groupHead);
  264. memset (amf_group->clccli_path, 0, sizeof (&amf_unit->clccli_path));
  265. memset (amf_group->binary_path, 0, sizeof (&amf_unit->binary_path));
  266. current_parse = AMF_GROUP;
  267. } else
  268. if (strstr_rs (line, "healthcheck{")) {
  269. amf_healthcheck = (struct amf_healthcheck *)mempool_malloc (sizeof (struct amf_healthcheck));
  270. memset (amf_healthcheck, 0, sizeof (struct amf_healthcheck));
  271. list_init (&amf_healthcheck->list);
  272. list_add_tail (&amf_healthcheck->list,
  273. &amf_healthcheck_head);
  274. current_parse = AMF_HEALTHCHECK;
  275. } else {
  276. goto parse_error;
  277. }
  278. break;
  279. case AMF_GROUP:
  280. if ((loc = strstr_rs (line, "name=")) != 0) {
  281. setSaNameT (&amf_group->name, loc);
  282. } else
  283. if ((loc = strstr_rs (line, "model=")) != 0) {
  284. if (strcmp (loc, "2n") == 0) {
  285. amf_group->model = SA_AMF_2N_REDUNDANCY_MODEL;
  286. } else
  287. if (strcmp (loc, "nplusm") == 0) {
  288. amf_group->model = SA_AMF_NPM_REDUNDANCY_MODEL;
  289. } else
  290. if (strcmp (loc, "nway") == 0) {
  291. printf ("nway redundancy model not supported.\n");
  292. goto parse_error;
  293. } else
  294. if (strcmp (loc, "nwayactive") == 0) {
  295. printf ("nway active redundancy model not supported.\n");
  296. goto parse_error;
  297. } else
  298. if (strcmp (loc, "noredundancy") == 0) {
  299. amf_group->model = SA_AMF_NO_REDUNDANCY_MODEL;
  300. } else {
  301. goto parse_error;
  302. }
  303. } else
  304. if ((loc = strstr_rs (line, "preferred-active-units=")) != 0) {
  305. amf_group->preferred_active_units = atoi (loc);
  306. } else
  307. if ((loc = strstr_rs (line, "preferred-standby-units=")) != 0) {
  308. amf_group->preferred_standby_units = atoi (loc);
  309. } else
  310. if ((loc = strstr_rs (line, "maximum-active-instances=")) != 0) {
  311. amf_group->maximum_active_instances = atoi (loc);
  312. } else
  313. if ((loc = strstr_rs (line, "maximum-standby-instances=")) != 0) {
  314. amf_group->maximum_standby_instances = atoi (loc);
  315. } else
  316. if ((loc = strstr_rs (line, "clccli_path=")) != 0) {
  317. strcpy (amf_group->clccli_path, loc);
  318. } else
  319. if ((loc = strstr_rs (line, "binary_path=")) != 0) {
  320. strcpy (amf_group->binary_path, loc);
  321. } else
  322. if ((loc = strstr_rs (line, "component_restart_probation=")) != 0) {
  323. amf_group->component_restart_probation = atoi (loc);
  324. printf ("restart probation %d\n", amf_group->component_restart_probation);
  325. } else
  326. if ((loc = strstr_rs (line, "component_restart_max=")) != 0) {
  327. amf_group->component_restart_max = atoi (loc);
  328. printf ("restart max %d\n", amf_group->component_restart_max);
  329. } else
  330. if ((loc = strstr_rs (line, "unit_restart_probation=")) != 0) {
  331. amf_group->unit_restart_probation = atoi (loc);
  332. printf ("unit restart probation %d\n", amf_group->unit_restart_probation);
  333. } else
  334. if ((loc = strstr_rs (line, "unit_restart_max=")) != 0) {
  335. amf_group->unit_restart_max = atoi (loc);
  336. printf ("unit restart max %d\n", amf_group->unit_restart_max);
  337. } else
  338. if (strstr_rs (line, "unit{")) {
  339. amf_unit = (struct amf_unit *)mempool_malloc (sizeof (struct amf_unit));
  340. memset (amf_unit, 0, sizeof (struct amf_unit));
  341. amf_unit->amf_group = amf_group;
  342. amf_unit->operational_state = SA_AMF_OPERATIONAL_DISABLED;
  343. amf_unit->presence_state = SA_AMF_PRESENCE_UNINSTANTIATED;
  344. list_init (&amf_unit->comp_head);
  345. list_init (&amf_unit->si_head);
  346. amf_unit->escalation_level = ESCALATION_LEVEL_NO_ESCALATION;
  347. amf_unit->restart_count = 0;
  348. list_add_tail (&amf_unit->unit_list, &amf_group->unit_head);
  349. memset (amf_unit->clccli_path, 0, sizeof (&amf_unit->clccli_path));
  350. memset (amf_unit->binary_path, 0, sizeof (&amf_unit->binary_path));
  351. current_parse = AMF_UNIT;
  352. } else
  353. if (strstr_rs (line, "serviceinstance{")) {
  354. amf_si = (struct amf_si *)mempool_malloc (sizeof (struct amf_si));
  355. memset (amf_si, 0, sizeof (struct amf_si));
  356. list_init (&amf_si->csi_head);
  357. list_init (&amf_si->unit_list);
  358. list_init (&amf_si->pg_head);
  359. list_add_tail (&amf_si->si_list, &amf_group->si_head);
  360. amf_si->group = amf_group;
  361. current_parse = AMF_SERVICEINSTANCE;
  362. } else
  363. if (strstr_rs (line, "}")) {
  364. current_parse = AMF_HEAD;
  365. } else {
  366. goto parse_error;
  367. }
  368. break;
  369. case AMF_UNIT:
  370. if ((loc = strstr_rs (line, "name=")) != 0) {
  371. setSaNameT (&amf_unit->name, loc);
  372. } else
  373. if ((loc = strstr_rs (line, "component{")) != 0) {
  374. amf_comp = (struct amf_comp *)mempool_malloc (sizeof (struct amf_comp));
  375. memset (amf_comp, 0, sizeof (struct amf_comp));
  376. amf_comp->unit = amf_unit;
  377. amf_comp->operational_state = SA_AMF_OPERATIONAL_DISABLED;
  378. amf_comp->presence_state = SA_AMF_PRESENCE_UNINSTANTIATED;
  379. list_init (&amf_comp->comp_list);
  380. list_init (&amf_comp->healthcheck_list);
  381. list_init (&amf_comp->csi_type_name_head);
  382. list_add_tail (&amf_comp->comp_list, &amf_unit->comp_head);
  383. memset (amf_comp->clccli_path, 0, sizeof (&amf_comp->clccli_path));
  384. memset (amf_comp->binary_path, 0, sizeof (&amf_unit->binary_path));
  385. memset (amf_comp->binary_name, 0, sizeof (&amf_comp->binary_name));
  386. current_parse = AMF_COMPONENT;
  387. } else
  388. if ((loc = strstr_rs (line, "clccli_path=")) != 0) {
  389. strcpy (amf_unit->clccli_path, loc);
  390. } else
  391. if ((loc = strstr_rs (line, "binary_path=")) != 0) {
  392. strcpy (amf_unit->binary_path, loc);
  393. } else
  394. if (strstr_rs (line, "}")) {
  395. current_parse = AMF_GROUP;
  396. } else {
  397. goto parse_error;
  398. }
  399. break;
  400. case AMF_COMPONENT:
  401. if ((loc = strstr_rs (line, "name=")) != 0) {
  402. setSaNameT (&amf_comp->name, loc);
  403. } else
  404. #ifdef COMPILE_OUT
  405. if ((loc = strstr_rs (line, "model=")) != 0) {
  406. if (strcmp (loc, "x_active_and_y_standby") == 0) {
  407. amf_comp->componentCapabilityModel = SA_AMF_COMPONENT_CAPABILITY_X_ACTIVE_AND_Y_STANDBY;
  408. } else
  409. if (strcmp (loc, "x_active_or_y_standby") == 0) {
  410. amf_comp->componentCapabilityModel = SA_AMF_COMPONENT_CAPABILITY_X_ACTIVE_OR_Y_STANDBY;
  411. } else
  412. if (strcmp (loc, "1_active_or_y_standby") == 0) {
  413. amf_comp->componentCapabilityModel = SA_AMF_COMPONENT_CAPABILITY_1_ACTIVE_OR_Y_STANDBY;
  414. } else
  415. if (strcmp (loc, "1_active_or_1_standby") == 0) {
  416. amf_comp->componentCapabilityModel = SA_AMF_COMPONENT_CAPABILITY_1_ACTIVE_OR_1_STANDBY;
  417. } else
  418. if (strcmp (loc, "x_active") == 0) {
  419. amf_comp->componentCapabilityModel = SA_AMF_COMPONENT_CAPABILITY_X_ACTIVE;
  420. } else
  421. if (strcmp (loc, "1_active") == 0) {
  422. amf_comp->componentCapabilityModel = SA_AMF_COMPONENT_CAPABILITY_1_ACTIVE;
  423. } else
  424. if (strcmp (loc, "no_active") == 0) {
  425. amf_comp->componentCapabilityModel = SA_AMF_COMPONENT_CAPABILITY_NO_ACTIVE;
  426. } else {
  427. goto parse_error;
  428. }
  429. } else
  430. #endif
  431. if ((loc = strstr_rs(line, "comptype=")) != 0) {
  432. if (strstr (line, "sa_aware")) {
  433. amf_comp->comptype = clc_component_sa_aware;
  434. } else
  435. if (strstr (line, "proxied_pre")) {
  436. amf_comp->comptype = clc_component_proxied_pre;
  437. } else
  438. if (strstr (line, "proxied_non_pre")) {
  439. amf_comp->comptype = clc_component_proxied_non_pre;
  440. } else
  441. if (strstr (line, "non_proxied_non_sa_aware")) {
  442. amf_comp->comptype = clc_component_proxied_non_pre;
  443. } else {
  444. goto parse_error;
  445. }
  446. } else
  447. if ((loc = strstr_rs(line, "instantiate=")) != 0) {
  448. strcpy (amf_comp->instantiate_cmd, loc);
  449. } else
  450. if ((loc = strstr_rs(line, "terminate=")) != 0) {
  451. strcpy (amf_comp->terminate_cmd, loc);
  452. } else
  453. if ((loc = strstr_rs(line, "cleanup=")) != 0) {
  454. strcpy (amf_comp->cleanup_cmd, loc);
  455. } else
  456. if ((loc = strstr_rs(line, "am_start=")) != 0) {
  457. strcpy (amf_comp->am_start_cmd, loc);
  458. } else
  459. if ((loc = strstr_rs(line, "am_stop=")) != 0) {
  460. strcpy (amf_comp->am_stop_cmd, loc);
  461. } else
  462. if ((loc = strstr_rs (line, "clccli_path=")) != 0) {
  463. strcpy (amf_comp->clccli_path, loc);
  464. } else
  465. if ((loc = strstr_rs (line, "binary_path=")) != 0) {
  466. strcpy (amf_comp->binary_path, loc);
  467. } else
  468. if ((loc = strstr_rs (line, "bn=")) != 0) {
  469. strcpy (amf_comp->binary_name, loc);
  470. } else
  471. if ((loc = strstr_rs (line, "csi_type_name{")) != 0) {
  472. csi_type_name =
  473. (struct amf_comp_csi_type_name*)mempool_malloc (sizeof(struct amf_comp_csi_type_name));
  474. list_init(&csi_type_name->list);
  475. list_add_tail (&csi_type_name->list, &amf_comp->csi_type_name_head);
  476. current_parse = AMF_COMPONENT_CSI_TYPE_NAMES;
  477. } else
  478. if (strstr_rs (line, "}")) {
  479. current_parse = AMF_UNIT;
  480. } else {
  481. goto parse_error;
  482. }
  483. break;
  484. case AMF_COMPONENT_CSI_TYPE_NAMES:
  485. if ((loc = strstr_rs (line, "name=")) != 0) {
  486. setSaNameT(&csi_type_name->name, loc);
  487. } else
  488. if ((loc = strstr_rs (line, "csi_type_name{")) != 0) {
  489. csi_type_name =
  490. (struct amf_comp_csi_type_name*)mempool_malloc (sizeof(struct amf_comp_csi_type_name));
  491. list_init(&csi_type_name->list);
  492. list_add_tail (&csi_type_name->list, &amf_comp->csi_type_name_head);
  493. current_parse = AMF_COMPONENT_CSI_TYPE_NAMES;
  494. } else
  495. if (strstr_rs (line, "}")) {
  496. current_parse = AMF_COMPONENT;
  497. } else {
  498. goto parse_error;
  499. }
  500. break;
  501. case AMF_SERVICEINSTANCE:
  502. if ((loc = strstr_rs (line, "name=")) != 0) {
  503. setSaNameT (&amf_si->name, loc);
  504. } else
  505. if ((loc = strstr_rs (line, "csi_descriptor{")) != 0) {
  506. amf_csi = (struct amf_csi*)mempool_malloc (sizeof(struct amf_csi));
  507. list_init(&amf_csi->csi_list);
  508. list_init(&amf_csi->name_value_head);
  509. list_add_tail (&amf_csi->csi_list, &amf_si->csi_head);
  510. current_parse = AMF_SERVICEINSTANCE_CSIDESCRIPTOR;
  511. } else
  512. if (strstr_rs (line, "}")) {
  513. current_parse = AMF_GROUP;
  514. } else {
  515. goto parse_error;
  516. }
  517. break;
  518. case AMF_SERVICEINSTANCE_CSIDESCRIPTOR:
  519. if ((loc = strstr_rs (line, "csi_name=")) != 0) {
  520. setSaNameT (&amf_csi->name, loc);
  521. } else
  522. if ((loc = strstr_rs (line, "type_name=")) != 0) {
  523. setSaNameT (&amf_csi->type_name, loc);
  524. } else
  525. if ((loc = strstr_rs (line, "name_value{")) != 0) {
  526. csi_name_value = (struct amf_csi_name_value*)mempool_malloc (sizeof(struct amf_csi_name_value));
  527. list_init(&csi_name_value->csi_name_list);
  528. list_add_tail (&csi_name_value->csi_name_list, &amf_csi->name_value_head);
  529. current_parse = AMF_SERVICEINSTANCE_CSIDESCRIPTOR_NAMEVALUE;
  530. } else
  531. if (strstr_rs (line, "}")) {
  532. current_parse = AMF_SERVICEINSTANCE;
  533. } else {
  534. goto parse_error;
  535. }
  536. break;
  537. case AMF_SERVICEINSTANCE_CSIDESCRIPTOR_NAMEVALUE:
  538. if ((loc = strstr_rs (line, "name=")) != 0) {
  539. strcpy(csi_name_value->name, loc);
  540. } else
  541. if ((loc = strstr_rs (line, "value=")) != 0) {
  542. strcpy(csi_name_value->value, loc);
  543. } else
  544. if (strstr_rs (line, "}")) {
  545. current_parse = AMF_SERVICEINSTANCE_CSIDESCRIPTOR;
  546. } else {
  547. goto parse_error;
  548. }
  549. break;
  550. case AMF_HEALTHCHECK:
  551. if ((loc = strstr_rs (line, "key=")) != 0) {
  552. strcpy ((char *)amf_healthcheck->key.key, loc);
  553. amf_healthcheck->key.keyLen = strlen (loc);
  554. } else
  555. if ((loc = strstr_rs (line, "period=")) != 0) {
  556. amf_healthcheck->period = atoi (loc);
  557. } else
  558. if ((loc = strstr_rs (line, "maximum_duration=")) != 0) {
  559. amf_healthcheck->maximum_duration = atoi (loc);
  560. } else
  561. if (strstr_rs (line, "}")) {
  562. current_parse = AMF_HEAD;
  563. } else {
  564. goto parse_error;
  565. }
  566. break;
  567. default:
  568. printf ("Invalid state\n");
  569. goto parse_error;
  570. break;
  571. }
  572. }
  573. fclose (fp);
  574. return (0);
  575. parse_error:
  576. sprintf (error_string_response,
  577. "parse error at %s: %d.\n", filename, line_number);
  578. *error_string = error_string_response;
  579. fclose (fp);
  580. return (-1);
  581. }