list.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. /*
  2. * libuci - Library for the Unified Configuration Interface
  3. * Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License version 2.1
  7. * as published by the Free Software Foundation
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. /* initialize a list head/item */
  15. static inline void uci_list_init(struct uci_list *ptr)
  16. {
  17. ptr->prev = ptr;
  18. ptr->next = ptr;
  19. }
  20. /* inserts a new list entry after a given entry */
  21. static inline void uci_list_insert(struct uci_list *list, struct uci_list *ptr)
  22. {
  23. list->next->prev = ptr;
  24. ptr->prev = list;
  25. ptr->next = list->next;
  26. list->next = ptr;
  27. }
  28. /* inserts a new list entry at the tail of the list */
  29. static inline void uci_list_add(struct uci_list *head, struct uci_list *ptr)
  30. {
  31. /* NB: head->prev points at the tail */
  32. uci_list_insert(head->prev, ptr);
  33. }
  34. static inline void uci_list_del(struct uci_list *ptr)
  35. {
  36. struct uci_list *next, *prev;
  37. next = ptr->next;
  38. prev = ptr->prev;
  39. prev->next = next;
  40. next->prev = prev;
  41. uci_list_init(ptr);
  42. }
  43. static inline void uci_list_set_pos(struct uci_list *head, struct uci_list *ptr, int pos)
  44. {
  45. struct uci_list *new_head = head;
  46. struct uci_element *p = NULL;
  47. uci_list_del(ptr);
  48. uci_foreach_element(head, p) {
  49. new_head = &p->list;
  50. if (pos-- <= 0)
  51. break;
  52. }
  53. uci_list_add(new_head, ptr);
  54. }
  55. static inline void uci_list_fixup(struct uci_list *ptr)
  56. {
  57. ptr->prev->next = ptr;
  58. ptr->next->prev = ptr;
  59. }
  60. /*
  61. * uci_alloc_generic allocates a new uci_element with payload
  62. * payload is appended to the struct to save memory and reduce fragmentation
  63. */
  64. static struct uci_element *
  65. uci_alloc_generic(struct uci_context *ctx, int type, const char *name, int size)
  66. {
  67. struct uci_element *e;
  68. int datalen = size;
  69. void *ptr;
  70. ptr = uci_malloc(ctx, datalen);
  71. e = (struct uci_element *) ptr;
  72. e->type = type;
  73. if (name) {
  74. UCI_TRAP_SAVE(ctx, error);
  75. e->name = uci_strdup(ctx, name);
  76. UCI_TRAP_RESTORE(ctx);
  77. }
  78. uci_list_init(&e->list);
  79. goto done;
  80. error:
  81. free(ptr);
  82. UCI_THROW(ctx, ctx->err);
  83. done:
  84. return e;
  85. }
  86. static void
  87. uci_free_element(struct uci_element *e)
  88. {
  89. if (e->name)
  90. free(e->name);
  91. if (!uci_list_empty(&e->list))
  92. uci_list_del(&e->list);
  93. free(e);
  94. }
  95. static struct uci_option *
  96. uci_alloc_option(struct uci_section *s, const char *name, const char *value)
  97. {
  98. struct uci_package *p = s->package;
  99. struct uci_context *ctx = p->ctx;
  100. struct uci_option *o;
  101. o = uci_alloc_element(ctx, option, name, strlen(value) + 1);
  102. o->type = UCI_TYPE_STRING;
  103. o->v.string = uci_dataptr(o);
  104. o->section = s;
  105. strcpy(o->v.string, value);
  106. uci_list_add(&s->options, &o->e.list);
  107. return o;
  108. }
  109. static inline void
  110. uci_free_option(struct uci_option *o)
  111. {
  112. struct uci_element *e, *tmp;
  113. switch(o->type) {
  114. case UCI_TYPE_STRING:
  115. if ((o->v.string != uci_dataptr(o)) &&
  116. (o->v.string != NULL))
  117. free(o->v.string);
  118. break;
  119. case UCI_TYPE_LIST:
  120. uci_foreach_element_safe(&o->v.list, tmp, e) {
  121. uci_free_element(e);
  122. }
  123. break;
  124. default:
  125. break;
  126. }
  127. uci_free_element(&o->e);
  128. }
  129. static struct uci_option *
  130. uci_alloc_list(struct uci_section *s, const char *name)
  131. {
  132. struct uci_package *p = s->package;
  133. struct uci_context *ctx = p->ctx;
  134. struct uci_option *o;
  135. o = uci_alloc_element(ctx, option, name, 0);
  136. o->type = UCI_TYPE_LIST;
  137. o->section = s;
  138. uci_list_init(&o->v.list);
  139. uci_list_add(&s->options, &o->e.list);
  140. return o;
  141. }
  142. /* fix up an unnamed section, e.g. after adding options to it */
  143. static void uci_fixup_section(struct uci_context *ctx, struct uci_section *s)
  144. {
  145. unsigned int hash = ~0;
  146. struct uci_element *e;
  147. char buf[16];
  148. if (!s || s->e.name)
  149. return;
  150. /*
  151. * Generate a name for unnamed sections. This is used as reference
  152. * when locating or updating the section from apps/scripts.
  153. * To make multiple concurrent versions somewhat safe for updating,
  154. * the name is generated from a hash of its type and name/value
  155. * pairs of its option, and it is prefixed by a counter value.
  156. * If the order of the unnamed sections changes for some reason,
  157. * updates to them will be rejected.
  158. */
  159. hash = djbhash(hash, s->type);
  160. uci_foreach_element(&s->options, e) {
  161. struct uci_option *o;
  162. hash = djbhash(hash, e->name);
  163. o = uci_to_option(e);
  164. switch(o->type) {
  165. case UCI_TYPE_STRING:
  166. hash = djbhash(hash, o->v.string);
  167. break;
  168. default:
  169. break;
  170. }
  171. }
  172. sprintf(buf, "cfg%02x%04x", ++s->package->n_section, hash % (1 << 16));
  173. s->e.name = uci_strdup(ctx, buf);
  174. }
  175. static struct uci_section *
  176. uci_alloc_section(struct uci_package *p, const char *type, const char *name)
  177. {
  178. struct uci_context *ctx = p->ctx;
  179. struct uci_section *s;
  180. if (name && !name[0])
  181. name = NULL;
  182. s = uci_alloc_element(ctx, section, name, strlen(type) + 1);
  183. uci_list_init(&s->options);
  184. s->type = uci_dataptr(s);
  185. s->package = p;
  186. strcpy(s->type, type);
  187. if (name == NULL)
  188. s->anonymous = true;
  189. p->n_section++;
  190. uci_list_add(&p->sections, &s->e.list);
  191. return s;
  192. }
  193. static void
  194. uci_free_section(struct uci_section *s)
  195. {
  196. struct uci_element *o, *tmp;
  197. uci_foreach_element_safe(&s->options, tmp, o) {
  198. uci_free_option(uci_to_option(o));
  199. }
  200. if ((s->type != uci_dataptr(s)) &&
  201. (s->type != NULL))
  202. free(s->type);
  203. uci_free_element(&s->e);
  204. }
  205. __plugin struct uci_package *
  206. uci_alloc_package(struct uci_context *ctx, const char *name)
  207. {
  208. struct uci_package *p;
  209. p = uci_alloc_element(ctx, package, name, 0);
  210. p->ctx = ctx;
  211. uci_list_init(&p->sections);
  212. uci_list_init(&p->history);
  213. uci_list_init(&p->saved_history);
  214. return p;
  215. }
  216. static void
  217. uci_free_package(struct uci_package **package)
  218. {
  219. struct uci_element *e, *tmp;
  220. struct uci_package *p = *package;
  221. if(!p)
  222. return;
  223. if (p->path)
  224. free(p->path);
  225. uci_foreach_element_safe(&p->sections, tmp, e) {
  226. uci_free_section(uci_to_section(e));
  227. }
  228. uci_foreach_element_safe(&p->history, tmp, e) {
  229. uci_free_history(uci_to_history(e));
  230. }
  231. uci_foreach_element_safe(&p->saved_history, tmp, e) {
  232. uci_free_history(uci_to_history(e));
  233. }
  234. uci_free_element(&p->e);
  235. *package = NULL;
  236. }
  237. static void
  238. uci_free_any(struct uci_element **e)
  239. {
  240. switch((*e)->type) {
  241. case UCI_TYPE_SECTION:
  242. uci_free_section(uci_to_section(*e));
  243. break;
  244. case UCI_TYPE_OPTION:
  245. uci_free_option(uci_to_option(*e));
  246. break;
  247. default:
  248. break;
  249. }
  250. *e = NULL;
  251. }
  252. static inline struct uci_element *
  253. uci_lookup_list(struct uci_list *list, const char *name)
  254. {
  255. struct uci_element *e;
  256. uci_foreach_element(list, e) {
  257. if (!strcmp(e->name, name))
  258. return e;
  259. }
  260. return NULL;
  261. }
  262. static struct uci_element *
  263. uci_lookup_ext_section(struct uci_context *ctx, struct uci_ptr *ptr)
  264. {
  265. char *idxstr, *t, *section, *name;
  266. struct uci_element *e = NULL;
  267. struct uci_section *s;
  268. int idx, c;
  269. section = uci_strdup(ctx, ptr->section);
  270. name = idxstr = section + 1;
  271. if (section[0] != '@')
  272. goto error;
  273. /* parse the section index part */
  274. idxstr = strchr(idxstr, '[');
  275. if (!idxstr)
  276. goto error;
  277. *idxstr = 0;
  278. idxstr++;
  279. t = strchr(idxstr, ']');
  280. if (!t)
  281. goto error;
  282. if (t[1] != 0)
  283. goto error;
  284. *t = 0;
  285. t = NULL;
  286. idx = strtol(idxstr, &t, 10);
  287. if (t && *t)
  288. goto error;
  289. if (!*name)
  290. name = NULL;
  291. else if (!uci_validate_type(name))
  292. goto error;
  293. /* if the given index is negative, it specifies the section number from
  294. * the end of the list */
  295. if (idx < 0) {
  296. c = 0;
  297. uci_foreach_element(&ptr->p->sections, e) {
  298. s = uci_to_section(e);
  299. if (name && (strcmp(s->type, name) != 0))
  300. continue;
  301. c++;
  302. }
  303. idx += c;
  304. }
  305. c = 0;
  306. uci_foreach_element(&ptr->p->sections, e) {
  307. s = uci_to_section(e);
  308. if (name && (strcmp(s->type, name) != 0))
  309. continue;
  310. if (idx == c)
  311. goto done;
  312. c++;
  313. }
  314. e = NULL;
  315. goto done;
  316. error:
  317. e = NULL;
  318. memset(ptr, 0, sizeof(struct uci_ptr));
  319. UCI_THROW(ctx, UCI_ERR_INVAL);
  320. done:
  321. free(section);
  322. if (e)
  323. ptr->section = e->name;
  324. return e;
  325. }
  326. int
  327. uci_lookup_ptr(struct uci_context *ctx, struct uci_ptr *ptr, char *str, bool extended)
  328. {
  329. struct uci_element *e;
  330. UCI_HANDLE_ERR(ctx);
  331. UCI_ASSERT(ctx, ptr != NULL);
  332. if (str)
  333. UCI_INTERNAL(uci_parse_ptr, ctx, ptr, str);
  334. ptr->flags |= UCI_LOOKUP_DONE;
  335. /* look up the package first */
  336. e = uci_lookup_list(&ctx->root, ptr->package);
  337. if (!e) {
  338. UCI_INTERNAL(uci_load, ctx, ptr->package, &ptr->p);
  339. if (!ptr->p)
  340. goto notfound;
  341. ptr->last = &ptr->p->e;
  342. } else {
  343. ptr->p = uci_to_package(e);
  344. ptr->last = e;
  345. }
  346. if (!ptr->section)
  347. goto complete;
  348. /* if the section name validates as a regular name, pass through
  349. * to the regular uci_lookup function call */
  350. if (ptr->flags & UCI_LOOKUP_EXTENDED)
  351. e = uci_lookup_ext_section(ctx, ptr);
  352. else
  353. e = uci_lookup_list(&ptr->p->sections, ptr->section);
  354. if (!e)
  355. goto abort;
  356. ptr->last = e;
  357. ptr->s = uci_to_section(e);
  358. if (ptr->option) {
  359. e = uci_lookup_list(&ptr->s->options, ptr->option);
  360. if (!e)
  361. goto abort;
  362. ptr->o = uci_to_option(e);
  363. ptr->last = e;
  364. }
  365. complete:
  366. ptr->flags |= UCI_LOOKUP_COMPLETE;
  367. abort:
  368. return 0;
  369. notfound:
  370. UCI_THROW(ctx, UCI_ERR_NOTFOUND);
  371. return 0;
  372. }
  373. int
  374. uci_fill_ptr(struct uci_context *ctx, struct uci_ptr *ptr, struct uci_element *e, bool complete)
  375. {
  376. UCI_HANDLE_ERR(ctx);
  377. UCI_ASSERT(ctx, ptr != NULL);
  378. UCI_ASSERT(ctx, e != NULL);
  379. memset(ptr, 0, sizeof(struct uci_ptr));
  380. switch(e->type) {
  381. case UCI_TYPE_OPTION:
  382. ptr->o = uci_to_option(e);
  383. goto fill_option;
  384. case UCI_TYPE_SECTION:
  385. ptr->s = uci_to_section(e);
  386. goto fill_section;
  387. case UCI_TYPE_PACKAGE:
  388. ptr->p = uci_to_package(e);
  389. goto fill_package;
  390. default:
  391. UCI_THROW(ctx, UCI_ERR_INVAL);
  392. }
  393. fill_option:
  394. ptr->option = ptr->o->e.name;
  395. ptr->s = ptr->o->section;
  396. fill_section:
  397. ptr->section = ptr->s->e.name;
  398. ptr->p = ptr->s->package;
  399. fill_package:
  400. ptr->package = ptr->p->e.name;
  401. ptr->flags |= UCI_LOOKUP_DONE;
  402. if (complete)
  403. ptr->flags |= UCI_LOOKUP_COMPLETE;
  404. return 0;
  405. }
  406. static struct uci_element *
  407. expand_ptr(struct uci_context *ctx, struct uci_ptr *ptr, bool complete)
  408. {
  409. UCI_ASSERT(ctx, ptr != NULL);
  410. if (!(ptr->flags & UCI_LOOKUP_DONE))
  411. UCI_INTERNAL(uci_lookup_ptr, ctx, ptr, NULL, 1);
  412. if (complete && !(ptr->flags & UCI_LOOKUP_COMPLETE))
  413. UCI_THROW(ctx, UCI_ERR_NOTFOUND);
  414. UCI_ASSERT(ctx, ptr->p != NULL);
  415. /* fill in missing string info */
  416. if (ptr->p && !ptr->package)
  417. ptr->package = ptr->p->e.name;
  418. if (ptr->s && !ptr->section)
  419. ptr->section = ptr->s->e.name;
  420. if (ptr->o && !ptr->option)
  421. ptr->option = ptr->o->e.name;
  422. if (ptr->o)
  423. return &ptr->o->e;
  424. if (ptr->s)
  425. return &ptr->s->e;
  426. if (ptr->p)
  427. return &ptr->p->e;
  428. else
  429. return NULL;
  430. }
  431. static void uci_add_element_list(struct uci_context *ctx, struct uci_ptr *ptr, bool internal)
  432. {
  433. struct uci_element *e;
  434. struct uci_package *p;
  435. p = ptr->p;
  436. if (!internal && p->has_history)
  437. uci_add_history(ctx, &p->history, UCI_CMD_LIST_ADD, ptr->section, ptr->option, ptr->value);
  438. e = uci_alloc_generic(ctx, UCI_TYPE_ITEM, ptr->value, sizeof(struct uci_option));
  439. uci_list_add(&ptr->o->v.list, &e->list);
  440. }
  441. int uci_rename(struct uci_context *ctx, struct uci_ptr *ptr)
  442. {
  443. /* NB: UCI_INTERNAL use means without history tracking */
  444. bool internal = ctx->internal;
  445. struct uci_element *e;
  446. struct uci_package *p;
  447. char *n;
  448. UCI_HANDLE_ERR(ctx);
  449. e = expand_ptr(ctx, ptr, true);
  450. p = ptr->p;
  451. UCI_ASSERT(ctx, ptr->s);
  452. UCI_ASSERT(ctx, ptr->value);
  453. if (!internal && p->has_history)
  454. uci_add_history(ctx, &p->history, UCI_CMD_RENAME, ptr->section, ptr->option, ptr->value);
  455. n = uci_strdup(ctx, ptr->value);
  456. if (e->name)
  457. free(e->name);
  458. e->name = n;
  459. if (e->type == UCI_TYPE_SECTION)
  460. uci_to_section(e)->anonymous = false;
  461. return 0;
  462. }
  463. int uci_reorder_section(struct uci_context *ctx, struct uci_section *s, int pos)
  464. {
  465. struct uci_package *p = s->package;
  466. char order[32];
  467. UCI_HANDLE_ERR(ctx);
  468. uci_list_set_pos(&s->package->sections, &s->e.list, pos);
  469. if (!ctx->internal && p->has_history) {
  470. sprintf(order, "%d", pos);
  471. uci_add_history(ctx, &p->history, UCI_CMD_REORDER, s->e.name, NULL, order);
  472. }
  473. return 0;
  474. }
  475. int uci_add_section(struct uci_context *ctx, struct uci_package *p, const char *type, struct uci_section **res)
  476. {
  477. bool internal = ctx->internal;
  478. struct uci_section *s;
  479. UCI_HANDLE_ERR(ctx);
  480. UCI_ASSERT(ctx, p != NULL);
  481. s = uci_alloc_section(p, type, NULL);
  482. uci_fixup_section(ctx, s);
  483. *res = s;
  484. if (!internal && p->has_history)
  485. uci_add_history(ctx, &p->history, UCI_CMD_ADD, s->e.name, NULL, type);
  486. return 0;
  487. }
  488. int uci_delete(struct uci_context *ctx, struct uci_ptr *ptr)
  489. {
  490. /* NB: pass on internal flag to uci_del_element */
  491. bool internal = ctx->internal;
  492. struct uci_package *p;
  493. struct uci_element *e;
  494. UCI_HANDLE_ERR(ctx);
  495. e = expand_ptr(ctx, ptr, true);
  496. p = ptr->p;
  497. UCI_ASSERT(ctx, ptr->s);
  498. if (!internal && p->has_history)
  499. uci_add_history(ctx, &p->history, UCI_CMD_REMOVE, ptr->section, ptr->option, NULL);
  500. uci_free_any(&e);
  501. if (ptr->option)
  502. ptr->o = NULL;
  503. else if (ptr->section)
  504. ptr->s = NULL;
  505. return 0;
  506. }
  507. int uci_add_list(struct uci_context *ctx, struct uci_ptr *ptr)
  508. {
  509. /* NB: UCI_INTERNAL use means without history tracking */
  510. bool internal = ctx->internal;
  511. struct uci_option *prev = NULL;
  512. const char *value2 = NULL;
  513. UCI_HANDLE_ERR(ctx);
  514. expand_ptr(ctx, ptr, false);
  515. UCI_ASSERT(ctx, ptr->s);
  516. UCI_ASSERT(ctx, ptr->value);
  517. if (ptr->o) {
  518. switch (ptr->o->type) {
  519. case UCI_TYPE_STRING:
  520. /* we already have a string value, convert that to a list */
  521. prev = ptr->o;
  522. value2 = ptr->value;
  523. ptr->value = ptr->o->v.string;
  524. break;
  525. case UCI_TYPE_LIST:
  526. uci_add_element_list(ctx, ptr, internal);
  527. return 0;
  528. default:
  529. UCI_THROW(ctx, UCI_ERR_INVAL);
  530. break;
  531. }
  532. }
  533. ptr->o = uci_alloc_list(ptr->s, ptr->option);
  534. if (prev) {
  535. uci_add_element_list(ctx, ptr, true);
  536. uci_free_option(prev);
  537. ptr->value = value2;
  538. }
  539. uci_add_element_list(ctx, ptr, internal);
  540. return 0;
  541. }
  542. int uci_set(struct uci_context *ctx, struct uci_ptr *ptr)
  543. {
  544. /* NB: UCI_INTERNAL use means without history tracking */
  545. bool internal = ctx->internal;
  546. UCI_HANDLE_ERR(ctx);
  547. expand_ptr(ctx, ptr, false);
  548. UCI_ASSERT(ctx, ptr->value);
  549. UCI_ASSERT(ctx, ptr->s || (!ptr->option && ptr->section));
  550. if (!ptr->option) {
  551. UCI_ASSERT(ctx, uci_validate_type(ptr->value));
  552. }
  553. if (!ptr->o && ptr->s && ptr->option) {
  554. struct uci_element *e;
  555. e = uci_lookup_list(&ptr->s->options, ptr->option);
  556. if (e)
  557. ptr->o = uci_to_option(e);
  558. }
  559. if (!ptr->o && ptr->option) { /* new option */
  560. ptr->o = uci_alloc_option(ptr->s, ptr->option, ptr->value);
  561. ptr->last = &ptr->o->e;
  562. } else if (!ptr->s && ptr->section) { /* new section */
  563. ptr->s = uci_alloc_section(ptr->p, ptr->value, ptr->section);
  564. ptr->last = &ptr->s->e;
  565. } else if (ptr->o && ptr->option) { /* update option */
  566. if ((ptr->o->type == UCI_TYPE_STRING) &&
  567. !strcmp(ptr->o->v.string, ptr->value))
  568. return 0;
  569. uci_free_option(ptr->o);
  570. ptr->o = uci_alloc_option(ptr->s, ptr->option, ptr->value);
  571. ptr->last = &ptr->o->e;
  572. } else if (ptr->s && ptr->section) { /* update section */
  573. char *s = uci_strdup(ctx, ptr->value);
  574. if (ptr->s->type == uci_dataptr(ptr->s)) {
  575. ptr->last = NULL;
  576. ptr->last = uci_realloc(ctx, ptr->s, sizeof(struct uci_section));
  577. ptr->s = uci_to_section(ptr->last);
  578. uci_list_fixup(&ptr->s->e.list);
  579. } else {
  580. free(ptr->s->type);
  581. }
  582. ptr->s->type = s;
  583. } else {
  584. UCI_THROW(ctx, UCI_ERR_INVAL);
  585. }
  586. if (!internal && ptr->p->has_history)
  587. uci_add_history(ctx, &ptr->p->history, UCI_CMD_CHANGE, ptr->section, ptr->option, ptr->value);
  588. return 0;
  589. }
  590. int uci_unload(struct uci_context *ctx, struct uci_package *p)
  591. {
  592. UCI_HANDLE_ERR(ctx);
  593. UCI_ASSERT(ctx, p != NULL);
  594. uci_free_package(&p);
  595. return 0;
  596. }