shell_xml.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327
  1. /*
  2. * ------------------------------------------------------
  3. * shell_xml.c
  4. *
  5. * This file implements the means to read an XML encoded file and populate the
  6. * CLI tree based on the contents.
  7. * ------------------------------------------------------
  8. */
  9. #include "private.h"
  10. #include "xmlapi.h"
  11. #include "lub/string.h"
  12. #include "lub/ctype.h"
  13. #include "lub/system.h"
  14. #include "lub/conv.h"
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <assert.h>
  18. #include <errno.h>
  19. #include <sys/types.h>
  20. #include <dirent.h>
  21. typedef int (PROCESS_FN) (clish_shell_t *instance,
  22. clish_xmlnode_t *element, void *parent);
  23. /* Define a control block for handling the decode of an XML file */
  24. typedef struct clish_xml_cb_s clish_xml_cb_t;
  25. struct clish_xml_cb_s {
  26. const char *element;
  27. PROCESS_FN *handler;
  28. };
  29. /* forward declare the handler functions */
  30. static PROCESS_FN
  31. process_clish_module,
  32. process_startup,
  33. process_view,
  34. process_command,
  35. process_param,
  36. process_action,
  37. process_ptype,
  38. process_overview,
  39. process_detail,
  40. process_namespace,
  41. process_config,
  42. process_var,
  43. process_wdog,
  44. process_hotkey,
  45. process_plugin,
  46. process_hook;
  47. static clish_xml_cb_t xml_elements[] = {
  48. {"CLISH_MODULE", process_clish_module},
  49. {"STARTUP", process_startup},
  50. {"VIEW", process_view},
  51. {"COMMAND", process_command},
  52. {"PARAM", process_param},
  53. {"ACTION", process_action},
  54. {"PTYPE", process_ptype},
  55. {"OVERVIEW", process_overview},
  56. {"DETAIL", process_detail},
  57. {"NAMESPACE", process_namespace},
  58. {"CONFIG", process_config},
  59. {"VAR", process_var},
  60. {"WATCHDOG", process_wdog},
  61. {"HOTKEY", process_hotkey},
  62. {"PLUGIN", process_plugin},
  63. {"HOOK", process_hook},
  64. {NULL, NULL}
  65. };
  66. /*
  67. * if CLISH_PATH is unset in the environment then this is the value used.
  68. */
  69. const char *default_path = "/etc/clish;~/.clish";
  70. #ifdef WIN32
  71. const char *path_separators = ";";
  72. #else
  73. const char *path_separators = ":;";
  74. #endif
  75. static int process_node(clish_shell_t *shell, clish_xmlnode_t *node,
  76. void *parent);
  77. /*-------------------------------------------------------- */
  78. int clish_shell_load_scheme(clish_shell_t *this, const char *xml_path, const char *xslt_path)
  79. {
  80. const char *path = xml_path;
  81. char *buffer;
  82. char *dirname;
  83. char *saveptr = NULL;
  84. int res = -1;
  85. clish_xmldoc_t *doc = NULL;
  86. DIR *dir;
  87. #ifdef HAVE_LIB_LIBXSLT
  88. clish_xslt_t *xslt = NULL;
  89. /* Load global XSLT stylesheet */
  90. if (xslt_path) {
  91. xslt = clish_xslt_read(xslt_path);
  92. if (!clish_xslt_is_valid(xslt)) {
  93. fprintf(stderr, CLISH_XML_ERROR_STR"Can't load XSLT file %s\n",
  94. xslt_path);
  95. return -1;
  96. }
  97. }
  98. #else
  99. xslt_path = xslt_path; /* Happy compiler */
  100. #endif
  101. /* Use the default path */
  102. if (!path)
  103. path = default_path;
  104. buffer = lub_system_tilde_expand(path);
  105. /* Loop though each directory */
  106. for (dirname = strtok_r(buffer, path_separators, &saveptr);
  107. dirname; dirname = strtok_r(NULL, path_separators, &saveptr)) {
  108. struct dirent *entry;
  109. /* Search this directory for any XML files */
  110. dir = opendir(dirname);
  111. if (NULL == dir) {
  112. #ifdef DEBUG
  113. tinyrl_printf(this->tinyrl,
  114. "*** Failed to open '%s' directory\n",
  115. dirname);
  116. #endif
  117. continue;
  118. }
  119. for (entry = readdir(dir); entry; entry = readdir(dir)) {
  120. const char *extension = strrchr(entry->d_name, '.');
  121. char *filename = NULL;
  122. clish_xmlnode_t *root;
  123. int r;
  124. /* Check the filename */
  125. if (!extension || strcmp(".xml", extension))
  126. continue;
  127. /* Build the filename */
  128. lub_string_cat(&filename, dirname);
  129. lub_string_cat(&filename, "/");
  130. lub_string_cat(&filename, entry->d_name);
  131. #ifdef DEBUG
  132. fprintf(stderr, "Parse XML-file: %s\n", filename);
  133. #endif
  134. /* Load current XML file */
  135. doc = clish_xmldoc_read(filename);
  136. if (!clish_xmldoc_is_valid(doc)) {
  137. int errcaps = clish_xmldoc_error_caps(doc);
  138. printf("Unable to open file '%s'", filename);
  139. if ((errcaps & CLISH_XMLERR_LINE) == CLISH_XMLERR_LINE)
  140. printf(", at line %d", clish_xmldoc_get_err_line(doc));
  141. if ((errcaps & CLISH_XMLERR_COL) == CLISH_XMLERR_COL)
  142. printf(", at column %d", clish_xmldoc_get_err_col(doc));
  143. if ((errcaps & CLISH_XMLERR_DESC) == CLISH_XMLERR_DESC)
  144. printf(", message is %s", clish_xmldoc_get_err_msg(doc));
  145. printf("\n");
  146. goto error;
  147. }
  148. #ifdef HAVE_LIB_LIBXSLT
  149. /* Use embedded stylesheet if stylesheet
  150. * filename is not specified.
  151. */
  152. if (!xslt_path)
  153. xslt = clish_xslt_read_embedded(doc);
  154. if (clish_xslt_is_valid(xslt)) {
  155. clish_xmldoc_t *tmp = NULL;
  156. tmp = clish_xslt_apply(doc, xslt);
  157. if (!clish_xmldoc_is_valid(tmp)) {
  158. fprintf(stderr, CLISH_XML_ERROR_STR"Can't load XSLT file %s\n", xslt_path);
  159. goto error;
  160. }
  161. clish_xmldoc_release(doc);
  162. doc = tmp;
  163. }
  164. if (!xslt_path && clish_xslt_is_valid(xslt))
  165. clish_xslt_release(xslt);
  166. #endif
  167. root = clish_xmldoc_get_root(doc);
  168. r = process_node(this, root, NULL);
  169. clish_xmldoc_release(doc);
  170. /* Error message */
  171. if (r) {
  172. fprintf(stderr, CLISH_XML_ERROR_STR"File %s\n",
  173. filename);
  174. lub_string_free(filename);
  175. goto error;
  176. }
  177. lub_string_free(filename);
  178. }
  179. closedir(dir);
  180. }
  181. /* To don't free memory twice on cleanup */
  182. #ifdef HAVE_LIB_LIBXSLT
  183. if (!xslt_path)
  184. xslt = NULL;
  185. #endif
  186. doc = NULL;
  187. dir = NULL;
  188. res = 0; /* Success */
  189. error:
  190. lub_string_free(buffer);
  191. if (dir)
  192. closedir(dir);
  193. if (clish_xmldoc_is_valid(doc))
  194. clish_xmldoc_release(doc);
  195. #ifdef HAVE_LIB_LIBXSLT
  196. if (clish_xslt_is_valid(xslt))
  197. clish_xslt_release(xslt);
  198. #endif
  199. return res;
  200. }
  201. /*
  202. * ------------------------------------------------------
  203. * This function reads an element from the XML stream and processes it.
  204. * ------------------------------------------------------
  205. */
  206. static int process_node(clish_shell_t *shell, clish_xmlnode_t *node,
  207. void *parent)
  208. {
  209. int res = 0;
  210. switch (clish_xmlnode_get_type(node)) {
  211. case CLISH_XMLNODE_ELM: {
  212. clish_xml_cb_t * cb;
  213. char name[128];
  214. unsigned int namelen = sizeof(name);
  215. if (clish_xmlnode_get_name(node, name, &namelen) == 0) {
  216. for (cb = &xml_elements[0]; cb->element; cb++) {
  217. if (0 == strcmp(name, cb->element)) {
  218. #ifdef DEBUG
  219. fprintf(stderr, "NODE:");
  220. clish_xmlnode_print(node, stderr);
  221. fprintf(stderr, "\n");
  222. #endif
  223. /* process the elements at this level */
  224. res = cb->handler(shell, node, parent);
  225. /* Error message */
  226. if (res) {
  227. char *ename = clish_xmlnode_fetch_attr(node, "name");
  228. char *eref = clish_xmlnode_fetch_attr(node, "ref");
  229. char *ekey = clish_xmlnode_fetch_attr(node, "key");
  230. char *efile = clish_xmlnode_fetch_attr(node, "file");
  231. fprintf(stderr, CLISH_XML_ERROR_STR"Node %s", name);
  232. if (ename)
  233. fprintf(stderr, ", name=\"%s\"", ename);
  234. if (eref)
  235. fprintf(stderr, ", ref=\"%s\"", eref);
  236. if (ekey)
  237. fprintf(stderr, ", key=\"%s\"", ekey);
  238. if (efile)
  239. fprintf(stderr, ", file=\"%s\"", efile);
  240. fprintf(stderr, "\n");
  241. clish_xml_release(ename);
  242. clish_xml_release(eref);
  243. clish_xml_release(ekey);
  244. clish_xml_release(efile);
  245. }
  246. break;
  247. }
  248. }
  249. }
  250. break;
  251. }
  252. case CLISH_XMLNODE_DOC:
  253. case CLISH_XMLNODE_TEXT:
  254. case CLISH_XMLNODE_ATTR:
  255. case CLISH_XMLNODE_PI:
  256. case CLISH_XMLNODE_COMMENT:
  257. case CLISH_XMLNODE_DECL:
  258. case CLISH_XMLNODE_UNKNOWN:
  259. default:
  260. break;
  261. }
  262. return res;
  263. }
  264. /* ------------------------------------------------------ */
  265. static int process_children(clish_shell_t *shell,
  266. clish_xmlnode_t *element, void *parent)
  267. {
  268. clish_xmlnode_t *node = NULL;
  269. int res;
  270. while ((node = clish_xmlnode_next_child(element, node)) != NULL) {
  271. /* Now deal with all the contained elements */
  272. res = process_node(shell, node, parent);
  273. if (res)
  274. return res;
  275. }
  276. return 0;
  277. }
  278. /* ------------------------------------------------------ */
  279. static int process_clish_module(clish_shell_t *shell, clish_xmlnode_t *element,
  280. void *parent)
  281. {
  282. /* Create the global view */
  283. if (!shell->global)
  284. shell->global = clish_shell_find_create_view(shell, "__view_global");
  285. parent = parent; /* Happy compiler */
  286. return process_children(shell, element, shell->global);
  287. }
  288. /* ------------------------------------------------------ */
  289. static int process_view(clish_shell_t *shell, clish_xmlnode_t *element,
  290. void *parent)
  291. {
  292. clish_view_t *view = NULL;
  293. clish_view_restore_e restore_e = CLISH_RESTORE_NONE;
  294. int res = -1;
  295. char *name = clish_xmlnode_fetch_attr(element, "name");
  296. char *prompt = clish_xmlnode_fetch_attr(element, "prompt");
  297. char *depth = clish_xmlnode_fetch_attr(element, "depth");
  298. char *restore = clish_xmlnode_fetch_attr(element, "restore");
  299. char *access = clish_xmlnode_fetch_attr(element, "access");
  300. /* Check syntax */
  301. if (!name) {
  302. fprintf(stderr, CLISH_XML_ERROR_ATTR("name"));
  303. goto error;
  304. }
  305. /* re-use a view if it already exists */
  306. view = clish_shell_find_create_view(shell, name);
  307. if (prompt)
  308. clish_view__set_prompt(view, prompt);
  309. if (depth && (lub_ctype_isdigit(*depth))) {
  310. unsigned int res = 0;
  311. lub_conv_atoui(depth, &res, 0);
  312. clish_view__set_depth(view, res);
  313. }
  314. if (restore) {
  315. restore_e = clish_view_restore_resolve(restore);
  316. clish_view__set_restore(view, restore_e);
  317. }
  318. if (access)
  319. clish_view__set_access(view, access);
  320. //process_view_end:
  321. res = process_children(shell, element, view);
  322. error:
  323. clish_xml_release(name);
  324. clish_xml_release(prompt);
  325. clish_xml_release(depth);
  326. clish_xml_release(restore);
  327. clish_xml_release(access);
  328. parent = parent; /* Happy compiler */
  329. return res;
  330. }
  331. /* ------------------------------------------------------ */
  332. static int process_ptype(clish_shell_t *shell, clish_xmlnode_t *element,
  333. void *parent)
  334. {
  335. clish_ptype_method_e method;
  336. clish_ptype_preprocess_e preprocess;
  337. int res = -1;
  338. clish_ptype_t *ptype;
  339. char *name = clish_xmlnode_fetch_attr(element, "name");
  340. char *help = clish_xmlnode_fetch_attr(element, "help");
  341. char *pattern = clish_xmlnode_fetch_attr(element, "pattern");
  342. char *method_name = clish_xmlnode_fetch_attr(element, "method");
  343. char *preprocess_name = clish_xmlnode_fetch_attr(element, "preprocess");
  344. char *completion = clish_xmlnode_fetch_attr(element, "completion");
  345. /* Check syntax */
  346. if (!name) {
  347. fprintf(stderr, CLISH_XML_ERROR_ATTR("name"));
  348. goto error;
  349. }
  350. method = clish_ptype_method_resolve(method_name);
  351. if (CLISH_PTYPE_METHOD_MAX == method) {
  352. fprintf(stderr, CLISH_XML_ERROR_ATTR("method"));
  353. goto error;
  354. }
  355. if ((method != CLISH_PTYPE_METHOD_CODE) && !pattern) {
  356. fprintf(stderr, CLISH_XML_ERROR_ATTR("pattern"));
  357. goto error;
  358. }
  359. preprocess = clish_ptype_preprocess_resolve(preprocess_name);
  360. ptype = clish_shell_find_create_ptype(shell,
  361. name, help, pattern, method, preprocess);
  362. if (completion)
  363. clish_ptype__set_completion(ptype, completion);
  364. res = process_children(shell, element, ptype);
  365. error:
  366. clish_xml_release(name);
  367. clish_xml_release(help);
  368. clish_xml_release(pattern);
  369. clish_xml_release(method_name);
  370. clish_xml_release(preprocess_name);
  371. clish_xml_release(completion);
  372. parent = parent; /* Happy compiler */
  373. return res;
  374. }
  375. /* ------------------------------------------------------ */
  376. static int process_overview(clish_shell_t *shell, clish_xmlnode_t *element,
  377. void *parent)
  378. {
  379. char *content = NULL;
  380. unsigned int content_len = 2048;
  381. int result;
  382. /*
  383. * the code below faithfully assume that we'll be able fully store
  384. * the content of the node. If it's really, really big, we may have
  385. * an issue (but then, if it's that big, how the hell does it
  386. * already fits in allocated memory?)
  387. * Ergo, it -should- be safe.
  388. */
  389. do {
  390. char *new = (char*)realloc(content, content_len);
  391. if (!new) {
  392. if (content)
  393. free(content);
  394. return -1;
  395. }
  396. content = new;
  397. result = clish_xmlnode_get_content(element, content,
  398. &content_len);
  399. } while (result == -E2BIG);
  400. if (result == 0 && content) {
  401. /* set the overview text for this view */
  402. assert(NULL == shell->overview);
  403. /* store the overview */
  404. shell->overview = lub_string_dup(content);
  405. }
  406. if (content)
  407. free(content);
  408. parent = parent; /* Happy compiler */
  409. return 0;
  410. }
  411. /* ------------------------------------------------------ */
  412. static int process_command(clish_shell_t *shell, clish_xmlnode_t *element,
  413. void *parent)
  414. {
  415. clish_view_t *v = (clish_view_t *) parent;
  416. clish_command_t *cmd = NULL;
  417. clish_command_t *old;
  418. int res = -1;
  419. char *access = clish_xmlnode_fetch_attr(element, "access");
  420. char *name = clish_xmlnode_fetch_attr(element, "name");
  421. char *help = clish_xmlnode_fetch_attr(element, "help");
  422. char *view = clish_xmlnode_fetch_attr(element, "view");
  423. char *viewid = clish_xmlnode_fetch_attr(element, "viewid");
  424. char *escape_chars = clish_xmlnode_fetch_attr(element, "escape_chars");
  425. char *args_name = clish_xmlnode_fetch_attr(element, "args");
  426. char *args_help = clish_xmlnode_fetch_attr(element, "args_help");
  427. char *ref = clish_xmlnode_fetch_attr(element, "ref");
  428. #ifdef LEGACY
  429. char *lock = clish_xmlnode_fetch_attr(element, "lock");
  430. char *interrupt = clish_xmlnode_fetch_attr(element, "interrupt");
  431. clish_action_t *action;
  432. #endif
  433. /* Check syntax */
  434. if (!name) {
  435. fprintf(stderr, CLISH_XML_ERROR_ATTR("name"));
  436. goto error;
  437. }
  438. if (!help) {
  439. fprintf(stderr, CLISH_XML_ERROR_ATTR("help"));
  440. goto error;
  441. }
  442. /* check this command doesn't already exist */
  443. old = clish_view_find_command(v, name, BOOL_FALSE);
  444. if (old) {
  445. fprintf(stderr, CLISH_XML_ERROR_STR"Duplicate COMMAND name=\"%s\".\n", name);
  446. goto error;
  447. }
  448. /* create a command */
  449. cmd = clish_view_new_command(v, name, help);
  450. clish_command__set_pview(cmd, v);
  451. /* Reference 'ref' field */
  452. if (ref) {
  453. char *saveptr = NULL;
  454. const char *delim = "@";
  455. char *view_name = NULL;
  456. char *cmdn = NULL;
  457. char *str = lub_string_dup(ref);
  458. cmdn = strtok_r(str, delim, &saveptr);
  459. if (!cmdn) {
  460. fprintf(stderr, CLISH_XML_ERROR_STR"Invalid \"ref\" attribute value.\n");
  461. lub_string_free(str);
  462. goto error;
  463. }
  464. clish_command__set_alias(cmd, cmdn); /* alias name */
  465. view_name = strtok_r(NULL, delim, &saveptr);
  466. clish_command__set_alias_view(cmd, view_name);
  467. lub_string_free(str);
  468. }
  469. /* define some specialist escape characters */
  470. if (escape_chars)
  471. clish_command__set_escape_chars(cmd, escape_chars);
  472. if (args_name) {
  473. /* define a "rest of line" argument */
  474. clish_param_t *param;
  475. /* Check syntax */
  476. if (!args_help) {
  477. fprintf(stderr, CLISH_XML_ERROR_ATTR("args_help"));
  478. goto error;
  479. }
  480. param = clish_param_new(args_name, args_help, "__ptype_ARGS");
  481. clish_command__set_args(cmd, param);
  482. }
  483. /* define the view which this command changes to */
  484. if (view) {
  485. /* reference the next view */
  486. clish_command__set_viewname(cmd, view);
  487. }
  488. /* define the view id which this command changes to */
  489. if (viewid)
  490. clish_command__set_viewid(cmd, viewid);
  491. #ifdef LEGACY
  492. action = clish_command__get_action(cmd);
  493. /* lock */
  494. if (lock) { // Don't change anything if lock is not specified
  495. if (lub_string_nocasecmp(lock, "false") == 0)
  496. clish_action__set_lock(action, BOOL_FALSE);
  497. else
  498. clish_action__set_lock(action, BOOL_TRUE);
  499. }
  500. /* interrupt */
  501. if (interrupt) { // Don't change anything if lock is not specified
  502. if (lub_string_nocasecmp(interrupt, "true") == 0)
  503. clish_action__set_interrupt(action, BOOL_TRUE);
  504. else
  505. clish_action__set_interrupt(action, BOOL_FALSE);
  506. }
  507. #endif
  508. if (access)
  509. clish_command__set_access(cmd, access);
  510. //process_command_end:
  511. res = process_children(shell, element, cmd);
  512. error:
  513. clish_xml_release(access);
  514. clish_xml_release(name);
  515. clish_xml_release(help);
  516. clish_xml_release(view);
  517. clish_xml_release(viewid);
  518. clish_xml_release(escape_chars);
  519. clish_xml_release(args_name);
  520. clish_xml_release(args_help);
  521. clish_xml_release(ref);
  522. #ifdef LEGACY
  523. clish_xml_release(lock);
  524. clish_xml_release(interrupt);
  525. #endif
  526. return res;
  527. }
  528. /* ------------------------------------------------------ */
  529. static int process_startup(clish_shell_t *shell, clish_xmlnode_t *element,
  530. void *parent)
  531. {
  532. clish_command_t *cmd = NULL;
  533. int res = -1;
  534. char *view = clish_xmlnode_fetch_attr(element, "view");
  535. char *viewid = clish_xmlnode_fetch_attr(element, "viewid");
  536. char *timeout = clish_xmlnode_fetch_attr(element, "timeout");
  537. char *default_plugin = clish_xmlnode_fetch_attr(element,
  538. "default_plugin");
  539. char *default_shebang = clish_xmlnode_fetch_attr(element,
  540. "default_shebang");
  541. #ifdef LEGACY
  542. char *lock = clish_xmlnode_fetch_attr(element, "lock");
  543. char *interrupt = clish_xmlnode_fetch_attr(element, "interrupt");
  544. clish_action_t *action;
  545. #endif
  546. /* Check syntax */
  547. if (!view) {
  548. fprintf(stderr, CLISH_XML_ERROR_ATTR("view"));
  549. goto error;
  550. }
  551. if (shell->startup) {
  552. fprintf(stderr, CLISH_XML_ERROR_STR"STARTUP tag duplication.\n");
  553. goto error;
  554. }
  555. /* create a command with NULL help */
  556. cmd = clish_command_new("startup", NULL);
  557. clish_command__set_internal(cmd, BOOL_TRUE);
  558. /* reference the next view */
  559. clish_command__set_viewname(cmd, view);
  560. /* define the view id which this command changes to */
  561. if (viewid)
  562. clish_command__set_viewid(cmd, viewid);
  563. if (default_shebang)
  564. clish_shell__set_default_shebang(shell, default_shebang);
  565. if (timeout) {
  566. unsigned int to = 0;
  567. lub_conv_atoui(timeout, &to, 0);
  568. clish_shell__set_idle_timeout(shell, to);
  569. }
  570. #ifdef LEGACY
  571. action = clish_command__get_action(cmd);
  572. /* lock */
  573. if (lock) { // Don't change anything if lock is not specified
  574. if (lub_string_nocasecmp(lock, "false") == 0)
  575. clish_action__set_lock(action, BOOL_FALSE);
  576. else
  577. clish_action__set_lock(action, BOOL_TRUE);
  578. }
  579. /* interrupt */
  580. if (interrupt) { // Don't change anything if lock is not specified
  581. if (lub_string_nocasecmp(interrupt, "true") == 0)
  582. clish_action__set_interrupt(action, BOOL_TRUE);
  583. else
  584. clish_action__set_interrupt(action, BOOL_FALSE);
  585. }
  586. #endif
  587. /* If we need the default plugin */
  588. if (default_plugin && (0 == strcmp(default_plugin, "false")))
  589. shell->default_plugin = BOOL_FALSE;
  590. /* remember this command */
  591. shell->startup = cmd;
  592. res = process_children(shell, element, cmd);
  593. error:
  594. clish_xml_release(view);
  595. clish_xml_release(viewid);
  596. clish_xml_release(default_plugin);
  597. clish_xml_release(default_shebang);
  598. clish_xml_release(timeout);
  599. #ifdef LEGACY
  600. clish_xml_release(lock);
  601. clish_xml_release(interrupt);
  602. #endif
  603. parent = parent; /* Happy compiler */
  604. return res;
  605. }
  606. /* ------------------------------------------------------ */
  607. static int process_param(clish_shell_t *shell, clish_xmlnode_t *element,
  608. void *parent)
  609. {
  610. clish_command_t *cmd = NULL;
  611. clish_param_t *p_param = NULL;
  612. clish_xmlnode_t *pelement;
  613. clish_param_t *param;
  614. char *pname;
  615. int res = -1;
  616. char *name = clish_xmlnode_fetch_attr(element, "name");
  617. char *help = clish_xmlnode_fetch_attr(element, "help");
  618. char *ptype = clish_xmlnode_fetch_attr(element, "ptype");
  619. char *prefix = clish_xmlnode_fetch_attr(element, "prefix");
  620. char *defval = clish_xmlnode_fetch_attr(element, "default");
  621. char *mode = clish_xmlnode_fetch_attr(element, "mode");
  622. char *optional = clish_xmlnode_fetch_attr(element, "optional");
  623. char *order = clish_xmlnode_fetch_attr(element, "order");
  624. char *value = clish_xmlnode_fetch_attr(element, "value");
  625. char *hidden = clish_xmlnode_fetch_attr(element, "hidden");
  626. char *test = clish_xmlnode_fetch_attr(element, "test");
  627. char *completion = clish_xmlnode_fetch_attr(element, "completion");
  628. char *access = clish_xmlnode_fetch_attr(element, "access");
  629. /* The PARAM can be child of COMMAND or another PARAM */
  630. pelement = clish_xmlnode_parent(element);
  631. pname = clish_xmlnode_get_all_name(pelement);
  632. if (pname && lub_string_nocasecmp(pname, "PARAM") == 0)
  633. p_param = (clish_param_t *)parent;
  634. else
  635. cmd = (clish_command_t *)parent;
  636. if (pname)
  637. free(pname);
  638. if (!cmd && !p_param)
  639. goto error;
  640. /* Check syntax */
  641. if (cmd && (cmd == shell->startup)) {
  642. fprintf(stderr, CLISH_XML_ERROR_STR"STARTUP can't contain PARAMs.\n");
  643. goto error;
  644. }
  645. if (!name) {
  646. fprintf(stderr, CLISH_XML_ERROR_ATTR("name"));
  647. goto error;
  648. }
  649. if (!help) {
  650. fprintf(stderr, CLISH_XML_ERROR_ATTR("help"));
  651. goto error;
  652. }
  653. if (!ptype) {
  654. fprintf(stderr, CLISH_XML_ERROR_ATTR("ptype"));
  655. goto error;
  656. }
  657. param = clish_param_new(name, help, ptype);
  658. /* If prefix is set clish will emulate old optional
  659. * command syntax over newer optional command mechanism.
  660. * It will create nested PARAM.
  661. */
  662. if (prefix) {
  663. const char *ptype_name = "__ptype_SUBCOMMAND";
  664. clish_param_t *opt_param = NULL;
  665. char *str = NULL;
  666. clish_ptype_t *tmp;
  667. /* Create a ptype for prefix-named subcommand that
  668. * will contain the nested optional parameter. The
  669. * name of ptype is hardcoded. It's not good but
  670. * it's only the service ptype.
  671. */
  672. tmp = clish_shell_find_create_ptype(shell,
  673. ptype_name, "Option", "[^\\\\]+",
  674. CLISH_PTYPE_METHOD_REGEXP, CLISH_PTYPE_PRE_NONE);
  675. assert(tmp);
  676. lub_string_cat(&str, "_prefix_");
  677. lub_string_cat(&str, name);
  678. opt_param = clish_param_new(str, help, ptype_name);
  679. lub_string_free(str);
  680. clish_param__set_mode(opt_param,
  681. CLISH_PARAM_SUBCOMMAND);
  682. clish_param__set_value(opt_param, prefix);
  683. clish_param__set_optional(opt_param, BOOL_TRUE);
  684. if (test)
  685. clish_param__set_test(opt_param, test);
  686. /* Add the parameter to the command */
  687. if (cmd)
  688. clish_command_insert_param(cmd, opt_param);
  689. /* Add the parameter to the param */
  690. if (p_param)
  691. clish_param_insert_param(p_param, opt_param);
  692. /* Unset cmd and set parent param to opt_param */
  693. cmd = NULL;
  694. p_param = opt_param;
  695. }
  696. if (defval)
  697. clish_param__set_defval(param, defval);
  698. if (hidden && lub_string_nocasecmp(hidden, "true") == 0)
  699. clish_param__set_hidden(param, BOOL_TRUE);
  700. else
  701. clish_param__set_hidden(param, BOOL_FALSE);
  702. if (mode) {
  703. if (lub_string_nocasecmp(mode, "switch") == 0) {
  704. clish_param__set_mode(param,
  705. CLISH_PARAM_SWITCH);
  706. /* Force hidden attribute */
  707. clish_param__set_hidden(param, BOOL_TRUE);
  708. } else if (lub_string_nocasecmp(mode, "subcommand") == 0)
  709. clish_param__set_mode(param,
  710. CLISH_PARAM_SUBCOMMAND);
  711. else
  712. clish_param__set_mode(param,
  713. CLISH_PARAM_COMMON);
  714. }
  715. if (optional && lub_string_nocasecmp(optional, "true") == 0)
  716. clish_param__set_optional(param, BOOL_TRUE);
  717. else
  718. clish_param__set_optional(param, BOOL_FALSE);
  719. if (order && lub_string_nocasecmp(order, "true") == 0)
  720. clish_param__set_order(param, BOOL_TRUE);
  721. else
  722. clish_param__set_order(param, BOOL_FALSE);
  723. if (value) {
  724. clish_param__set_value(param, value);
  725. /* Force mode to subcommand */
  726. clish_param__set_mode(param,
  727. CLISH_PARAM_SUBCOMMAND);
  728. }
  729. if (test && !prefix)
  730. clish_param__set_test(param, test);
  731. if (completion)
  732. clish_param__set_completion(param, completion);
  733. if (access)
  734. clish_param__set_access(param, access);
  735. /* Add the parameter to the command */
  736. if (cmd)
  737. clish_command_insert_param(cmd, param);
  738. /* Add the parameter to the param */
  739. if (p_param)
  740. clish_param_insert_param(p_param, param);
  741. res = process_children(shell, element, param);
  742. error:
  743. clish_xml_release(name);
  744. clish_xml_release(help);
  745. clish_xml_release(ptype);
  746. clish_xml_release(prefix);
  747. clish_xml_release(defval);
  748. clish_xml_release(mode);
  749. clish_xml_release(optional);
  750. clish_xml_release(order);
  751. clish_xml_release(value);
  752. clish_xml_release(hidden);
  753. clish_xml_release(test);
  754. clish_xml_release(completion);
  755. clish_xml_release(access);
  756. return res;
  757. }
  758. /* ------------------------------------------------------ */
  759. static int process_action(clish_shell_t *shell, clish_xmlnode_t *element,
  760. void *parent)
  761. {
  762. clish_action_t *action = NULL;
  763. char *builtin = clish_xmlnode_fetch_attr(element, "builtin");
  764. char *shebang = clish_xmlnode_fetch_attr(element, "shebang");
  765. char *lock = clish_xmlnode_fetch_attr(element, "lock");
  766. char *interrupt = clish_xmlnode_fetch_attr(element, "interrupt");
  767. char *interactive = clish_xmlnode_fetch_attr(element, "interactive");
  768. clish_xmlnode_t *pelement = clish_xmlnode_parent(element);
  769. char *pname = clish_xmlnode_get_all_name(pelement);
  770. char *text;
  771. clish_sym_t *sym = NULL;
  772. if (pname && lub_string_nocasecmp(pname, "VAR") == 0)
  773. action = clish_var__get_action((clish_var_t *)parent);
  774. else if (pname && lub_string_nocasecmp(pname, "PTYPE") == 0)
  775. action = clish_ptype__get_action((clish_ptype_t *)parent);
  776. else
  777. action = clish_command__get_action((clish_command_t *)parent);
  778. if (pname)
  779. free(pname);
  780. text = clish_xmlnode_get_all_content(element);
  781. if (text && *text) {
  782. /* store the action */
  783. clish_action__set_script(action, text);
  784. }
  785. if (text)
  786. free(text);
  787. if (builtin)
  788. sym = clish_shell_add_unresolved_sym(shell, builtin,
  789. CLISH_SYM_TYPE_ACTION);
  790. else
  791. sym = shell->hooks[CLISH_SYM_TYPE_ACTION];
  792. clish_action__set_builtin(action, sym);
  793. if (shebang)
  794. clish_action__set_shebang(action, shebang);
  795. /* lock */
  796. if (lock && lub_string_nocasecmp(lock, "false") == 0)
  797. clish_action__set_lock(action, BOOL_FALSE);
  798. /* interrupt */
  799. if (interrupt && lub_string_nocasecmp(interrupt, "true") == 0)
  800. clish_action__set_interrupt(action, BOOL_TRUE);
  801. clish_xml_release(builtin);
  802. clish_xml_release(shebang);
  803. clish_xml_release(lock);
  804. clish_xml_release(interrupt);
  805. clish_xml_release(interactive);
  806. return 0;
  807. }
  808. /* ------------------------------------------------------ */
  809. static int process_detail(clish_shell_t *shell, clish_xmlnode_t *element,
  810. void *parent)
  811. {
  812. clish_command_t *cmd = (clish_command_t *) parent;
  813. /* read the following text element */
  814. char *text = clish_xmlnode_get_all_content(element);
  815. if (text && *text) {
  816. /* store the action */
  817. clish_command__set_detail(cmd, text);
  818. }
  819. if (text)
  820. free(text);
  821. shell = shell; /* Happy compiler */
  822. return 0;
  823. }
  824. /* ------------------------------------------------------ */
  825. static int process_namespace(clish_shell_t *shell, clish_xmlnode_t *element,
  826. void *parent)
  827. {
  828. clish_view_t *v = (clish_view_t *)parent;
  829. clish_nspace_t *nspace = NULL;
  830. int res = -1;
  831. char *view = clish_xmlnode_fetch_attr(element, "ref");
  832. char *prefix = clish_xmlnode_fetch_attr(element, "prefix");
  833. char *prefix_help = clish_xmlnode_fetch_attr(element, "prefix_help");
  834. char *help = clish_xmlnode_fetch_attr(element, "help");
  835. char *completion = clish_xmlnode_fetch_attr(element, "completion");
  836. char *context_help = clish_xmlnode_fetch_attr(element, "context_help");
  837. char *inherit = clish_xmlnode_fetch_attr(element, "inherit");
  838. char *access = clish_xmlnode_fetch_attr(element, "access");
  839. /* Check syntax */
  840. if (!view) {
  841. fprintf(stderr, CLISH_XML_ERROR_ATTR("ref"));
  842. goto error;
  843. }
  844. clish_view_t *ref_view = clish_shell_find_view(shell, view);
  845. /* Don't include itself without prefix */
  846. if ((ref_view == v) && !prefix)
  847. goto process_namespace_end;
  848. nspace = clish_nspace_new(view);
  849. clish_view_insert_nspace(v, nspace);
  850. if (prefix) {
  851. clish_nspace__set_prefix(nspace, prefix);
  852. if (prefix_help)
  853. clish_nspace_create_prefix_cmd(nspace,
  854. "prefix",
  855. prefix_help);
  856. else
  857. clish_nspace_create_prefix_cmd(nspace,
  858. "prefix",
  859. "Prefix for imported commands.");
  860. }
  861. if (help && lub_string_nocasecmp(help, "true") == 0)
  862. clish_nspace__set_help(nspace, BOOL_TRUE);
  863. else
  864. clish_nspace__set_help(nspace, BOOL_FALSE);
  865. if (completion && lub_string_nocasecmp(completion, "false") == 0)
  866. clish_nspace__set_completion(nspace, BOOL_FALSE);
  867. else
  868. clish_nspace__set_completion(nspace, BOOL_TRUE);
  869. if (context_help && lub_string_nocasecmp(context_help, "true") == 0)
  870. clish_nspace__set_context_help(nspace, BOOL_TRUE);
  871. else
  872. clish_nspace__set_context_help(nspace, BOOL_FALSE);
  873. if (inherit && lub_string_nocasecmp(inherit, "false") == 0)
  874. clish_nspace__set_inherit(nspace, BOOL_FALSE);
  875. else
  876. clish_nspace__set_inherit(nspace, BOOL_TRUE);
  877. if (access)
  878. clish_nspace__set_access(nspace, access);
  879. process_namespace_end:
  880. res = 0;
  881. error:
  882. clish_xml_release(view);
  883. clish_xml_release(prefix);
  884. clish_xml_release(prefix_help);
  885. clish_xml_release(help);
  886. clish_xml_release(completion);
  887. clish_xml_release(context_help);
  888. clish_xml_release(inherit);
  889. clish_xml_release(access);
  890. return res;
  891. }
  892. /* ------------------------------------------------------ */
  893. static int process_config(clish_shell_t *shell, clish_xmlnode_t *element,
  894. void *parent)
  895. {
  896. clish_command_t *cmd = (clish_command_t *)parent;
  897. clish_config_t *config;
  898. if (!cmd)
  899. return 0;
  900. config = clish_command__get_config(cmd);
  901. /* read the following text element */
  902. char *operation = clish_xmlnode_fetch_attr(element, "operation");
  903. char *priority = clish_xmlnode_fetch_attr(element, "priority");
  904. char *pattern = clish_xmlnode_fetch_attr(element, "pattern");
  905. char *file = clish_xmlnode_fetch_attr(element, "file");
  906. char *splitter = clish_xmlnode_fetch_attr(element, "splitter");
  907. char *seq = clish_xmlnode_fetch_attr(element, "sequence");
  908. char *unique = clish_xmlnode_fetch_attr(element, "unique");
  909. char *depth = clish_xmlnode_fetch_attr(element, "depth");
  910. if (operation && !lub_string_nocasecmp(operation, "unset"))
  911. clish_config__set_op(config, CLISH_CONFIG_UNSET);
  912. else if (operation && !lub_string_nocasecmp(operation, "none"))
  913. clish_config__set_op(config, CLISH_CONFIG_NONE);
  914. else if (operation && !lub_string_nocasecmp(operation, "dump"))
  915. clish_config__set_op(config, CLISH_CONFIG_DUMP);
  916. else {
  917. clish_config__set_op(config, CLISH_CONFIG_SET);
  918. /* The priority if no clearly specified */
  919. clish_config__set_priority(config, 0x7f00);
  920. }
  921. if (priority) {
  922. unsigned short pri = 0;
  923. lub_conv_atous(priority, &pri, 0);
  924. clish_config__set_priority(config, pri);
  925. }
  926. if (pattern)
  927. clish_config__set_pattern(config, pattern);
  928. else
  929. clish_config__set_pattern(config, "^${__cmd}");
  930. if (file)
  931. clish_config__set_file(config, file);
  932. if (splitter && lub_string_nocasecmp(splitter, "false") == 0)
  933. clish_config__set_splitter(config, BOOL_FALSE);
  934. else
  935. clish_config__set_splitter(config, BOOL_TRUE);
  936. if (unique && lub_string_nocasecmp(unique, "false") == 0)
  937. clish_config__set_unique(config, BOOL_FALSE);
  938. else
  939. clish_config__set_unique(config, BOOL_TRUE);
  940. if (seq)
  941. clish_config__set_seq(config, seq);
  942. else
  943. /* The entries without sequence cannot be non-unique */
  944. clish_config__set_unique(config, BOOL_TRUE);
  945. if (depth)
  946. clish_config__set_depth(config, depth);
  947. clish_xml_release(operation);
  948. clish_xml_release(priority);
  949. clish_xml_release(pattern);
  950. clish_xml_release(file);
  951. clish_xml_release(splitter);
  952. clish_xml_release(seq);
  953. clish_xml_release(unique);
  954. clish_xml_release(depth);
  955. shell = shell; /* Happy compiler */
  956. return 0;
  957. }
  958. /* ------------------------------------------------------ */
  959. static int process_var(clish_shell_t *shell, clish_xmlnode_t *element,
  960. void *parent)
  961. {
  962. clish_var_t *var = NULL;
  963. int res = -1;
  964. char *name = clish_xmlnode_fetch_attr(element, "name");
  965. char *dynamic = clish_xmlnode_fetch_attr(element, "dynamic");
  966. char *value = clish_xmlnode_fetch_attr(element, "value");
  967. /* Check syntax */
  968. if (!name) {
  969. fprintf(stderr, CLISH_XML_ERROR_ATTR("name"));
  970. goto error;
  971. }
  972. /* Check if this var doesn't already exist */
  973. var = (clish_var_t *)lub_bintree_find(&shell->var_tree, name);
  974. if (var) {
  975. fprintf(stderr, CLISH_XML_ERROR_STR"Duplicate VAR name=\"%s\".\n", name);
  976. goto error;
  977. }
  978. /* Create var instance */
  979. var = clish_var_new(name);
  980. lub_bintree_insert(&shell->var_tree, var);
  981. if (dynamic && lub_string_nocasecmp(dynamic, "true") == 0)
  982. clish_var__set_dynamic(var, BOOL_TRUE);
  983. if (value)
  984. clish_var__set_value(var, value);
  985. res = process_children(shell, element, var);
  986. error:
  987. clish_xml_release(name);
  988. clish_xml_release(dynamic);
  989. clish_xml_release(value);
  990. parent = parent; /* Happy compiler */
  991. return res;
  992. }
  993. /* ------------------------------------------------------ */
  994. static int process_wdog(clish_shell_t *shell,
  995. clish_xmlnode_t *element, void *parent)
  996. {
  997. clish_command_t *cmd = NULL;
  998. int res = -1;
  999. /* Check syntax */
  1000. if (shell->wdog) {
  1001. fprintf(stderr, CLISH_XML_ERROR_STR"WATCHDOG tag duplication.\n");
  1002. goto error;
  1003. }
  1004. /* Create a command with NULL help */
  1005. cmd = clish_command_new("watchdog", NULL);
  1006. #ifdef LEGACY
  1007. // Legacy watchdog has lockless ACTION
  1008. clish_action__set_lock(clish_command__get_action(cmd), BOOL_FALSE);
  1009. #endif
  1010. /* Remember this command */
  1011. shell->wdog = cmd;
  1012. res = process_children(shell, element, cmd);
  1013. error:
  1014. parent = parent; /* Happy compiler */
  1015. return res;
  1016. }
  1017. /* ------------------------------------------------------ */
  1018. static int process_hotkey(clish_shell_t *shell, clish_xmlnode_t *element,
  1019. void *parent)
  1020. {
  1021. clish_view_t *v = (clish_view_t *)parent;
  1022. int res = -1;
  1023. char *key = clish_xmlnode_fetch_attr(element, "key");
  1024. char *cmd = clish_xmlnode_fetch_attr(element, "cmd");
  1025. /* Check syntax */
  1026. if (!key) {
  1027. fprintf(stderr, CLISH_XML_ERROR_ATTR("key"));
  1028. goto error;
  1029. }
  1030. if (!cmd) {
  1031. fprintf(stderr, CLISH_XML_ERROR_ATTR("cmd"));
  1032. goto error;
  1033. }
  1034. clish_view_insert_hotkey(v, key, cmd);
  1035. res = 0;
  1036. error:
  1037. clish_xml_release(key);
  1038. clish_xml_release(cmd);
  1039. shell = shell; /* Happy compiler */
  1040. return res;
  1041. }
  1042. /* ------------------------------------------------------ */
  1043. static int process_plugin(clish_shell_t *shell, clish_xmlnode_t *element,
  1044. void *parent)
  1045. {
  1046. clish_plugin_t *plugin;
  1047. char *file = clish_xmlnode_fetch_attr(element, "file");
  1048. char *name = clish_xmlnode_fetch_attr(element, "name");
  1049. char *alias = clish_xmlnode_fetch_attr(element, "alias");
  1050. char *rtld_global = clish_xmlnode_fetch_attr(element, "rtld_global");
  1051. int res = -1;
  1052. char *text;
  1053. /* Check syntax */
  1054. if (!name) {
  1055. fprintf(stderr, CLISH_XML_ERROR_ATTR("name"));
  1056. goto error;
  1057. }
  1058. plugin = clish_shell_find_plugin(shell, name);
  1059. if (plugin) {
  1060. fprintf(stderr,
  1061. CLISH_XML_ERROR_STR"PLUGIN %s duplication.\n", name);
  1062. goto error;
  1063. }
  1064. plugin = clish_shell_create_plugin(shell, name);
  1065. if (alias && *alias)
  1066. clish_plugin__set_alias(plugin, alias);
  1067. if (file && *file)
  1068. clish_plugin__set_file(plugin, file);
  1069. if (rtld_global && lub_string_nocasecmp(rtld_global, "true") == 0)
  1070. clish_plugin__set_rtld_global(plugin, BOOL_TRUE);
  1071. /* Get PLUGIN body content */
  1072. text = clish_xmlnode_get_all_content(element);
  1073. if (text && *text)
  1074. clish_plugin__set_conf(plugin, text);
  1075. if (text)
  1076. free(text);
  1077. res = 0;
  1078. error:
  1079. clish_xml_release(file);
  1080. clish_xml_release(name);
  1081. clish_xml_release(alias);
  1082. clish_xml_release(rtld_global);
  1083. parent = parent; /* Happy compiler */
  1084. return res;
  1085. }
  1086. /* ------------------------------------------------------ */
  1087. static int process_hook(clish_shell_t *shell, clish_xmlnode_t *element,
  1088. void *parent)
  1089. {
  1090. char *name = clish_xmlnode_fetch_attr(element, "name");
  1091. char *builtin = clish_xmlnode_fetch_attr(element, "builtin");
  1092. int res = -1;
  1093. int type = CLISH_SYM_TYPE_NONE;
  1094. /* Check syntax */
  1095. if (!name) {
  1096. fprintf(stderr, CLISH_XML_ERROR_ATTR("name"));
  1097. goto error;
  1098. }
  1099. /* Find out HOOK type */
  1100. if (!strcmp(name, "action"))
  1101. type = CLISH_SYM_TYPE_ACTION;
  1102. else if (!strcmp(name, "access"))
  1103. type = CLISH_SYM_TYPE_ACCESS;
  1104. else if (!strcmp(name, "config"))
  1105. type = CLISH_SYM_TYPE_CONFIG;
  1106. else if (!strcmp(name, "log"))
  1107. type = CLISH_SYM_TYPE_LOG;
  1108. if (CLISH_SYM_TYPE_NONE == type) {
  1109. fprintf(stderr, CLISH_XML_ERROR_STR"Unknown HOOK name %s.\n", name);
  1110. goto error;
  1111. }
  1112. /* Check duplicate HOOK tag */
  1113. if (shell->hooks_use[type]) {
  1114. fprintf(stderr,
  1115. CLISH_XML_ERROR_STR"HOOK %s duplication.\n", name);
  1116. goto error;
  1117. }
  1118. shell->hooks_use[type] = BOOL_TRUE;
  1119. clish_sym__set_name(shell->hooks[type], builtin);
  1120. res = 0;
  1121. error:
  1122. clish_xml_release(name);
  1123. clish_xml_release(builtin);
  1124. parent = parent; /* Happy compiler */
  1125. return res;
  1126. }
  1127. /* ------------------------------------------------------ */