shell_xml.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322
  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. char *completion = clish_xmlnode_fetch_attr(element, "completion");
  343. /* Check syntax */
  344. if (!name) {
  345. fprintf(stderr, CLISH_XML_ERROR_ATTR("name"));
  346. goto error;
  347. }
  348. method = clish_ptype_method_resolve(method_name);
  349. if (CLISH_PTYPE_METHOD_MAX == method) {
  350. fprintf(stderr, CLISH_XML_ERROR_ATTR("method"));
  351. goto error;
  352. }
  353. if ((method != CLISH_PTYPE_METHOD_CODE) && !pattern) {
  354. fprintf(stderr, CLISH_XML_ERROR_ATTR("pattern"));
  355. goto error;
  356. }
  357. preprocess = clish_ptype_preprocess_resolve(preprocess_name);
  358. ptype = clish_shell_find_create_ptype(shell,
  359. name, help, pattern, method, preprocess);
  360. if (completion)
  361. clish_ptype__set_completion(ptype, completion);
  362. res = process_children(shell, element, ptype);
  363. error:
  364. clish_xml_release(name);
  365. clish_xml_release(help);
  366. clish_xml_release(pattern);
  367. clish_xml_release(method_name);
  368. clish_xml_release(preprocess_name);
  369. clish_xml_release(completion);
  370. parent = parent; /* Happy compiler */
  371. return res;
  372. }
  373. /* ------------------------------------------------------ */
  374. static int process_overview(clish_shell_t *shell, clish_xmlnode_t *element,
  375. void *parent)
  376. {
  377. char *content = NULL;
  378. unsigned int content_len = 2048;
  379. int result;
  380. /*
  381. * the code below faithfully assume that we'll be able fully store
  382. * the content of the node. If it's really, really big, we may have
  383. * an issue (but then, if it's that big, how the hell does it
  384. * already fits in allocated memory?)
  385. * Ergo, it -should- be safe.
  386. */
  387. do {
  388. char *new = (char*)realloc(content, content_len);
  389. if (!new) {
  390. if (content)
  391. free(content);
  392. return -1;
  393. }
  394. content = new;
  395. result = clish_xmlnode_get_content(element, content,
  396. &content_len);
  397. } while (result == -E2BIG);
  398. if (result == 0 && content) {
  399. /* set the overview text for this view */
  400. assert(NULL == shell->overview);
  401. /* store the overview */
  402. shell->overview = lub_string_dup(content);
  403. }
  404. if (content)
  405. free(content);
  406. parent = parent; /* Happy compiler */
  407. return 0;
  408. }
  409. /* ------------------------------------------------------ */
  410. static int process_command(clish_shell_t *shell, clish_xmlnode_t *element,
  411. void *parent)
  412. {
  413. clish_view_t *v = (clish_view_t *) parent;
  414. clish_command_t *cmd = NULL;
  415. clish_command_t *old;
  416. int res = -1;
  417. char *access = clish_xmlnode_fetch_attr(element, "access");
  418. char *name = clish_xmlnode_fetch_attr(element, "name");
  419. char *help = clish_xmlnode_fetch_attr(element, "help");
  420. char *view = clish_xmlnode_fetch_attr(element, "view");
  421. char *viewid = clish_xmlnode_fetch_attr(element, "viewid");
  422. char *escape_chars = clish_xmlnode_fetch_attr(element, "escape_chars");
  423. char *args_name = clish_xmlnode_fetch_attr(element, "args");
  424. char *args_help = clish_xmlnode_fetch_attr(element, "args_help");
  425. char *ref = clish_xmlnode_fetch_attr(element, "ref");
  426. #ifdef LEGACY
  427. char *lock = clish_xmlnode_fetch_attr(element, "lock");
  428. char *interrupt = clish_xmlnode_fetch_attr(element, "interrupt");
  429. clish_action_t *action;
  430. #endif
  431. /* Check syntax */
  432. if (!name) {
  433. fprintf(stderr, CLISH_XML_ERROR_ATTR("name"));
  434. goto error;
  435. }
  436. if (!help) {
  437. fprintf(stderr, CLISH_XML_ERROR_ATTR("help"));
  438. goto error;
  439. }
  440. /* check this command doesn't already exist */
  441. old = clish_view_find_command(v, name, BOOL_FALSE);
  442. if (old) {
  443. fprintf(stderr, CLISH_XML_ERROR_STR"Duplicate COMMAND name=\"%s\".\n", name);
  444. goto error;
  445. }
  446. /* create a command */
  447. cmd = clish_view_new_command(v, name, help);
  448. clish_command__set_pview(cmd, v);
  449. /* Reference 'ref' field */
  450. if (ref) {
  451. char *saveptr = NULL;
  452. const char *delim = "@";
  453. char *view_name = NULL;
  454. char *cmdn = NULL;
  455. char *str = lub_string_dup(ref);
  456. cmdn = strtok_r(str, delim, &saveptr);
  457. if (!cmdn) {
  458. fprintf(stderr, CLISH_XML_ERROR_STR"Invalid \"ref\" attribute value.\n");
  459. lub_string_free(str);
  460. goto error;
  461. }
  462. clish_command__set_alias(cmd, cmdn); /* alias name */
  463. view_name = strtok_r(NULL, delim, &saveptr);
  464. clish_command__set_alias_view(cmd, view_name);
  465. lub_string_free(str);
  466. }
  467. /* define some specialist escape characters */
  468. if (escape_chars)
  469. clish_command__set_escape_chars(cmd, escape_chars);
  470. if (args_name) {
  471. /* define a "rest of line" argument */
  472. clish_param_t *param;
  473. /* Check syntax */
  474. if (!args_help) {
  475. fprintf(stderr, CLISH_XML_ERROR_ATTR("args_help"));
  476. goto error;
  477. }
  478. param = clish_param_new(args_name, args_help, "__ptype_ARGS");
  479. clish_command__set_args(cmd, param);
  480. }
  481. /* define the view which this command changes to */
  482. if (view) {
  483. /* reference the next view */
  484. clish_command__set_viewname(cmd, view);
  485. }
  486. /* define the view id which this command changes to */
  487. if (viewid)
  488. clish_command__set_viewid(cmd, viewid);
  489. #ifdef LEGACY
  490. action = clish_command__get_action(cmd);
  491. /* lock */
  492. if (lock) { // Don't change anything if lock is not specified
  493. if (lub_string_nocasecmp(lock, "false") == 0)
  494. clish_action__set_lock(action, BOOL_FALSE);
  495. else
  496. clish_action__set_lock(action, BOOL_TRUE);
  497. }
  498. /* interrupt */
  499. if (interrupt) { // Don't change anything if lock is not specified
  500. if (lub_string_nocasecmp(interrupt, "true") == 0)
  501. clish_action__set_interrupt(action, BOOL_TRUE);
  502. else
  503. clish_action__set_interrupt(action, BOOL_FALSE);
  504. }
  505. #endif
  506. if (access)
  507. clish_command__set_access(cmd, access);
  508. //process_command_end:
  509. res = process_children(shell, element, cmd);
  510. error:
  511. clish_xml_release(access);
  512. clish_xml_release(name);
  513. clish_xml_release(help);
  514. clish_xml_release(view);
  515. clish_xml_release(viewid);
  516. clish_xml_release(escape_chars);
  517. clish_xml_release(args_name);
  518. clish_xml_release(args_help);
  519. clish_xml_release(ref);
  520. #ifdef LEGACY
  521. clish_xml_release(lock);
  522. clish_xml_release(interrupt);
  523. #endif
  524. return res;
  525. }
  526. /* ------------------------------------------------------ */
  527. static int process_startup(clish_shell_t *shell, clish_xmlnode_t *element,
  528. void *parent)
  529. {
  530. clish_view_t *v = (clish_view_t *) parent;
  531. clish_command_t *cmd = NULL;
  532. int res = -1;
  533. char *view = clish_xmlnode_fetch_attr(element, "view");
  534. char *viewid = clish_xmlnode_fetch_attr(element, "viewid");
  535. char *default_shebang =
  536. clish_xmlnode_fetch_attr(element, "default_shebang");
  537. char *timeout = clish_xmlnode_fetch_attr(element, "timeout");
  538. char *default_plugin = clish_xmlnode_fetch_attr(element,
  539. "default_plugin");
  540. #ifdef LEGACY
  541. char *lock = clish_xmlnode_fetch_attr(element, "lock");
  542. char *interrupt = clish_xmlnode_fetch_attr(element, "interrupt");
  543. clish_action_t *action;
  544. #endif
  545. /* Check syntax */
  546. if (!view) {
  547. fprintf(stderr, CLISH_XML_ERROR_ATTR("view"));
  548. goto error;
  549. }
  550. if (shell->startup) {
  551. fprintf(stderr, CLISH_XML_ERROR_STR"STARTUP tag duplication.\n");
  552. goto error;
  553. }
  554. /* create a command with NULL help */
  555. cmd = clish_view_new_command(v, "startup", NULL);
  556. clish_command__set_internal(cmd, BOOL_TRUE);
  557. /* reference the next view */
  558. clish_command__set_viewname(cmd, view);
  559. /* define the view id which this command changes to */
  560. if (viewid)
  561. clish_command__set_viewid(cmd, viewid);
  562. if (default_shebang)
  563. clish_shell__set_default_shebang(shell, default_shebang);
  564. if (timeout) {
  565. unsigned int to = 0;
  566. lub_conv_atoui(timeout, &to, 0);
  567. clish_shell__set_idle_timeout(shell, to);
  568. }
  569. #ifdef LEGACY
  570. action = clish_command__get_action(cmd);
  571. /* lock */
  572. if (lock) { // Don't change anything if lock is not specified
  573. if (lub_string_nocasecmp(lock, "false") == 0)
  574. clish_action__set_lock(action, BOOL_FALSE);
  575. else
  576. clish_action__set_lock(action, BOOL_TRUE);
  577. }
  578. /* interrupt */
  579. if (interrupt) { // Don't change anything if lock is not specified
  580. if (lub_string_nocasecmp(interrupt, "true") == 0)
  581. clish_action__set_interrupt(action, BOOL_TRUE);
  582. else
  583. clish_action__set_interrupt(action, BOOL_FALSE);
  584. }
  585. #endif
  586. /* If we need the default plugin */
  587. if (default_plugin && (0 == strcmp(default_plugin, "false")))
  588. shell->default_plugin = BOOL_FALSE;
  589. /* remember this command */
  590. shell->startup = cmd;
  591. res = process_children(shell, element, cmd);
  592. error:
  593. clish_xml_release(view);
  594. clish_xml_release(viewid);
  595. clish_xml_release(default_shebang);
  596. clish_xml_release(timeout);
  597. #ifdef LEGACY
  598. clish_xml_release(lock);
  599. clish_xml_release(interrupt);
  600. #endif
  601. return res;
  602. }
  603. /* ------------------------------------------------------ */
  604. static int process_param(clish_shell_t *shell, clish_xmlnode_t *element,
  605. void *parent)
  606. {
  607. clish_command_t *cmd = NULL;
  608. clish_param_t *p_param = NULL;
  609. clish_xmlnode_t *pelement;
  610. clish_param_t *param;
  611. char *pname;
  612. int res = -1;
  613. char *name = clish_xmlnode_fetch_attr(element, "name");
  614. char *help = clish_xmlnode_fetch_attr(element, "help");
  615. char *ptype = clish_xmlnode_fetch_attr(element, "ptype");
  616. char *prefix = clish_xmlnode_fetch_attr(element, "prefix");
  617. char *defval = clish_xmlnode_fetch_attr(element, "default");
  618. char *mode = clish_xmlnode_fetch_attr(element, "mode");
  619. char *optional = clish_xmlnode_fetch_attr(element, "optional");
  620. char *order = clish_xmlnode_fetch_attr(element, "order");
  621. char *value = clish_xmlnode_fetch_attr(element, "value");
  622. char *hidden = clish_xmlnode_fetch_attr(element, "hidden");
  623. char *test = clish_xmlnode_fetch_attr(element, "test");
  624. char *completion = clish_xmlnode_fetch_attr(element, "completion");
  625. char *access = clish_xmlnode_fetch_attr(element, "access");
  626. /* The PARAM can be child of COMMAND or another PARAM */
  627. pelement = clish_xmlnode_parent(element);
  628. pname = clish_xmlnode_get_all_name(pelement);
  629. if (pname && lub_string_nocasecmp(pname, "PARAM") == 0)
  630. p_param = (clish_param_t *)parent;
  631. else
  632. cmd = (clish_command_t *)parent;
  633. if (pname)
  634. free(pname);
  635. if (!cmd && !p_param)
  636. goto error;
  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. param = clish_param_new(name, help, ptype);
  655. /* If prefix is set clish will emulate old optional
  656. * command syntax over newer optional command mechanism.
  657. * It will create nested PARAM.
  658. */
  659. if (prefix) {
  660. const char *ptype_name = "__ptype_SUBCOMMAND";
  661. clish_param_t *opt_param = NULL;
  662. char *str = NULL;
  663. clish_ptype_t *tmp;
  664. /* Create a ptype for prefix-named subcommand that
  665. * will contain the nested optional parameter. The
  666. * name of ptype is hardcoded. It's not good but
  667. * it's only the service ptype.
  668. */
  669. tmp = clish_shell_find_create_ptype(shell,
  670. ptype_name, "Option", "[^\\\\]+",
  671. CLISH_PTYPE_METHOD_REGEXP, CLISH_PTYPE_PRE_NONE);
  672. assert(tmp);
  673. lub_string_cat(&str, "_prefix_");
  674. lub_string_cat(&str, name);
  675. opt_param = clish_param_new(str, help, ptype_name);
  676. lub_string_free(str);
  677. clish_param__set_mode(opt_param,
  678. CLISH_PARAM_SUBCOMMAND);
  679. clish_param__set_value(opt_param, prefix);
  680. clish_param__set_optional(opt_param, BOOL_TRUE);
  681. if (test)
  682. clish_param__set_test(opt_param, test);
  683. /* Add the parameter to the command */
  684. if (cmd)
  685. clish_command_insert_param(cmd, opt_param);
  686. /* Add the parameter to the param */
  687. if (p_param)
  688. clish_param_insert_param(p_param, opt_param);
  689. /* Unset cmd and set parent param to opt_param */
  690. cmd = NULL;
  691. p_param = opt_param;
  692. }
  693. if (defval)
  694. clish_param__set_defval(param, defval);
  695. if (hidden && lub_string_nocasecmp(hidden, "true") == 0)
  696. clish_param__set_hidden(param, BOOL_TRUE);
  697. else
  698. clish_param__set_hidden(param, BOOL_FALSE);
  699. if (mode) {
  700. if (lub_string_nocasecmp(mode, "switch") == 0) {
  701. clish_param__set_mode(param,
  702. CLISH_PARAM_SWITCH);
  703. /* Force hidden attribute */
  704. clish_param__set_hidden(param, BOOL_TRUE);
  705. } else if (lub_string_nocasecmp(mode, "subcommand") == 0)
  706. clish_param__set_mode(param,
  707. CLISH_PARAM_SUBCOMMAND);
  708. else
  709. clish_param__set_mode(param,
  710. CLISH_PARAM_COMMON);
  711. }
  712. if (optional && lub_string_nocasecmp(optional, "true") == 0)
  713. clish_param__set_optional(param, BOOL_TRUE);
  714. else
  715. clish_param__set_optional(param, BOOL_FALSE);
  716. if (order && lub_string_nocasecmp(order, "true") == 0)
  717. clish_param__set_order(param, BOOL_TRUE);
  718. else
  719. clish_param__set_order(param, BOOL_FALSE);
  720. if (value) {
  721. clish_param__set_value(param, value);
  722. /* Force mode to subcommand */
  723. clish_param__set_mode(param,
  724. CLISH_PARAM_SUBCOMMAND);
  725. }
  726. if (test && !prefix)
  727. clish_param__set_test(param, test);
  728. if (completion)
  729. clish_param__set_completion(param, completion);
  730. if (access)
  731. clish_param__set_access(param, access);
  732. /* Add the parameter to the command */
  733. if (cmd)
  734. clish_command_insert_param(cmd, param);
  735. /* Add the parameter to the param */
  736. if (p_param)
  737. clish_param_insert_param(p_param, param);
  738. res = process_children(shell, element, param);
  739. error:
  740. clish_xml_release(name);
  741. clish_xml_release(help);
  742. clish_xml_release(ptype);
  743. clish_xml_release(prefix);
  744. clish_xml_release(defval);
  745. clish_xml_release(mode);
  746. clish_xml_release(optional);
  747. clish_xml_release(order);
  748. clish_xml_release(value);
  749. clish_xml_release(hidden);
  750. clish_xml_release(test);
  751. clish_xml_release(completion);
  752. clish_xml_release(access);
  753. return res;
  754. }
  755. /* ------------------------------------------------------ */
  756. static int process_action(clish_shell_t *shell, clish_xmlnode_t *element,
  757. void *parent)
  758. {
  759. clish_action_t *action = NULL;
  760. char *builtin = clish_xmlnode_fetch_attr(element, "builtin");
  761. char *shebang = clish_xmlnode_fetch_attr(element, "shebang");
  762. char *lock = clish_xmlnode_fetch_attr(element, "lock");
  763. char *interrupt = clish_xmlnode_fetch_attr(element, "interrupt");
  764. char *interactive = clish_xmlnode_fetch_attr(element, "interactive");
  765. clish_xmlnode_t *pelement = clish_xmlnode_parent(element);
  766. char *pname = clish_xmlnode_get_all_name(pelement);
  767. char *text;
  768. clish_sym_t *sym = NULL;
  769. if (pname && lub_string_nocasecmp(pname, "VAR") == 0)
  770. action = clish_var__get_action((clish_var_t *)parent);
  771. else if (pname && lub_string_nocasecmp(pname, "PTYPE") == 0)
  772. action = clish_ptype__get_action((clish_ptype_t *)parent);
  773. else
  774. action = clish_command__get_action((clish_command_t *)parent);
  775. if (pname)
  776. free(pname);
  777. text = clish_xmlnode_get_all_content(element);
  778. if (text && *text) {
  779. /* store the action */
  780. clish_action__set_script(action, text);
  781. }
  782. if (text)
  783. free(text);
  784. if (builtin)
  785. sym = clish_shell_add_unresolved_sym(shell, builtin,
  786. CLISH_SYM_TYPE_ACTION);
  787. else
  788. sym = shell->hooks[CLISH_SYM_TYPE_ACTION];
  789. clish_action__set_builtin(action, sym);
  790. if (shebang)
  791. clish_action__set_shebang(action, shebang);
  792. /* lock */
  793. if (lock && lub_string_nocasecmp(lock, "false") == 0)
  794. clish_action__set_lock(action, BOOL_FALSE);
  795. /* interrupt */
  796. if (interrupt && lub_string_nocasecmp(interrupt, "true") == 0)
  797. clish_action__set_interrupt(action, BOOL_TRUE);
  798. clish_xml_release(builtin);
  799. clish_xml_release(shebang);
  800. clish_xml_release(lock);
  801. clish_xml_release(interrupt);
  802. clish_xml_release(interactive);
  803. return 0;
  804. }
  805. /* ------------------------------------------------------ */
  806. static int process_detail(clish_shell_t *shell, clish_xmlnode_t *element,
  807. void *parent)
  808. {
  809. clish_command_t *cmd = (clish_command_t *) parent;
  810. /* read the following text element */
  811. char *text = clish_xmlnode_get_all_content(element);
  812. if (text && *text) {
  813. /* store the action */
  814. clish_command__set_detail(cmd, text);
  815. }
  816. if (text)
  817. free(text);
  818. shell = shell; /* Happy compiler */
  819. return 0;
  820. }
  821. /* ------------------------------------------------------ */
  822. static int process_namespace(clish_shell_t *shell, clish_xmlnode_t *element,
  823. void *parent)
  824. {
  825. clish_view_t *v = (clish_view_t *)parent;
  826. clish_nspace_t *nspace = NULL;
  827. int res = -1;
  828. char *view = clish_xmlnode_fetch_attr(element, "ref");
  829. char *prefix = clish_xmlnode_fetch_attr(element, "prefix");
  830. char *prefix_help = clish_xmlnode_fetch_attr(element, "prefix_help");
  831. char *help = clish_xmlnode_fetch_attr(element, "help");
  832. char *completion = clish_xmlnode_fetch_attr(element, "completion");
  833. char *context_help = clish_xmlnode_fetch_attr(element, "context_help");
  834. char *inherit = clish_xmlnode_fetch_attr(element, "inherit");
  835. char *access = clish_xmlnode_fetch_attr(element, "access");
  836. /* Check syntax */
  837. if (!view) {
  838. fprintf(stderr, CLISH_XML_ERROR_ATTR("ref"));
  839. goto error;
  840. }
  841. clish_view_t *ref_view = clish_shell_find_view(shell, view);
  842. /* Don't include itself without prefix */
  843. if ((ref_view == v) && !prefix)
  844. goto process_namespace_end;
  845. nspace = clish_nspace_new(view);
  846. clish_view_insert_nspace(v, nspace);
  847. if (prefix) {
  848. clish_nspace__set_prefix(nspace, prefix);
  849. if (prefix_help)
  850. clish_nspace_create_prefix_cmd(nspace,
  851. "prefix",
  852. prefix_help);
  853. else
  854. clish_nspace_create_prefix_cmd(nspace,
  855. "prefix",
  856. "Prefix for the imported commands.");
  857. }
  858. if (help && lub_string_nocasecmp(help, "true") == 0)
  859. clish_nspace__set_help(nspace, BOOL_TRUE);
  860. else
  861. clish_nspace__set_help(nspace, BOOL_FALSE);
  862. if (completion && lub_string_nocasecmp(completion, "false") == 0)
  863. clish_nspace__set_completion(nspace, BOOL_FALSE);
  864. else
  865. clish_nspace__set_completion(nspace, BOOL_TRUE);
  866. if (context_help && lub_string_nocasecmp(context_help, "true") == 0)
  867. clish_nspace__set_context_help(nspace, BOOL_TRUE);
  868. else
  869. clish_nspace__set_context_help(nspace, BOOL_FALSE);
  870. if (inherit && lub_string_nocasecmp(inherit, "false") == 0)
  871. clish_nspace__set_inherit(nspace, BOOL_FALSE);
  872. else
  873. clish_nspace__set_inherit(nspace, BOOL_TRUE);
  874. if (access)
  875. clish_nspace__set_access(nspace, access);
  876. process_namespace_end:
  877. res = 0;
  878. error:
  879. clish_xml_release(view);
  880. clish_xml_release(prefix);
  881. clish_xml_release(prefix_help);
  882. clish_xml_release(help);
  883. clish_xml_release(completion);
  884. clish_xml_release(context_help);
  885. clish_xml_release(inherit);
  886. clish_xml_release(access);
  887. return res;
  888. }
  889. /* ------------------------------------------------------ */
  890. static int process_config(clish_shell_t *shell, clish_xmlnode_t *element,
  891. void *parent)
  892. {
  893. clish_command_t *cmd = (clish_command_t *)parent;
  894. clish_config_t *config;
  895. if (!cmd)
  896. return 0;
  897. config = clish_command__get_config(cmd);
  898. /* read the following text element */
  899. char *operation = clish_xmlnode_fetch_attr(element, "operation");
  900. char *priority = clish_xmlnode_fetch_attr(element, "priority");
  901. char *pattern = clish_xmlnode_fetch_attr(element, "pattern");
  902. char *file = clish_xmlnode_fetch_attr(element, "file");
  903. char *splitter = clish_xmlnode_fetch_attr(element, "splitter");
  904. char *seq = clish_xmlnode_fetch_attr(element, "sequence");
  905. char *unique = clish_xmlnode_fetch_attr(element, "unique");
  906. char *depth = clish_xmlnode_fetch_attr(element, "depth");
  907. if (operation && !lub_string_nocasecmp(operation, "unset"))
  908. clish_config__set_op(config, CLISH_CONFIG_UNSET);
  909. else if (operation && !lub_string_nocasecmp(operation, "none"))
  910. clish_config__set_op(config, CLISH_CONFIG_NONE);
  911. else if (operation && !lub_string_nocasecmp(operation, "dump"))
  912. clish_config__set_op(config, CLISH_CONFIG_DUMP);
  913. else {
  914. clish_config__set_op(config, CLISH_CONFIG_SET);
  915. /* The priority if no clearly specified */
  916. clish_config__set_priority(config, 0x7f00);
  917. }
  918. if (priority) {
  919. unsigned short pri = 0;
  920. lub_conv_atous(priority, &pri, 0);
  921. clish_config__set_priority(config, pri);
  922. }
  923. if (pattern)
  924. clish_config__set_pattern(config, pattern);
  925. else
  926. clish_config__set_pattern(config, "^${__cmd}");
  927. if (file)
  928. clish_config__set_file(config, file);
  929. if (splitter && lub_string_nocasecmp(splitter, "false") == 0)
  930. clish_config__set_splitter(config, BOOL_FALSE);
  931. else
  932. clish_config__set_splitter(config, BOOL_TRUE);
  933. if (unique && lub_string_nocasecmp(unique, "false") == 0)
  934. clish_config__set_unique(config, BOOL_FALSE);
  935. else
  936. clish_config__set_unique(config, BOOL_TRUE);
  937. if (seq)
  938. clish_config__set_seq(config, seq);
  939. else
  940. /* The entries without sequence cannot be non-unique */
  941. clish_config__set_unique(config, BOOL_TRUE);
  942. if (depth)
  943. clish_config__set_depth(config, depth);
  944. clish_xml_release(operation);
  945. clish_xml_release(priority);
  946. clish_xml_release(pattern);
  947. clish_xml_release(file);
  948. clish_xml_release(splitter);
  949. clish_xml_release(seq);
  950. clish_xml_release(unique);
  951. clish_xml_release(depth);
  952. shell = shell; /* Happy compiler */
  953. return 0;
  954. }
  955. /* ------------------------------------------------------ */
  956. static int process_var(clish_shell_t *shell, clish_xmlnode_t *element,
  957. void *parent)
  958. {
  959. clish_var_t *var = NULL;
  960. int res = -1;
  961. char *name = clish_xmlnode_fetch_attr(element, "name");
  962. char *dynamic = clish_xmlnode_fetch_attr(element, "dynamic");
  963. char *value = clish_xmlnode_fetch_attr(element, "value");
  964. /* Check syntax */
  965. if (!name) {
  966. fprintf(stderr, CLISH_XML_ERROR_ATTR("name"));
  967. goto error;
  968. }
  969. /* Check if this var doesn't already exist */
  970. var = (clish_var_t *)lub_bintree_find(&shell->var_tree, name);
  971. if (var) {
  972. fprintf(stderr, CLISH_XML_ERROR_STR"Duplicate VAR name=\"%s\".\n", name);
  973. goto error;
  974. }
  975. /* Create var instance */
  976. var = clish_var_new(name);
  977. lub_bintree_insert(&shell->var_tree, var);
  978. if (dynamic && lub_string_nocasecmp(dynamic, "true") == 0)
  979. clish_var__set_dynamic(var, BOOL_TRUE);
  980. if (value)
  981. clish_var__set_value(var, value);
  982. res = process_children(shell, element, var);
  983. error:
  984. clish_xml_release(name);
  985. clish_xml_release(dynamic);
  986. clish_xml_release(value);
  987. parent = parent; /* Happy compiler */
  988. return res;
  989. }
  990. /* ------------------------------------------------------ */
  991. static int process_wdog(clish_shell_t *shell,
  992. clish_xmlnode_t *element, void *parent)
  993. {
  994. clish_view_t *v = (clish_view_t *)parent;
  995. clish_command_t *cmd = NULL;
  996. int res = -1;
  997. /* Check syntax */
  998. if (shell->wdog) {
  999. fprintf(stderr, CLISH_XML_ERROR_STR"WATCHDOG tag duplication.\n");
  1000. goto error;
  1001. }
  1002. /* Create a command with NULL help */
  1003. cmd = clish_view_new_command(v, "watchdog", NULL);
  1004. #ifdef LEGACY
  1005. // Legacy watchdog has lockless ACTION
  1006. clish_action__set_lock(clish_command__get_action(cmd), BOOL_FALSE);
  1007. #endif
  1008. /* Remember this command */
  1009. shell->wdog = cmd;
  1010. res = process_children(shell, element, cmd);
  1011. error:
  1012. return res;
  1013. }
  1014. /* ------------------------------------------------------ */
  1015. static int process_hotkey(clish_shell_t *shell, clish_xmlnode_t *element,
  1016. void *parent)
  1017. {
  1018. clish_view_t *v = (clish_view_t *)parent;
  1019. int res = -1;
  1020. char *key = clish_xmlnode_fetch_attr(element, "key");
  1021. char *cmd = clish_xmlnode_fetch_attr(element, "cmd");
  1022. /* Check syntax */
  1023. if (!key) {
  1024. fprintf(stderr, CLISH_XML_ERROR_ATTR("key"));
  1025. goto error;
  1026. }
  1027. if (!cmd) {
  1028. fprintf(stderr, CLISH_XML_ERROR_ATTR("cmd"));
  1029. goto error;
  1030. }
  1031. clish_view_insert_hotkey(v, key, cmd);
  1032. res = 0;
  1033. error:
  1034. clish_xml_release(key);
  1035. clish_xml_release(cmd);
  1036. shell = shell; /* Happy compiler */
  1037. return res;
  1038. }
  1039. /* ------------------------------------------------------ */
  1040. static int process_plugin(clish_shell_t *shell, clish_xmlnode_t *element,
  1041. void *parent)
  1042. {
  1043. clish_plugin_t *plugin;
  1044. char *file = clish_xmlnode_fetch_attr(element, "file");
  1045. char *name = clish_xmlnode_fetch_attr(element, "name");
  1046. char *alias = clish_xmlnode_fetch_attr(element, "alias");
  1047. char *rtld_global = clish_xmlnode_fetch_attr(element, "rtld_global");
  1048. int res = -1;
  1049. char *text;
  1050. /* Check syntax */
  1051. if (!name) {
  1052. fprintf(stderr, CLISH_XML_ERROR_ATTR("name"));
  1053. goto error;
  1054. }
  1055. plugin = clish_shell_find_plugin(shell, name);
  1056. if (plugin) {
  1057. fprintf(stderr,
  1058. CLISH_XML_ERROR_STR"PLUGIN %s duplication.\n", name);
  1059. goto error;
  1060. }
  1061. plugin = clish_shell_create_plugin(shell, name);
  1062. if (alias && *alias)
  1063. clish_plugin__set_alias(plugin, alias);
  1064. if (file && *file)
  1065. clish_plugin__set_file(plugin, file);
  1066. if (rtld_global && lub_string_nocasecmp(rtld_global, "true") == 0)
  1067. clish_plugin__set_rtld_global(plugin, BOOL_TRUE);
  1068. /* Get PLUGIN body content */
  1069. text = clish_xmlnode_get_all_content(element);
  1070. if (text && *text)
  1071. clish_plugin__set_conf(plugin, text);
  1072. if (text)
  1073. free(text);
  1074. res = 0;
  1075. error:
  1076. clish_xml_release(file);
  1077. clish_xml_release(name);
  1078. clish_xml_release(alias);
  1079. clish_xml_release(rtld_global);
  1080. parent = parent; /* Happy compiler */
  1081. return res;
  1082. }
  1083. /* ------------------------------------------------------ */
  1084. static int process_hook(clish_shell_t *shell, clish_xmlnode_t *element,
  1085. void *parent)
  1086. {
  1087. char *name = clish_xmlnode_fetch_attr(element, "name");
  1088. char *builtin = clish_xmlnode_fetch_attr(element, "builtin");
  1089. int res = -1;
  1090. int type = CLISH_SYM_TYPE_NONE;
  1091. /* Check syntax */
  1092. if (!name) {
  1093. fprintf(stderr, CLISH_XML_ERROR_ATTR("name"));
  1094. goto error;
  1095. }
  1096. /* Find out HOOK type */
  1097. if (!strcmp(name, "action"))
  1098. type = CLISH_SYM_TYPE_ACTION;
  1099. else if (!strcmp(name, "access"))
  1100. type = CLISH_SYM_TYPE_ACCESS;
  1101. else if (!strcmp(name, "config"))
  1102. type = CLISH_SYM_TYPE_CONFIG;
  1103. else if (!strcmp(name, "log"))
  1104. type = CLISH_SYM_TYPE_LOG;
  1105. if (CLISH_SYM_TYPE_NONE == type) {
  1106. fprintf(stderr, CLISH_XML_ERROR_STR"Unknown HOOK name %s.\n", name);
  1107. goto error;
  1108. }
  1109. /* Check duplicate HOOK tag */
  1110. if (shell->hooks_use[type]) {
  1111. fprintf(stderr,
  1112. CLISH_XML_ERROR_STR"HOOK %s duplication.\n", name);
  1113. goto error;
  1114. }
  1115. shell->hooks_use[type] = BOOL_TRUE;
  1116. clish_sym__set_name(shell->hooks[type], builtin);
  1117. res = 0;
  1118. error:
  1119. clish_xml_release(name);
  1120. clish_xml_release(builtin);
  1121. parent = parent; /* Happy compiler */
  1122. return res;
  1123. }
  1124. /* ------------------------------------------------------ */