STASIS
A pipeline delivery generator
Loading...
Searching...
No Matches
wheel.h
Go to the documentation of this file.
1#ifndef WHEEL_H
2#define WHEEL_H
3
4#include <stdio.h>
5#include <stdlib.h>
6#include <string.h>
7#include <fnmatch.h>
8#include <zip.h>
9
10#define WHEEL_MAXELEM 255
11
12#define WHEEL_FROM_DIST 0
13#define WHEEL_FROM_METADATA 1
14
15enum {
16 WHEEL_META_METADATA_VERSION=0,
17 WHEEL_META_NAME,
18 WHEEL_META_VERSION,
19 WHEEL_META_AUTHOR,
20 WHEEL_META_AUTHOR_EMAIL,
21 WHEEL_META_MAINTAINER,
22 WHEEL_META_MAINTAINER_EMAIL,
23 WHEEL_META_SUMMARY,
24 WHEEL_META_LICENSE,
25 WHEEL_META_LICENSE_EXPRESSION,
26 WHEEL_META_LICENSE_FILE,
27 WHEEL_META_HOME_PAGE,
28 WHEEL_META_DOWNLOAD_URL,
29 WHEEL_META_PROJECT_URL,
30 WHEEL_META_CLASSIFIER,
31 WHEEL_META_REQUIRES_PYTHON,
32 WHEEL_META_REQUIRES_EXTERNAL,
33 WHEEL_META_IMPORT_NAME,
34 WHEEL_META_IMPORT_NAMESPACE,
35 WHEEL_META_REQUIRES_DIST,
36 WHEEL_META_PROVIDES,
37 WHEEL_META_PROVIDES_DIST,
38 WHEEL_META_PROVIDES_EXTRA,
39 WHEEL_META_OBSOLETES,
40 WHEEL_META_OBSOLETES_DIST,
41 WHEEL_META_PLATFORM,
42 WHEEL_META_SUPPORTED_PLATFORM,
43 WHEEL_META_KEYWORDS,
44 WHEEL_META_DYNAMIC,
45 WHEEL_META_DESCRIPTION_CONTENT_TYPE,
46 WHEEL_META_DESCRIPTION,
47 WHEEL_META_END_ENUM, // NOP
48};
49
50
51enum {
52 WHEEL_DIST_VERSION=0,
53 WHEEL_DIST_GENERATOR,
54 WHEEL_DIST_ROOT_IS_PURELIB,
55 WHEEL_DIST_TAG,
56 WHEEL_DIST_ZIP_SAFE,
57 WHEEL_DIST_TOP_LEVEL,
58 WHEEL_DIST_ENTRY_POINT,
59 WHEEL_DIST_RECORD,
60 WHEEL_DIST_END_ENUM, // NOP
61};
62
64 char *target;
65 struct StrList *requires_dist;
66 int count;
67};
68
70 char *metadata_version;
71 char *name;
72 char *version;
73 char *summary;
74 struct StrList *author;
75 struct StrList *author_email;
76 struct StrList *maintainer;
77 struct StrList *maintainer_email;
78 char *license;
79 char *license_expression;
80 char *home_page;
81 char * download_url;
82 struct StrList *project_url;
83 struct StrList *classifier;
84 struct StrList *requires_python;
85 struct StrList *requires_external;
86 char *description_content_type;
87 struct StrList *license_file;
88 struct StrList *import_name;
89 struct StrList *import_namespace;
90 struct StrList *requires_dist;
91 struct StrList *provides;
92 struct StrList *provides_dist;
93 struct StrList *obsoletes;
94 struct StrList *obsoletes_dist;
95 char *description;
96 struct StrList *platform;
97 struct StrList *supported_platform;
98 struct StrList *keywords;
99 struct StrList *dynamic;
100
101 struct WheelMetadata_ProvidesExtra **provides_extra;
102};
103
105 char *filename;
106 char *checksum;
107 size_t size;
108};
109
111 char *name;
112 char *function;
113 char *type;
114};
115
116/*
117Wheel-Version: 1.0
118Generator: setuptools (75.8.0)
119Root-Is-Purelib: false
120Tag: cp313-cp313-manylinux_2_17_x86_64
121Tag: cp313-cp313-manylinux2014_x86_64
122*/
123
124struct Wheel {
125 char *wheel_version;
126 char *generator;
127 char *root_is_pure_lib;
128 struct StrList *tag;
129 struct StrList *top_level;
130 int zip_safe;
131 struct WheelMetadata *metadata;
132 struct WheelRecord **record;
133 size_t num_record;
134 struct WheelEntryPoint **entry_point;
135 size_t num_entry_point;
136};
137
138#define METADATA_MULTILINE_PREFIX " "
139
140
141static inline int consume_append(char **dest, const char *src, const char *accept) {
142 const char *start = src;
143 if (!strncmp(src, METADATA_MULTILINE_PREFIX, strlen(METADATA_MULTILINE_PREFIX))) {
144 start += strlen(METADATA_MULTILINE_PREFIX);
145 }
146
147 const char *end = strpbrk(start, accept);
148 size_t cut_len = end ? (size_t)(end - start) : strlen(start);
149 size_t dest_len = strlen(*dest);
150
151 char *tmp = realloc(*dest, strlen(*dest) + cut_len + 2);
152 if (!tmp) {
153 return -1;
154 }
155 *dest = tmp;
156 memcpy(*dest + dest_len, start, cut_len);
157
158 dest_len += cut_len;
159 (*dest)[dest_len ? dest_len : 0] = '\n';
160 (*dest)[dest_len + 1] = '\0';
161 return 0;
162}
163
164#define WHEEL_KEY_UNKNOWN (-1)
165enum {
166 WHEELVAL_STR = 0,
167 WHEELVAL_STRLIST,
168 WHEELVAL_OBJ_EXTRA,
169 WHEELVAL_OBJ_RECORD,
170 WHEELVAL_OBJ_ENTRY_POINT,
171};
172
174 int type;
175 size_t count;
176 void *data;
177};
178
179enum {
180 WHEEL_PACKAGE_E_SUCCESS=0,
181 WHEEL_PACKAGE_E_FILENAME=-1,
182 WHEEL_PACKAGE_E_ALLOC=-2,
183 WHEEL_PACKAGE_E_GET=-3,
184 WHEEL_PACKAGE_E_GET_METADATA=-4,
185 WHEEL_PACKAGE_E_GET_TOP_LEVEL=-5,
186 WHEEL_PACKAGE_E_GET_RECORDS=-6,
187 WHEEL_PACKAGE_E_GET_ENTRY_POINT=-7,
188};
189
197int wheel_package(struct Wheel **pkg, const char *filename);
198
203void wheel_package_free(struct Wheel **pkg);
204
205
213struct WheelValue wheel_get_value_by_name(const struct Wheel *pkg, int from, const char *key);
214
215
223struct WheelValue wheel_get_value_by_id(const struct Wheel *pkg, int from, ssize_t id);
224
230int wheel_value_error(struct WheelValue const *val);
231
238const char *wheel_get_key_by_id(int from, ssize_t id);
239
247int wheel_get_file_contents(const char *wheelfile, const char *filename, char **contents);
248
255int wheel_show_info(const struct Wheel *wheel);
256
257#endif //WHEEL_H
Definition strlist.h:16
Definition wheel.h:110
Definition wheel.h:63
Definition wheel.h:69
Definition wheel.h:104
Definition wheel.h:173
Definition wheel.h:124
int wheel_show_info(const struct Wheel *wheel)
Definition wheel.c:1217
int wheel_get_file_contents(const char *wheelfile, const char *filename, char **contents)
Definition wheel.c:640
const char * wheel_get_key_by_id(int from, ssize_t id)
Definition wheel.c:899
void wheel_package_free(struct Wheel **pkg)
Definition wheel.c:997
int wheel_value_error(struct WheelValue const *val)
Definition wheel.c:1208
struct WheelValue wheel_get_value_by_name(const struct Wheel *pkg, int from, const char *key)
Definition wheel.c:913
struct WheelValue wheel_get_value_by_id(const struct Wheel *pkg, int from, ssize_t id)
Definition wheel.c:931
int wheel_package(struct Wheel **pkg, const char *filename)
Definition wheel.c:1348