1
0

shell_xml.c 35 KB

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