1
0

shell_xml.c 34 KB

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