1
0

shell_xml.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324
  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_view_t *v = (clish_view_t *) parent;
  533. clish_command_t *cmd = NULL;
  534. int res = -1;
  535. char *view = clish_xmlnode_fetch_attr(element, "view");
  536. char *viewid = clish_xmlnode_fetch_attr(element, "viewid");
  537. char *default_shebang =
  538. clish_xmlnode_fetch_attr(element, "default_shebang");
  539. char *timeout = clish_xmlnode_fetch_attr(element, "timeout");
  540. char *default_plugin = clish_xmlnode_fetch_attr(element,
  541. "default_plugin");
  542. #ifdef LEGACY
  543. char *lock = clish_xmlnode_fetch_attr(element, "lock");
  544. char *interrupt = clish_xmlnode_fetch_attr(element, "interrupt");
  545. clish_action_t *action;
  546. #endif
  547. /* Check syntax */
  548. if (!view) {
  549. fprintf(stderr, CLISH_XML_ERROR_ATTR("view"));
  550. goto error;
  551. }
  552. if (shell->startup) {
  553. fprintf(stderr, CLISH_XML_ERROR_STR"STARTUP tag duplication.\n");
  554. goto error;
  555. }
  556. /* create a command with NULL help */
  557. cmd = clish_view_new_command(v, "startup", NULL);
  558. clish_command__set_internal(cmd, BOOL_TRUE);
  559. /* reference the next view */
  560. clish_command__set_viewname(cmd, view);
  561. /* define the view id which this command changes to */
  562. if (viewid)
  563. clish_command__set_viewid(cmd, viewid);
  564. if (default_shebang)
  565. clish_shell__set_default_shebang(shell, default_shebang);
  566. if (timeout) {
  567. unsigned int to = 0;
  568. lub_conv_atoui(timeout, &to, 0);
  569. clish_shell__set_idle_timeout(shell, to);
  570. }
  571. #ifdef LEGACY
  572. action = clish_command__get_action(cmd);
  573. /* lock */
  574. if (lock) { // Don't change anything if lock is not specified
  575. if (lub_string_nocasecmp(lock, "false") == 0)
  576. clish_action__set_lock(action, BOOL_FALSE);
  577. else
  578. clish_action__set_lock(action, BOOL_TRUE);
  579. }
  580. /* interrupt */
  581. if (interrupt) { // Don't change anything if lock is not specified
  582. if (lub_string_nocasecmp(interrupt, "true") == 0)
  583. clish_action__set_interrupt(action, BOOL_TRUE);
  584. else
  585. clish_action__set_interrupt(action, BOOL_FALSE);
  586. }
  587. #endif
  588. /* If we need the default plugin */
  589. if (default_plugin && (0 == strcmp(default_plugin, "false")))
  590. shell->default_plugin = BOOL_FALSE;
  591. /* remember this command */
  592. shell->startup = cmd;
  593. res = process_children(shell, element, cmd);
  594. error:
  595. clish_xml_release(view);
  596. clish_xml_release(viewid);
  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. return res;
  604. }
  605. /* ------------------------------------------------------ */
  606. static int process_param(clish_shell_t *shell, clish_xmlnode_t *element,
  607. void *parent)
  608. {
  609. clish_command_t *cmd = NULL;
  610. clish_param_t *p_param = NULL;
  611. clish_xmlnode_t *pelement;
  612. clish_param_t *param;
  613. char *pname;
  614. int res = -1;
  615. char *name = clish_xmlnode_fetch_attr(element, "name");
  616. char *help = clish_xmlnode_fetch_attr(element, "help");
  617. char *ptype = clish_xmlnode_fetch_attr(element, "ptype");
  618. char *prefix = clish_xmlnode_fetch_attr(element, "prefix");
  619. char *defval = clish_xmlnode_fetch_attr(element, "default");
  620. char *mode = clish_xmlnode_fetch_attr(element, "mode");
  621. char *optional = clish_xmlnode_fetch_attr(element, "optional");
  622. char *order = clish_xmlnode_fetch_attr(element, "order");
  623. char *value = clish_xmlnode_fetch_attr(element, "value");
  624. char *hidden = clish_xmlnode_fetch_attr(element, "hidden");
  625. char *test = clish_xmlnode_fetch_attr(element, "test");
  626. char *completion = clish_xmlnode_fetch_attr(element, "completion");
  627. char *access = clish_xmlnode_fetch_attr(element, "access");
  628. /* The PARAM can be child of COMMAND or another PARAM */
  629. pelement = clish_xmlnode_parent(element);
  630. pname = clish_xmlnode_get_all_name(pelement);
  631. if (pname && lub_string_nocasecmp(pname, "PARAM") == 0)
  632. p_param = (clish_param_t *)parent;
  633. else
  634. cmd = (clish_command_t *)parent;
  635. if (pname)
  636. free(pname);
  637. if (!cmd && !p_param)
  638. goto error;
  639. /* Check syntax */
  640. if (cmd && (cmd == shell->startup)) {
  641. fprintf(stderr, CLISH_XML_ERROR_STR"STARTUP can't contain PARAMs.\n");
  642. goto error;
  643. }
  644. if (!name) {
  645. fprintf(stderr, CLISH_XML_ERROR_ATTR("name"));
  646. goto error;
  647. }
  648. if (!help) {
  649. fprintf(stderr, CLISH_XML_ERROR_ATTR("help"));
  650. goto error;
  651. }
  652. if (!ptype) {
  653. fprintf(stderr, CLISH_XML_ERROR_ATTR("ptype"));
  654. goto error;
  655. }
  656. param = clish_param_new(name, help, ptype);
  657. /* If prefix is set clish will emulate old optional
  658. * command syntax over newer optional command mechanism.
  659. * It will create nested PARAM.
  660. */
  661. if (prefix) {
  662. const char *ptype_name = "__ptype_SUBCOMMAND";
  663. clish_param_t *opt_param = NULL;
  664. char *str = NULL;
  665. clish_ptype_t *tmp;
  666. /* Create a ptype for prefix-named subcommand that
  667. * will contain the nested optional parameter. The
  668. * name of ptype is hardcoded. It's not good but
  669. * it's only the service ptype.
  670. */
  671. tmp = clish_shell_find_create_ptype(shell,
  672. ptype_name, "Option", "[^\\\\]+",
  673. CLISH_PTYPE_METHOD_REGEXP, CLISH_PTYPE_PRE_NONE);
  674. assert(tmp);
  675. lub_string_cat(&str, "_prefix_");
  676. lub_string_cat(&str, name);
  677. opt_param = clish_param_new(str, help, ptype_name);
  678. lub_string_free(str);
  679. clish_param__set_mode(opt_param,
  680. CLISH_PARAM_SUBCOMMAND);
  681. clish_param__set_value(opt_param, prefix);
  682. clish_param__set_optional(opt_param, BOOL_TRUE);
  683. if (test)
  684. clish_param__set_test(opt_param, test);
  685. /* Add the parameter to the command */
  686. if (cmd)
  687. clish_command_insert_param(cmd, opt_param);
  688. /* Add the parameter to the param */
  689. if (p_param)
  690. clish_param_insert_param(p_param, opt_param);
  691. /* Unset cmd and set parent param to opt_param */
  692. cmd = NULL;
  693. p_param = opt_param;
  694. }
  695. if (defval)
  696. clish_param__set_defval(param, defval);
  697. if (hidden && lub_string_nocasecmp(hidden, "true") == 0)
  698. clish_param__set_hidden(param, BOOL_TRUE);
  699. else
  700. clish_param__set_hidden(param, BOOL_FALSE);
  701. if (mode) {
  702. if (lub_string_nocasecmp(mode, "switch") == 0) {
  703. clish_param__set_mode(param,
  704. CLISH_PARAM_SWITCH);
  705. /* Force hidden attribute */
  706. clish_param__set_hidden(param, BOOL_TRUE);
  707. } else if (lub_string_nocasecmp(mode, "subcommand") == 0)
  708. clish_param__set_mode(param,
  709. CLISH_PARAM_SUBCOMMAND);
  710. else
  711. clish_param__set_mode(param,
  712. CLISH_PARAM_COMMON);
  713. }
  714. if (optional && lub_string_nocasecmp(optional, "true") == 0)
  715. clish_param__set_optional(param, BOOL_TRUE);
  716. else
  717. clish_param__set_optional(param, BOOL_FALSE);
  718. if (order && lub_string_nocasecmp(order, "true") == 0)
  719. clish_param__set_order(param, BOOL_TRUE);
  720. else
  721. clish_param__set_order(param, BOOL_FALSE);
  722. if (value) {
  723. clish_param__set_value(param, value);
  724. /* Force mode to subcommand */
  725. clish_param__set_mode(param,
  726. CLISH_PARAM_SUBCOMMAND);
  727. }
  728. if (test && !prefix)
  729. clish_param__set_test(param, test);
  730. if (completion)
  731. clish_param__set_completion(param, completion);
  732. if (access)
  733. clish_param__set_access(param, access);
  734. /* Add the parameter to the command */
  735. if (cmd)
  736. clish_command_insert_param(cmd, param);
  737. /* Add the parameter to the param */
  738. if (p_param)
  739. clish_param_insert_param(p_param, param);
  740. res = process_children(shell, element, param);
  741. error:
  742. clish_xml_release(name);
  743. clish_xml_release(help);
  744. clish_xml_release(ptype);
  745. clish_xml_release(prefix);
  746. clish_xml_release(defval);
  747. clish_xml_release(mode);
  748. clish_xml_release(optional);
  749. clish_xml_release(order);
  750. clish_xml_release(value);
  751. clish_xml_release(hidden);
  752. clish_xml_release(test);
  753. clish_xml_release(completion);
  754. clish_xml_release(access);
  755. return res;
  756. }
  757. /* ------------------------------------------------------ */
  758. static int process_action(clish_shell_t *shell, clish_xmlnode_t *element,
  759. void *parent)
  760. {
  761. clish_action_t *action = NULL;
  762. char *builtin = clish_xmlnode_fetch_attr(element, "builtin");
  763. char *shebang = clish_xmlnode_fetch_attr(element, "shebang");
  764. char *lock = clish_xmlnode_fetch_attr(element, "lock");
  765. char *interrupt = clish_xmlnode_fetch_attr(element, "interrupt");
  766. char *interactive = clish_xmlnode_fetch_attr(element, "interactive");
  767. clish_xmlnode_t *pelement = clish_xmlnode_parent(element);
  768. char *pname = clish_xmlnode_get_all_name(pelement);
  769. char *text;
  770. clish_sym_t *sym = NULL;
  771. if (pname && lub_string_nocasecmp(pname, "VAR") == 0)
  772. action = clish_var__get_action((clish_var_t *)parent);
  773. else if (pname && lub_string_nocasecmp(pname, "PTYPE") == 0)
  774. action = clish_ptype__get_action((clish_ptype_t *)parent);
  775. else
  776. action = clish_command__get_action((clish_command_t *)parent);
  777. if (pname)
  778. free(pname);
  779. text = clish_xmlnode_get_all_content(element);
  780. if (text && *text) {
  781. /* store the action */
  782. clish_action__set_script(action, text);
  783. }
  784. if (text)
  785. free(text);
  786. if (builtin)
  787. sym = clish_shell_add_unresolved_sym(shell, builtin,
  788. CLISH_SYM_TYPE_ACTION);
  789. else
  790. sym = shell->hooks[CLISH_SYM_TYPE_ACTION];
  791. clish_action__set_builtin(action, sym);
  792. if (shebang)
  793. clish_action__set_shebang(action, shebang);
  794. /* lock */
  795. if (lock && lub_string_nocasecmp(lock, "false") == 0)
  796. clish_action__set_lock(action, BOOL_FALSE);
  797. /* interrupt */
  798. if (interrupt && lub_string_nocasecmp(interrupt, "true") == 0)
  799. clish_action__set_interrupt(action, BOOL_TRUE);
  800. clish_xml_release(builtin);
  801. clish_xml_release(shebang);
  802. clish_xml_release(lock);
  803. clish_xml_release(interrupt);
  804. clish_xml_release(interactive);
  805. return 0;
  806. }
  807. /* ------------------------------------------------------ */
  808. static int process_detail(clish_shell_t *shell, clish_xmlnode_t *element,
  809. void *parent)
  810. {
  811. clish_command_t *cmd = (clish_command_t *) parent;
  812. /* read the following text element */
  813. char *text = clish_xmlnode_get_all_content(element);
  814. if (text && *text) {
  815. /* store the action */
  816. clish_command__set_detail(cmd, text);
  817. }
  818. if (text)
  819. free(text);
  820. shell = shell; /* Happy compiler */
  821. return 0;
  822. }
  823. /* ------------------------------------------------------ */
  824. static int process_namespace(clish_shell_t *shell, clish_xmlnode_t *element,
  825. void *parent)
  826. {
  827. clish_view_t *v = (clish_view_t *)parent;
  828. clish_nspace_t *nspace = NULL;
  829. int res = -1;
  830. char *view = clish_xmlnode_fetch_attr(element, "ref");
  831. char *prefix = clish_xmlnode_fetch_attr(element, "prefix");
  832. char *prefix_help = clish_xmlnode_fetch_attr(element, "prefix_help");
  833. char *help = clish_xmlnode_fetch_attr(element, "help");
  834. char *completion = clish_xmlnode_fetch_attr(element, "completion");
  835. char *context_help = clish_xmlnode_fetch_attr(element, "context_help");
  836. char *inherit = clish_xmlnode_fetch_attr(element, "inherit");
  837. char *access = clish_xmlnode_fetch_attr(element, "access");
  838. /* Check syntax */
  839. if (!view) {
  840. fprintf(stderr, CLISH_XML_ERROR_ATTR("ref"));
  841. goto error;
  842. }
  843. clish_view_t *ref_view = clish_shell_find_view(shell, view);
  844. /* Don't include itself without prefix */
  845. if ((ref_view == v) && !prefix)
  846. goto process_namespace_end;
  847. nspace = clish_nspace_new(view);
  848. clish_view_insert_nspace(v, nspace);
  849. if (prefix) {
  850. clish_nspace__set_prefix(nspace, prefix);
  851. if (prefix_help)
  852. clish_nspace_create_prefix_cmd(nspace,
  853. "prefix",
  854. prefix_help);
  855. else
  856. clish_nspace_create_prefix_cmd(nspace,
  857. "prefix",
  858. "Prefix for the imported commands.");
  859. }
  860. if (help && lub_string_nocasecmp(help, "true") == 0)
  861. clish_nspace__set_help(nspace, BOOL_TRUE);
  862. else
  863. clish_nspace__set_help(nspace, BOOL_FALSE);
  864. if (completion && lub_string_nocasecmp(completion, "false") == 0)
  865. clish_nspace__set_completion(nspace, BOOL_FALSE);
  866. else
  867. clish_nspace__set_completion(nspace, BOOL_TRUE);
  868. if (context_help && lub_string_nocasecmp(context_help, "true") == 0)
  869. clish_nspace__set_context_help(nspace, BOOL_TRUE);
  870. else
  871. clish_nspace__set_context_help(nspace, BOOL_FALSE);
  872. if (inherit && lub_string_nocasecmp(inherit, "false") == 0)
  873. clish_nspace__set_inherit(nspace, BOOL_FALSE);
  874. else
  875. clish_nspace__set_inherit(nspace, BOOL_TRUE);
  876. if (access)
  877. clish_nspace__set_access(nspace, access);
  878. process_namespace_end:
  879. res = 0;
  880. error:
  881. clish_xml_release(view);
  882. clish_xml_release(prefix);
  883. clish_xml_release(prefix_help);
  884. clish_xml_release(help);
  885. clish_xml_release(completion);
  886. clish_xml_release(context_help);
  887. clish_xml_release(inherit);
  888. clish_xml_release(access);
  889. return res;
  890. }
  891. /* ------------------------------------------------------ */
  892. static int process_config(clish_shell_t *shell, clish_xmlnode_t *element,
  893. void *parent)
  894. {
  895. clish_command_t *cmd = (clish_command_t *)parent;
  896. clish_config_t *config;
  897. if (!cmd)
  898. return 0;
  899. config = clish_command__get_config(cmd);
  900. /* read the following text element */
  901. char *operation = clish_xmlnode_fetch_attr(element, "operation");
  902. char *priority = clish_xmlnode_fetch_attr(element, "priority");
  903. char *pattern = clish_xmlnode_fetch_attr(element, "pattern");
  904. char *file = clish_xmlnode_fetch_attr(element, "file");
  905. char *splitter = clish_xmlnode_fetch_attr(element, "splitter");
  906. char *seq = clish_xmlnode_fetch_attr(element, "sequence");
  907. char *unique = clish_xmlnode_fetch_attr(element, "unique");
  908. char *depth = clish_xmlnode_fetch_attr(element, "depth");
  909. if (operation && !lub_string_nocasecmp(operation, "unset"))
  910. clish_config__set_op(config, CLISH_CONFIG_UNSET);
  911. else if (operation && !lub_string_nocasecmp(operation, "none"))
  912. clish_config__set_op(config, CLISH_CONFIG_NONE);
  913. else if (operation && !lub_string_nocasecmp(operation, "dump"))
  914. clish_config__set_op(config, CLISH_CONFIG_DUMP);
  915. else {
  916. clish_config__set_op(config, CLISH_CONFIG_SET);
  917. /* The priority if no clearly specified */
  918. clish_config__set_priority(config, 0x7f00);
  919. }
  920. if (priority) {
  921. unsigned short pri = 0;
  922. lub_conv_atous(priority, &pri, 0);
  923. clish_config__set_priority(config, pri);
  924. }
  925. if (pattern)
  926. clish_config__set_pattern(config, pattern);
  927. else
  928. clish_config__set_pattern(config, "^${__cmd}");
  929. if (file)
  930. clish_config__set_file(config, file);
  931. if (splitter && lub_string_nocasecmp(splitter, "false") == 0)
  932. clish_config__set_splitter(config, BOOL_FALSE);
  933. else
  934. clish_config__set_splitter(config, BOOL_TRUE);
  935. if (unique && lub_string_nocasecmp(unique, "false") == 0)
  936. clish_config__set_unique(config, BOOL_FALSE);
  937. else
  938. clish_config__set_unique(config, BOOL_TRUE);
  939. if (seq)
  940. clish_config__set_seq(config, seq);
  941. else
  942. /* The entries without sequence cannot be non-unique */
  943. clish_config__set_unique(config, BOOL_TRUE);
  944. if (depth)
  945. clish_config__set_depth(config, depth);
  946. clish_xml_release(operation);
  947. clish_xml_release(priority);
  948. clish_xml_release(pattern);
  949. clish_xml_release(file);
  950. clish_xml_release(splitter);
  951. clish_xml_release(seq);
  952. clish_xml_release(unique);
  953. clish_xml_release(depth);
  954. shell = shell; /* Happy compiler */
  955. return 0;
  956. }
  957. /* ------------------------------------------------------ */
  958. static int process_var(clish_shell_t *shell, clish_xmlnode_t *element,
  959. void *parent)
  960. {
  961. clish_var_t *var = NULL;
  962. int res = -1;
  963. char *name = clish_xmlnode_fetch_attr(element, "name");
  964. char *dynamic = clish_xmlnode_fetch_attr(element, "dynamic");
  965. char *value = clish_xmlnode_fetch_attr(element, "value");
  966. /* Check syntax */
  967. if (!name) {
  968. fprintf(stderr, CLISH_XML_ERROR_ATTR("name"));
  969. goto error;
  970. }
  971. /* Check if this var doesn't already exist */
  972. var = (clish_var_t *)lub_bintree_find(&shell->var_tree, name);
  973. if (var) {
  974. fprintf(stderr, CLISH_XML_ERROR_STR"Duplicate VAR name=\"%s\".\n", name);
  975. goto error;
  976. }
  977. /* Create var instance */
  978. var = clish_var_new(name);
  979. lub_bintree_insert(&shell->var_tree, var);
  980. if (dynamic && lub_string_nocasecmp(dynamic, "true") == 0)
  981. clish_var__set_dynamic(var, BOOL_TRUE);
  982. if (value)
  983. clish_var__set_value(var, value);
  984. res = process_children(shell, element, var);
  985. error:
  986. clish_xml_release(name);
  987. clish_xml_release(dynamic);
  988. clish_xml_release(value);
  989. parent = parent; /* Happy compiler */
  990. return res;
  991. }
  992. /* ------------------------------------------------------ */
  993. static int process_wdog(clish_shell_t *shell,
  994. clish_xmlnode_t *element, void *parent)
  995. {
  996. clish_view_t *v = (clish_view_t *)parent;
  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_view_new_command(v, "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. return res;
  1015. }
  1016. /* ------------------------------------------------------ */
  1017. static int process_hotkey(clish_shell_t *shell, clish_xmlnode_t *element,
  1018. void *parent)
  1019. {
  1020. clish_view_t *v = (clish_view_t *)parent;
  1021. int res = -1;
  1022. char *key = clish_xmlnode_fetch_attr(element, "key");
  1023. char *cmd = clish_xmlnode_fetch_attr(element, "cmd");
  1024. /* Check syntax */
  1025. if (!key) {
  1026. fprintf(stderr, CLISH_XML_ERROR_ATTR("key"));
  1027. goto error;
  1028. }
  1029. if (!cmd) {
  1030. fprintf(stderr, CLISH_XML_ERROR_ATTR("cmd"));
  1031. goto error;
  1032. }
  1033. clish_view_insert_hotkey(v, key, cmd);
  1034. res = 0;
  1035. error:
  1036. clish_xml_release(key);
  1037. clish_xml_release(cmd);
  1038. shell = shell; /* Happy compiler */
  1039. return res;
  1040. }
  1041. /* ------------------------------------------------------ */
  1042. static int process_plugin(clish_shell_t *shell, clish_xmlnode_t *element,
  1043. void *parent)
  1044. {
  1045. clish_plugin_t *plugin;
  1046. char *file = clish_xmlnode_fetch_attr(element, "file");
  1047. char *name = clish_xmlnode_fetch_attr(element, "name");
  1048. char *alias = clish_xmlnode_fetch_attr(element, "alias");
  1049. char *rtld_global = clish_xmlnode_fetch_attr(element, "rtld_global");
  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_shell_find_plugin(shell, name);
  1058. if (plugin) {
  1059. fprintf(stderr,
  1060. CLISH_XML_ERROR_STR"PLUGIN %s duplication.\n", name);
  1061. goto error;
  1062. }
  1063. plugin = clish_shell_create_plugin(shell, name);
  1064. if (alias && *alias)
  1065. clish_plugin__set_alias(plugin, alias);
  1066. if (file && *file)
  1067. clish_plugin__set_file(plugin, file);
  1068. if (rtld_global && lub_string_nocasecmp(rtld_global, "true") == 0)
  1069. clish_plugin__set_rtld_global(plugin, BOOL_TRUE);
  1070. /* Get PLUGIN body content */
  1071. text = clish_xmlnode_get_all_content(element);
  1072. if (text && *text)
  1073. clish_plugin__set_conf(plugin, text);
  1074. if (text)
  1075. free(text);
  1076. res = 0;
  1077. error:
  1078. clish_xml_release(file);
  1079. clish_xml_release(name);
  1080. clish_xml_release(alias);
  1081. clish_xml_release(rtld_global);
  1082. parent = parent; /* Happy compiler */
  1083. return res;
  1084. }
  1085. /* ------------------------------------------------------ */
  1086. static int process_hook(clish_shell_t *shell, clish_xmlnode_t *element,
  1087. void *parent)
  1088. {
  1089. char *name = clish_xmlnode_fetch_attr(element, "name");
  1090. char *builtin = clish_xmlnode_fetch_attr(element, "builtin");
  1091. int res = -1;
  1092. int type = CLISH_SYM_TYPE_NONE;
  1093. /* Check syntax */
  1094. if (!name) {
  1095. fprintf(stderr, CLISH_XML_ERROR_ATTR("name"));
  1096. goto error;
  1097. }
  1098. /* Find out HOOK type */
  1099. if (!strcmp(name, "action"))
  1100. type = CLISH_SYM_TYPE_ACTION;
  1101. else if (!strcmp(name, "access"))
  1102. type = CLISH_SYM_TYPE_ACCESS;
  1103. else if (!strcmp(name, "config"))
  1104. type = CLISH_SYM_TYPE_CONFIG;
  1105. else if (!strcmp(name, "log"))
  1106. type = CLISH_SYM_TYPE_LOG;
  1107. if (CLISH_SYM_TYPE_NONE == type) {
  1108. fprintf(stderr, CLISH_XML_ERROR_STR"Unknown HOOK name %s.\n", name);
  1109. goto error;
  1110. }
  1111. /* Check duplicate HOOK tag */
  1112. if (shell->hooks_use[type]) {
  1113. fprintf(stderr,
  1114. CLISH_XML_ERROR_STR"HOOK %s duplication.\n", name);
  1115. goto error;
  1116. }
  1117. shell->hooks_use[type] = BOOL_TRUE;
  1118. clish_sym__set_name(shell->hooks[type], builtin);
  1119. res = 0;
  1120. error:
  1121. clish_xml_release(name);
  1122. clish_xml_release(builtin);
  1123. parent = parent; /* Happy compiler */
  1124. return res;
  1125. }
  1126. /* ------------------------------------------------------ */