summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2014-09-26 12:53:49 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2014-09-26 12:53:49 +0900
commit861ed79794fccff39e087d797683c79f9e40f2fb (patch)
treef7039eec9e3c6036feb2cdd3cdd41b9973eae723
parent3d791bd5fff82f0d0e31cebe1901c426d2bddeac (diff)
marrakesh - add src fetch and client arch + version ident
-rw-r--r--mrk-proto.h9
-rwxr-xr-xmrk-srv-build.sh19
-rw-r--r--mrk-srv.c103
-rw-r--r--mrk.c129
4 files changed, 255 insertions, 5 deletions
diff --git a/mrk-proto.h b/mrk-proto.h
index ce9399d..424f88b 100644
--- a/mrk-proto.h
+++ b/mrk-proto.h
@@ -11,11 +11,20 @@
11#define M_QRY_LIST 21 11#define M_QRY_LIST 21
12#define M_QRY_SEARCH 22 12#define M_QRY_SEARCH 22
13#define M_QRY_GET 23 13#define M_QRY_GET 23
14#define M_QRY_GETSRC 24
14 15
15#define M_ANS_START 31 16#define M_ANS_START 31
16#define M_ANS_DATA 32 17#define M_ANS_DATA 32
17#define M_ANS_END 33 18#define M_ANS_END 33
18 19
20#define M_SRC_START 41
21#define M_SRC_DATA 42
22#define M_SRC_END 43
23
24#define M_ID_UUID 51
25#define M_ID_VERSION 52
26#define M_ID_ARCH 53
27
19#if defined(__x86_64__) 28#if defined(__x86_64__)
20# define ARCH "x86_64" 29# define ARCH "x86_64"
21#elif defined(__i386__) 30#elif defined(__i386__)
diff --git a/mrk-srv-build.sh b/mrk-srv-build.sh
index ce061b5..15399e5 100755
--- a/mrk-srv-build.sh
+++ b/mrk-srv-build.sh
@@ -9,15 +9,26 @@ rm -rf Marrakesh || true
9export CC=gcc 9export CC=gcc
10export CFLAGS="-O3 -ffast-math" 10export CFLAGS="-O3 -ffast-math"
11export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig" 11export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig"
12export NAME=`grep "^PROJ:" Marrakesh.mrk | tail -1 | sed -e 's/PROJ://g' | sed -e 's/ *$//' -e 's/^ *//'`
12 13
14## this is a sample - you need to do this N times, once per arch
15export MRKARCH="x86_64"
16export MRKOS="linux"
13mrk extract *.mks 17mrk extract *.mks
14mrk build 18mrk build
15mrk bin 19mrk bin
16cp *.mkb "$2"/ 20export D="$2"/"$MRKOS-$MRKARCH"
21mkdir -p "$D" || true
22cp *.mkb "$D"
23rm -f "$D"/"$NAME" || true
24ln -sf *.mkb "$D"/"$NAME"
17 25
18export NAME=`grep "^PROJ:" Marrakesh.mrk | tail -1 | sed -e 's/PROJ://g' | sed -e 's/ *$//' -e 's/^ *//'` 26## # copy src to right place
19rm -f "$2"/"$NAME" || true 27export D="$2"/"src"
20ln -sf *.mkb "$2"/"$NAME" 28mkdir -p "$D" || true
29cp *.mks "$D"
30rm -f "$D"/"$NAME" || true
31ln -sf *.mkb "$D"/"$NAME"
21 32
22cd /tmp 33cd /tmp
23rm -rf "$1" 34rm -rf "$1"
diff --git a/mrk-srv.c b/mrk-srv.c
index 94971a1..106d9b1 100644
--- a/mrk-srv.c
+++ b/mrk-srv.c
@@ -55,6 +55,8 @@ typedef struct
55 char *dir; 55 char *dir;
56 FILE *f; 56 FILE *f;
57 Ecore_Exe *exe; 57 Ecore_Exe *exe;
58 char *arch;
59 char *version;
58} Client; 60} Client;
59 61
60static Ecore_Ipc_Server *ipc = NULL; 62static Ecore_Ipc_Server *ipc = NULL;
@@ -178,7 +180,8 @@ client_send(Client *c, const char *name)
178 char tmp[4096]; 180 char tmp[4096];
179 char *lnk; 181 char *lnk;
180 182
181 snprintf(tmp, sizeof(tmp), "%s/%s", repodir, name); 183 if (!c->arch) return;
184 snprintf(tmp, sizeof(tmp), "%s/%s/%s", repodir, c->arch, name);
182 lnk = ecore_file_readlink(tmp); 185 lnk = ecore_file_readlink(tmp);
183 if (!lnk) 186 if (!lnk)
184 ecore_ipc_client_send(c->client, 10, M_DOWN_START, 0, 0, 0, NULL, 0); 187 ecore_ipc_client_send(c->client, 10, M_DOWN_START, 0, 0, 0, NULL, 0);
@@ -207,6 +210,54 @@ client_send(Client *c, const char *name)
207 } 210 }
208} 211}
209 212
213static void
214client_src_send(Client *c, const char *name)
215{
216 char tmp[4096];
217 char *lnk;
218
219 snprintf(tmp, sizeof(tmp), "%s/src/%s", repodir, name);
220 lnk = ecore_file_readlink(tmp);
221 if (!lnk)
222 ecore_ipc_client_send(c->client, 10, M_SRC_START, 0, 0, 0, NULL, 0);
223 else
224 {
225 FILE *f;
226
227 f = fopen(tmp, "rb");
228 if (!f)
229 ecore_ipc_client_send(c->client, 10, M_SRC_START, 0, 0, 0, NULL, 0);
230 else
231 {
232 ecore_ipc_client_send(c->client, 10, M_SRC_START, 0, 0, 0, lnk, strlen(lnk));
233 for (;;)
234 {
235 size_t size;
236 char buf[10000];
237
238 size = fread(buf, 1, 10000, f);
239 if (size <= 0) break;
240 ecore_ipc_client_send(c->client, 10, M_SRC_DATA, 0, 0, 0, buf, size);
241 }
242 ecore_ipc_client_send(c->client, 10, M_SRC_END, 0, 0, 0, NULL, 0);
243 fclose(f);
244 }
245 }
246}
247
248static int
249arch_ok(const char *arch)
250{
251 if (!strcmp(arch, "x86_64-linux")) return 1;
252 return 0;
253}
254
255static int
256version_ok(const char *arch)
257{
258 return 1;
259}
260
210static Eina_Bool 261static Eina_Bool
211_ipc_cb_add(void *data, int type, void *event) 262_ipc_cb_add(void *data, int type, void *event)
212{ 263{
@@ -283,6 +334,56 @@ _ipc_cb_dat(void *data, int type, void *event)
283 } 334 }
284 // e->data == appname (Terminology, Rage etc.) 335 // e->data == appname (Terminology, Rage etc.)
285 break; 336 break;
337 case M_QRY_GETSRC:
338 if ((e->size > 0) && (e->size < 1000))
339 {
340 char *name = malloc(e->size + 1);
341 if (name)
342 {
343 memcpy(name, e->data, e->size);
344 name[e->size] = 0;
345 client_src_send(c, name);
346 free(name);
347 }
348 }
349 // e->data == appname (Terminology, Rage etc.)
350 break;
351 case M_ID_UUID:
352 break;
353 case M_ID_VERSION:
354 if ((e->size > 0) && (e->size < 1000))
355 {
356 char *version = malloc(e->size + 1);
357 if (version)
358 {
359 memcpy(version, e->data, e->size);
360 version[e->size] = 0;
361 if (version_ok(version))
362 {
363 if (c->version) free(c->version);
364 c->version = version;
365 }
366 else free(version);
367 }
368 }
369 break;
370 case M_ID_ARCH:
371 if ((e->size > 0) && (e->size < 1000))
372 {
373 char *arch = malloc(e->size + 1);
374 if (arch)
375 {
376 memcpy(arch, e->data, e->size);
377 arch[e->size] = 0;
378 if (arch_ok(arch))
379 {
380 if (c->arch) free(c->arch);
381 c->arch = arch;
382 }
383 else free(arch);
384 }
385 }
386 break;
286 default: 387 default:
287 break; 388 break;
288 } 389 }
diff --git a/mrk.c b/mrk.c
index 1cbedc9..7e51007 100644
--- a/mrk.c
+++ b/mrk.c
@@ -1054,6 +1054,15 @@ _ipc_cb_add(void *data, int type, void *event)
1054 Ecore_Ipc_Event_Server_Add *e = event; 1054 Ecore_Ipc_Event_Server_Add *e = event;
1055 FILE *f; 1055 FILE *f;
1056 1056
1057 char tmp[4096];
1058
1059 snprintf(tmp, sizeof(tmp), "%s-%s", os, arch);
1060 ecore_ipc_server_send(ipc, 10, M_ID_ARCH, 0, 0, 0,
1061 tmp, strlen(tmp));
1062 snprintf(tmp, sizeof(tmp), "%i.%i.%i",
1063 eina_version->major, eina_version->minor, eina_version->micro);
1064 ecore_ipc_server_send(ipc, 10, M_ID_VERSION, 0, 0, 0,
1065 tmp, strlen(tmp));
1057 f = fopen(up_path, "rb"); 1066 f = fopen(up_path, "rb");
1058 if (f) 1067 if (f)
1059 { 1068 {
@@ -1128,6 +1137,15 @@ static Eina_Bool
1128_ipc2_cb_add(void *data, int type, void *event) 1137_ipc2_cb_add(void *data, int type, void *event)
1129{ 1138{
1130 Ecore_Ipc_Event_Server_Add *e = event; 1139 Ecore_Ipc_Event_Server_Add *e = event;
1140 char tmp[4096];
1141
1142 snprintf(tmp, sizeof(tmp), "%s-%s", os, arch);
1143 ecore_ipc_server_send(ipc, 10, M_ID_ARCH, 0, 0, 0,
1144 tmp, strlen(tmp));
1145 snprintf(tmp, sizeof(tmp), "%i.%i.%i",
1146 eina_version->major, eina_version->minor, eina_version->micro);
1147 ecore_ipc_server_send(ipc, 10, M_ID_VERSION, 0, 0, 0,
1148 tmp, strlen(tmp));
1131 ecore_ipc_server_send(ipc, 10, M_QRY_GET, 0, 0, 0, 1149 ecore_ipc_server_send(ipc, 10, M_QRY_GET, 0, 0, 0,
1132 down_name, strlen(down_name)); 1150 down_name, strlen(down_name));
1133 return EINA_TRUE; 1151 return EINA_TRUE;
@@ -1220,6 +1238,115 @@ package_down(const char *name)
1220 return 1; 1238 return 1;
1221} 1239}
1222 1240
1241static char *downsrc_name = NULL;
1242static char *downsrc_file = NULL;
1243static FILE *downsrc_f = NULL;
1244
1245static Eina_Bool
1246_ipc3_cb_add(void *data, int type, void *event)
1247{
1248 Ecore_Ipc_Event_Server_Add *e = event;
1249 char tmp[4096];
1250
1251 snprintf(tmp, sizeof(tmp), "%s-%s", os, arch);
1252 ecore_ipc_server_send(ipc, 10, M_ID_ARCH, 0, 0, 0,
1253 tmp, strlen(tmp));
1254 snprintf(tmp, sizeof(tmp), "%i.%i.%i",
1255 eina_version->major, eina_version->minor, eina_version->micro);
1256 ecore_ipc_server_send(ipc, 10, M_ID_VERSION, 0, 0, 0,
1257 tmp, strlen(tmp));
1258 ecore_ipc_server_send(ipc, 10, M_QRY_GET, 0, 0, 0,
1259 downsrc_name, strlen(downsrc_name));
1260 return EINA_TRUE;
1261}
1262
1263static Eina_Bool
1264_ipc3_cb_del(void *data, int type, void *event)
1265{
1266 Ecore_Ipc_Event_Server_Del *e = event;
1267 err("disconnect...");
1268 ecore_main_loop_quit();
1269 return EINA_TRUE;
1270}
1271
1272static Eina_Bool
1273_ipc3_cb_dat(void *data, int type, void *event)
1274{
1275 Ecore_Ipc_Event_Server_Data *e = event;
1276 if (e->major == 10)
1277 {
1278 switch (e->minor)
1279 {
1280 case M_SRC_START:
1281 if ((e->size > 0) && (e->size <= 1000) && (e->data))
1282 {
1283 char *file = malloc(e->size + 1);
1284 if (file)
1285 {
1286 memcpy(file, e->data, e->size);
1287 file[e->size] = 0;
1288 if ((sane_forbidden_path(file, sane_name_veto) &&
1289 sane_allowed_path(file, sane_name_ok)))
1290 {
1291 if (!downsrc_f)
1292 {
1293 char tmp[4096];
1294
1295 downsrc_file = file;
1296 snprintf(tmp, sizeof(tmp),
1297 "%s/Applications/.tmp",
1298 getenv("HOME"));
1299 ecore_file_mkpath(tmp);
1300 snprintf(tmp, sizeof(tmp),
1301 "%s/Applications/.tmp/%s",
1302 getenv("HOME"), downsrc_file);
1303 if (ecore_file_exists(tmp))
1304 err("file already exists");
1305 downsrc_f = fopen(file, "wb");
1306 printf("%s\n", file);
1307 }
1308 else err("already have download");
1309 }
1310 else err("mangled filename");
1311 }
1312 else err("download file not sane");
1313 }
1314 else err("no such package");
1315 break;
1316 case M_SRC_DATA:
1317 if ((downsrc_f) && (e->data) && (e->size > 0) && (e->size <= 10000))
1318 {
1319 fwrite(e->data, e->size, 1, downsrc_f);
1320 }
1321 break;
1322 case M_SRC_END:
1323 if (downsrc_f)
1324 {
1325 fclose(downsrc_f);
1326 downsrc_f = NULL;
1327 ecore_main_loop_quit();
1328 }
1329 break;
1330 default:
1331 break;
1332 }
1333 }
1334 return EINA_TRUE;
1335}
1336
1337static int
1338package_downsrc(const char *name)
1339{
1340 ipc = ecore_ipc_server_connect(ECORE_IPC_REMOTE_SYSTEM, server, server_port, NULL);
1341 if (!ipc) return 0;
1342 ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_ADD, _ipc3_cb_add, NULL);
1343 ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_DEL, _ipc3_cb_del, NULL);
1344 ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_DATA, _ipc3_cb_dat, NULL);
1345 downsrc_name = strdup(name);
1346 ecore_main_loop_begin();
1347 return 1;
1348}
1349
1223int 1350int
1224main(int argc, char **argv) 1351main(int argc, char **argv)
1225{ 1352{
@@ -1338,6 +1465,8 @@ main(int argc, char **argv)
1338 } 1465 }
1339 else if (!strcmp(argv[1], "getsrc")) 1466 else if (!strcmp(argv[1], "getsrc"))
1340 { 1467 {
1468 if (argc < 3) err("need package to download");
1469 if (!package_downsrc(argv[2])) return 1;
1341 } 1470 }
1342 else if (!strcmp(argv[1], "check")) 1471 else if (!strcmp(argv[1], "check"))
1343 { 1472 {