syspkg.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * syspkg/inc/syspkg.h
  3. * https://gitlab.com/bztsrc/syspkg
  4. *
  5. * Copyright (C) 2021 bzt (bztsrc@gitlab)
  6. *
  7. * Permission is hereby granted, free of charge, to any person
  8. * obtaining a copy of this software and associated documentation
  9. * files (the "Software"), to deal in the Software without
  10. * restriction, including without limitation the rights to use, copy,
  11. * modify, merge, publish, distribute, sublicense, and/or sell copies
  12. * of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be
  16. * included in all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  19. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  21. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  22. * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  23. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  25. * DEALINGS IN THE SOFTWARE.
  26. *
  27. * @brief Public API declarations and prototypes
  28. *
  29. */
  30. #ifndef _SYSPKG_H_
  31. #define _SYSPKG_H_
  32. #include <stdint.h>
  33. #include <stdlib.h>
  34. #include <errno.h>
  35. #ifndef SUCCESS
  36. #define SUCCESS 0
  37. #endif
  38. /* progress bar callback prototype and message types */
  39. enum {
  40. SYSPKG_MSG_GENKEYS, /* generating keys */
  41. SYSPKG_MSG_GENCERT, /* generating certificates */
  42. SYSPKG_MSG_GENPAYLOAD, /* generating payloads */
  43. SYSPKG_MSG_CHKPAYLOAD, /* checking payload validity */
  44. SYSPKG_MSG_DLDPAYLOAD, /* downloading payloads */
  45. SYSPKG_MSG_GETREPO, /* downloading repo lists */
  46. SYSPKG_MSG_GETMETA, /* downloading metajsons */
  47. SYSPKG_MSG_CLNMETA, /* cleaning up package database */
  48. SYSPKG_MSG_GENHTML, /* generating package catalog */
  49. SYSPKG_MSG_DELPKG, /* removing packages */
  50. SYSPKG_MSG_UNPPKG, /* unpacking packages */
  51. SYSPKG_MSG_CFGPKG /* configuring packages */
  52. };
  53. typedef void (*syspkg_progressbar_t)(int step, int numstep, int64_t curr, int64_t total, int msg);
  54. enum {
  55. SYSPKG_FORM_NONE,
  56. SYSPKG_FORM_STR, /* string */
  57. SYSPKG_FORM_NUM, /* decimal number */
  58. SYSPKG_FORM_CHK, /* checkbox */
  59. SYSPKG_FORM_SEL /* option list */
  60. };
  61. typedef struct {
  62. char *value; /* value to be returned */
  63. char *name; /* translated label */
  64. char *desc; /* translated popup description */
  65. char type; /* one of the SYSPKG_FORM_* defines above */
  66. union {
  67. char *str;
  68. struct {
  69. int min;
  70. int max;
  71. int def;
  72. } num;
  73. struct {
  74. char *enabled;
  75. char *disabled;
  76. } chk;
  77. struct {
  78. char **opts;
  79. int len;
  80. } sel;
  81. } spec;
  82. } syspkg_input_t;
  83. /* package configuration form callback */
  84. typedef int (*syspkg_conf_t)(char *id, char *name, char *terms, int len, syspkg_input_t *input);
  85. /* bytecode callback */
  86. typedef void (*syspkg_bytecode_t)(unsigned char **buf, int *len);
  87. /* mount point */
  88. typedef struct {
  89. uint64_t fsid;
  90. int64_t freeblks;
  91. int blksiz;
  92. } syspkg_mnts_t;
  93. /* one package description */
  94. typedef struct {
  95. char *id;
  96. unsigned int version;
  97. } syspkg_dep_t;
  98. typedef struct {
  99. char *id; /* package unix name */
  100. char *name; /* name in the current locale */
  101. char *desc; /* description in the current locale */
  102. char *category; /* package's category, not translated */
  103. char *license; /* license identifier */
  104. char *url; /* download url */
  105. char *homepage; /* webpage */
  106. char *bugtracker; /* issue page */
  107. syspkg_dep_t *depends; /* mandatory dependencies */
  108. syspkg_dep_t *suggests; /* optional dependencies */
  109. syspkg_dep_t *conflicts; /* conflicting packages */
  110. char *maintainer; /* maintainer's canonical name */
  111. char *release; /* available version */
  112. char *irelease; /* installed version or NULL */
  113. unsigned int version; /* available version (maj << 16) | (feat << 8) | (fix) */
  114. unsigned int iversion; /* installed version or 0 */
  115. unsigned int afirst, alast; /* first and last screenshot's attachment id or -1U */
  116. int err; /* recursion level when it was selected or negative error code */
  117. } syspkg_package_t;
  118. typedef struct {
  119. char *id; /* package unix name */
  120. char **depends; /* dependencies */
  121. char **conflicts; /* conflicts */
  122. char *path; /* a file installed by this package */
  123. char *url; /* metajson url */
  124. char *irelease; /* installed version or NULL */
  125. unsigned int iversion; /* installed version or 0 */
  126. unsigned int iref; /* number of references to this package */
  127. } syspkg_installed_t;
  128. typedef struct {
  129. char *url; /* repo url */
  130. char *cn; /* canonical name */
  131. unsigned int num; /* number of packages in this repo */
  132. } syspkg_repo_t;
  133. /* the main context */
  134. typedef struct {
  135. syspkg_progressbar_t progressbar;/* progress bar callback */
  136. syspkg_conf_t conf; /* configure package form callback */
  137. syspkg_bytecode_t bytecode; /* bytecode converter callback */
  138. char *cfgdir; /* user local configuration directory */
  139. char *cert; /* returned certificate */
  140. char *lang; /* detected language */
  141. char *osver; /* optional OS version filter */
  142. char **arch; /* supported architectures */
  143. char **license; /* supported licenses */
  144. char **repourls; /* list of repository urls */
  145. syspkg_repo_t *repos; /* returned list of repositories */
  146. syspkg_installed_t *inst; /* list of installed packages */
  147. syspkg_package_t **packages;/* returned list of packages */
  148. syspkg_package_t **installs;/* packages to be installed */
  149. syspkg_package_t **removes; /* packages to be removed */
  150. syspkg_dep_t **suggests; /* returned list of suggested packages */
  151. syspkg_dep_t **missing; /* returned list of unmet dependencies */
  152. char **conflicts; /* returned list of conflicting package pairs */
  153. syspkg_mnts_t *mnts; /* mount points, to count free space */
  154. int numinst; /* number of installed packages */
  155. int numpackages; /* number of returned packages */
  156. int numinstalls; /* number of packages to be installed */
  157. int numremoves; /* number of packages to be removed */
  158. int numsuggests; /* number of suggested packages */
  159. int nummissing; /* number of missing packages */
  160. int numconflicts; /* number of conflicting packages */
  161. int numfiles; /* number of files in the database */
  162. int nummnts; /* number of mount points */
  163. size_t dlsize, total; /* total bytes to download and install (or remove) */
  164. size_t comp; /* largest compressed file */
  165. } syspkg_ctx_t;
  166. /*** Public API ***/
  167. /* pkg.c */
  168. syspkg_ctx_t *syspkg_new(syspkg_progressbar_t progressbar, syspkg_conf_t conf);
  169. int syspkg_free(syspkg_ctx_t *ctx);
  170. /* cert.c */
  171. int syspkg_cert(syspkg_ctx_t *ctx, char *name, char *countrycode, int isrepo);
  172. int syspkg_sign(syspkg_ctx_t *ctx, char *crtfile);
  173. int syspkg_revoke(syspkg_ctx_t *ctx, char *crtfile);
  174. int syspkg_trust(syspkg_ctx_t *ctx, char *crtfile);
  175. int syspkg_untrust(syspkg_ctx_t *ctx, char *cn);
  176. /* meta.c */
  177. int syspkg_build(syspkg_ctx_t *ctx, char *jsonfile, int numpl, char **plspec);
  178. int syspkg_check(syspkg_ctx_t *ctx, char *url);
  179. int syspkg_search(syspkg_ctx_t *ctx, int installed, char *search, char *depends, int *ids);
  180. int syspkg_which(syspkg_ctx_t *ctx, char *search);
  181. /* repo.c */
  182. int syspkg_addrepo(syspkg_ctx_t *ctx, char *url);
  183. int syspkg_delrepo(syspkg_ctx_t *ctx, char *name);
  184. int syspkg_listrepo(syspkg_ctx_t *ctx);
  185. /* package.c */
  186. int syspkg_update(syspkg_ctx_t *ctx);
  187. int syspkg_upgrade(syspkg_ctx_t *ctx);
  188. int syspkg_remove(syspkg_ctx_t *ctx, char **name, int nodeps);
  189. int syspkg_install(syspkg_ctx_t *ctx, char **name, int nodeps);
  190. int syspkg_reconf(syspkg_ctx_t *ctx, char **name);
  191. int syspkg_commit(syspkg_ctx_t *ctx);
  192. /* attach.c */
  193. unsigned int *syspkg_loadattachment(unsigned int aidx, int size);
  194. #endif /* _SYSPKG_H_ */