summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2014-09-27 09:58:18 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2014-09-27 09:58:18 +0900
commit44b39a8e3ab1e342ad76abfaa8e056eb41867226 (patch)
treebf7e0b45fa7b2e09d37fdb6dc3c84e131e996f95
parentc331c1f10535b12f436d7f22497577a892620a29 (diff)
make repo db indexer work and server load index and search/list
-rw-r--r--mrk-index.c210
-rw-r--r--mrk-srv.c294
-rw-r--r--mrk.c104
3 files changed, 584 insertions, 24 deletions
diff --git a/mrk-index.c b/mrk-index.c
index 151dc7a..7fab73a 100644
--- a/mrk-index.c
+++ b/mrk-index.c
@@ -29,21 +29,95 @@ read_string(Eet_File *ef, const char *key)
29} 29}
30 30
31static void 31static void
32key_add(Eina_Hash *hash, const char *key, const char *entry) 32key_register(Eina_Hash *hash, const char *key, const char *entry)
33{ 33{
34 const char *ss; 34 const char *ss;
35 Eina_List *entries; 35 Eina_List *entries;
36 36
37 printf("IDX: %p %s -> %s\n", hash, key, entry);
37 ss = eina_stringshare_add(entry); 38 ss = eina_stringshare_add(entry);
38 entries = eina_hash_find(hash, key); 39 entries = eina_hash_find(hash, key);
39 entries = eina_list_sorted_insert(entries, EINA_COMPARE_CB(strcasecmp), ss); 40 entries = eina_list_sorted_insert(entries, EINA_COMPARE_CB(strcasecmp), ss);
40 eina_hash_add(hash, key, entries); 41 eina_hash_set(hash, key, entries);
42}
43
44typedef struct
45{
46 Eina_Hash *master;
47 const char *entry;
48} Inf;
49
50static Eina_Bool
51key_enter_cb(const Eina_Hash *hash, const void *key, void *data, void *fdata)
52{
53 Inf *inf = fdata;
54 key_register(inf->master, key, inf->entry);
55 return EINA_TRUE;
56}
57
58static void
59key_enter(Eina_Hash *master, Eina_Hash *keys, const char *entry)
60{
61 Inf inf = { master, entry };
62
63 eina_hash_foreach(keys, key_enter_cb, &inf);
64}
65
66static Eina_Hash *
67key_new(void)
68{
69 return eina_hash_string_superfast_new(NULL);
41} 70}
42 71
43static void 72static void
44key_str_add(Eina_Hash *hash, const char *string, const char *entry) 73key_free(Eina_Hash *hash)
45{ 74{
46 // XXX: parse "words" from string - add each to the key given 75 eina_hash_free(hash);
76}
77
78static void
79key_add(Eina_Hash *hash, const char *key)
80{
81 if (eina_hash_find(hash, key)) return;
82 eina_hash_add(hash, key, hash);
83}
84
85static void
86key_str_add(Eina_Hash *hash, const char *str)
87{
88 char *ts = strdup(str);
89 char *p, *pe;
90 if (!ts) return;
91 for (p = ts; *p; p++)
92 {
93 if (!(((*p >= 'a') && (*p <= 'z')) ||
94 ((*p >= 'A') && (*p <= 'Z')) ||
95 ((*p >= '0') && (*p <= '9')))) *p = 0;
96 else *p = tolower(*p);
97 pe = p;
98 }
99 for (p = ts; p < pe; p++)
100 {
101 if (*p)
102 {
103 key_add(hash, p);
104 p += strlen(p);
105 }
106 }
107 free(ts);
108}
109
110static Eina_Bool
111key_merge_cb(const Eina_Hash *hash, const void *key, void *data, void *fdata)
112{
113 key_add(fdata, key);
114 return EINA_TRUE;
115}
116
117static void
118key_merge(Eina_Hash *master, Eina_Hash *keys)
119{
120 eina_hash_foreach(keys, key_merge_cb, master);
47} 121}
48 122
49static int 123static int
@@ -53,57 +127,101 @@ index_file(const char *file, const char *fname)
53 char *s; 127 char *s;
54 int i; 128 int i;
55 char tmp[4096]; 129 char tmp[4096];
130 Eina_Hash *ky;
131 Eina_Hash *tk;
56 132
133 printf("--- %s ---\n", file);
57 ef = eet_open(file, EET_FILE_MODE_READ); 134 ef = eet_open(file, EET_FILE_MODE_READ);
58 if (!ef) return 0; 135 if (!ef) return 0;
59 136
137 ky = key_new();
138 printf(".. name\n");
60 s = read_string(ef, "name"); 139 s = read_string(ef, "name");
61 if (s) 140 if (s)
62 { 141 {
63 key_add(db->name_hash, s, fname); 142 tk = key_new();
64 key_add(db->key_hash, s, fname); 143 key_add(tk, s);
65 free(s); 144 key_str_add(ky, s);
66 } 145 key_enter(db->name_hash, tk, fname);
67 s = read_string(ef, "version"); 146 key_free(tk);
68 if (s) 147 tk = key_new();
69 { 148 key_str_add(tk, s);
70 key_add(db->key_hash, s, fname); 149 key_merge(ky, tk);
150 key_free(tk);
71 free(s); 151 free(s);
72 } 152 }
153 printf(".. tags\n");
73 for (i = 0; i < 9999; i++) 154 for (i = 0; i < 9999; i++)
74 { 155 {
156 tk = key_new();
75 snprintf(tmp, sizeof(tmp), "tag/%i", i); 157 snprintf(tmp, sizeof(tmp), "tag/%i", i);
76 s = read_string(ef, tmp); 158 s = read_string(ef, tmp);
77 if (s) 159 if (s)
78 { 160 {
79 key_add(db->tag_hash, s, fname); 161 key_str_add(tk, s);
80 key_add(db->key_hash, s, fname);
81 free(s); 162 free(s);
82 } 163 }
164 key_enter(db->tag_hash, tk, fname);
165 key_merge(ky, tk);
166 key_free(tk);
83 } 167 }
168 printf(".. categories\n");
169 key_register(db->category_hash, "@", fname);
84 for (i = 0; i < 9999; i++) 170 for (i = 0; i < 9999; i++)
85 { 171 {
172 tk = key_new();
86 snprintf(tmp, sizeof(tmp), "category/%i", i); 173 snprintf(tmp, sizeof(tmp), "category/%i", i);
87 s = read_string(ef, tmp); 174 s = read_string(ef, tmp);
88 if (s) 175 if (s)
89 { 176 {
90 key_add(db->category_hash, s, fname); 177 key_str_add(tk, s);
91 key_add(db->key_hash, s, fname);
92 free(s); 178 free(s);
93 } 179 }
180 key_enter(db->category_hash, tk, fname);
181 key_merge(ky, tk);
182 key_free(tk);
94 } 183 }
95 184
96 // XXX: weed duplicates from every key 185 printf(".. brief\n");
186 s = read_string(ef, "brief");
187 if (s)
188 {
189 tk = key_new();
190 key_str_add(tk, s);
191 key_merge(ky, tk);
192 key_free(tk);
193 free(s);
194 }
195
196 key_enter(db->key_hash, ky, fname);
197 key_free(ky);
198
97 eet_close(ef); 199 eet_close(ef);
98 return 1; 200 return 1;
99} 201}
100 202
203static Eina_Bool
204index_out_cb(const Eina_Hash *hash, const void *key, void *data, void *fdata)
205{
206 FILE *f = fdata;
207 const char *s;
208
209 fprintf(f, "%s\n", key, data);
210 EINA_LIST_FREE(data, s)
211 {
212 fprintf(f, "\t%s\n", s);
213 eina_stringshare_del(s);
214 }
215 return EINA_TRUE;
216}
217
101static int 218static int
102index_dir(const char *dir) 219index_dir(const char *dir)
103{ 220{
104 Eina_List *files; 221 Eina_List *files;
105 char *s; 222 char *s;
106 char tmp[4096]; 223 char tmp[4096];
224 FILE *f;
107 225
108 db = calloc(1, sizeof(Mdb)); 226 db = calloc(1, sizeof(Mdb));
109 if (!db) return 0; 227 if (!db) return 0;
@@ -111,25 +229,70 @@ index_dir(const char *dir)
111 db->category_hash = eina_hash_string_superfast_new(NULL); 229 db->category_hash = eina_hash_string_superfast_new(NULL);
112 db->tag_hash = eina_hash_string_superfast_new(NULL); 230 db->tag_hash = eina_hash_string_superfast_new(NULL);
113 db->key_hash = eina_hash_string_superfast_new(NULL); 231 db->key_hash = eina_hash_string_superfast_new(NULL);
232
114 files = ecore_file_ls(dir); 233 files = ecore_file_ls(dir);
115 EINA_LIST_FREE(files, s) 234 EINA_LIST_FREE(files, s)
116 { 235 {
117 char *lnk; 236 char *lnk;
118 237
119 if (s[0] == '.') continue; 238 if (s[0] == '.')
239 {
240 free(s);
241 continue;
242 }
120 snprintf(tmp, sizeof(tmp), "%s/%s", dir, s); 243 snprintf(tmp, sizeof(tmp), "%s/%s", dir, s);
121 lnk = ecore_file_readlink(tmp); 244 lnk = ecore_file_readlink(tmp);
122 if (!lnk) continue; 245 if (!lnk)
246 {
247 free(s);
248 continue;
249 }
123 index_file(tmp, s); 250 index_file(tmp, s);
124 free(lnk); 251 free(lnk);
125 free(s); 252 free(s);
126 } 253 }
254
255 snprintf(tmp, sizeof(tmp), "%s/.mrkdb-name.txt", dir);
256 f = fopen(tmp, "wb");
257 if (f)
258 {
259 eina_hash_foreach(db->name_hash, index_out_cb, f);
260 eina_hash_free(db->name_hash);
261 fclose(f);
262 }
263 snprintf(tmp, sizeof(tmp), "%s/.mrkdb-tag.txt", dir);
264 f = fopen(tmp, "wb");
265 if (f)
266 {
267 eina_hash_foreach(db->tag_hash, index_out_cb, f);
268 eina_hash_free(db->tag_hash);
269 fclose(f);
270 }
271 snprintf(tmp, sizeof(tmp), "%s/.mrkdb-category.txt", dir);
272 f = fopen(tmp, "wb");
273 if (f)
274 {
275 eina_hash_foreach(db->category_hash, index_out_cb, f);
276 eina_hash_free(db->category_hash);
277 fclose(f);
278 }
279 snprintf(tmp, sizeof(tmp), "%s/.mrkdb-key.txt", dir);
280 f = fopen(tmp, "wb");
281 if (f)
282 {
283 eina_hash_foreach(db->key_hash, index_out_cb, f);
284 eina_hash_free(db->key_hash);
285 fclose(f);
286 }
287 free(db);
127 return 1; 288 return 1;
128} 289}
129 290
130int 291int
131main(int argc, char **argv) 292main(int argc, char **argv)
132{ 293{
294 int i;
295
133 if (argc < 2) 296 if (argc < 2)
134 { 297 {
135 printf("usage:\n" 298 printf("usage:\n"
@@ -142,8 +305,13 @@ main(int argc, char **argv)
142 eet_init(); 305 eet_init();
143 ecore_file_init(); 306 ecore_file_init();
144 307
145 if (argc > 1) repodir = ecore_file_realpath(argv[1]); 308 for (i = 1; i < argc; i++)
146 index_dir(repodir); 309 {
310 repodir = ecore_file_realpath(argv[i]);
311 index_dir(repodir);
312 free(repodir);
313 repodir = NULL;
314 }
147 315
148 ecore_file_shutdown(); 316 ecore_file_shutdown();
149 eet_shutdown(); 317 eet_shutdown();
diff --git a/mrk-srv.c b/mrk-srv.c
index 6dfa0f9..d8f0312 100644
--- a/mrk-srv.c
+++ b/mrk-srv.c
@@ -13,6 +13,175 @@ static const char *sane_name_ok = "01234567890-_abcdefghijklmnopqrstuvwxyzABCDEF
13static char *repodir = "./repo"; 13static char *repodir = "./repo";
14static char *build_sh = "./mrk-srv-build.sh"; 14static char *build_sh = "./mrk-srv-build.sh";
15 15
16typedef struct
17{
18 const char *arch; // also dir
19 Eina_Hash *name_hash;
20 Eina_Hash *category_hash;
21 Eina_Hash *tag_hash;
22 Eina_Hash *key_hash;
23} Db;
24
25static Eina_List *dbs = NULL;
26
27static void
28dbs_load_hash(Eina_Hash *hash, FILE *f)
29{
30 char line[16384], *s;
31 int len;
32 Eina_List *list = NULL;
33 const char *key = NULL;
34
35 for (;;)
36 {
37 s = fgets(line, sizeof(line), f);
38 if (!s) break;;
39 len = strlen(s);
40 if (len < 1) continue;
41 s[len - 1] = 0;
42 if ((s[0] == '\t') && (key))
43 {
44 list = eina_list_append(list, eina_stringshare_add(s + 1));
45 }
46 else
47 {
48 if (key) eina_hash_set(hash, key, list);
49 list = NULL;
50 if (key) eina_stringshare_del(key);
51 key = eina_stringshare_add(s);
52 }
53 }
54 if (key) eina_hash_set(hash, key, list);
55 list = NULL;
56 if (key) eina_stringshare_del(key);
57 key = NULL;
58}
59
60static void
61dbs_load(void)
62{
63 Eina_List *files;
64 char *s;
65 char tmp[4096];
66
67 files = ecore_file_ls(repodir);
68 EINA_LIST_FREE(files, s)
69 {
70 Db *db = NULL;
71 FILE *f;
72
73 if (s[0] == '.')
74 {
75 free(s);
76 continue;
77 }
78 snprintf(tmp, sizeof(tmp), "%s/%s/.mrkdb-name.txt", repodir, s);
79 f = fopen(tmp, "rb");
80 if (f)
81 {
82 db = calloc(1, sizeof(Db));
83 if (db)
84 {
85 db->arch = strdup(s);
86
87 if (db->arch)
88 {
89 db->name_hash = eina_hash_string_superfast_new(NULL);
90 db->category_hash = eina_hash_string_superfast_new(NULL);
91 db->tag_hash = eina_hash_string_superfast_new(NULL);
92 db->key_hash = eina_hash_string_superfast_new(NULL);
93 dbs = eina_list_append(dbs, db);
94 dbs_load_hash(db->name_hash, f);
95 }
96 else
97 {
98 free(db);
99 db = NULL;
100 }
101 }
102 fclose(f);
103 }
104 if (db)
105 {
106 snprintf(tmp, sizeof(tmp), "%s/%s/.mrkdb-tag.txt", repodir, s);
107 f = fopen(tmp, "rb");
108 if (f)
109 {
110 dbs_load_hash(db->tag_hash, f);
111 fclose(f);
112 }
113 snprintf(tmp, sizeof(tmp), "%s/%s/.mrkdb-category.txt", repodir, s);
114 f = fopen(tmp, "rb");
115 if (f)
116 {
117 dbs_load_hash(db->category_hash, f);
118 fclose(f);
119 }
120 snprintf(tmp, sizeof(tmp), "%s/%s/.mrkdb-key.txt", repodir, s);
121 f = fopen(tmp, "rb");
122 if (f)
123 {
124 dbs_load_hash(db->key_hash, f);
125 fclose(f);
126 }
127 }
128 db = NULL;
129 }
130}
131
132static Eina_Bool
133dbs_clear_hash_cb(const Eina_Hash *hash, const void *key, void *data, void *fdata)
134{
135 const char *s;
136
137 EINA_LIST_FREE(data, s)
138 {
139 eina_stringshare_del(s);
140 }
141 return EINA_TRUE;
142}
143
144static void
145dbs_clear_hash(Eina_Hash *hash)
146{
147 if (!hash) return;
148 eina_hash_foreach(hash, dbs_clear_hash_cb, NULL);
149 eina_hash_free(hash);
150}
151
152static void
153dbs_clear(void)
154{
155 Db *db;
156
157 EINA_LIST_FREE(dbs, db)
158 {
159 dbs_clear_hash(db->name_hash);
160 dbs_clear_hash(db->category_hash);
161 dbs_clear_hash(db->tag_hash);
162 dbs_clear_hash(db->key_hash);
163 free(db);
164 }
165}
166
167static Db *
168dbs_arch_find(const char *arch)
169{
170 Eina_List *l;
171 Db *db;
172
173 if (!arch) return NULL;
174 EINA_LIST_FOREACH(dbs, l, db)
175 {
176 if (!strcmp(db->arch, arch))
177 {
178 if (dbs != l) dbs = eina_list_promote_list(dbs, l);
179 return db;
180 }
181 }
182 return NULL;
183}
184
16static int 185static int
17sane_forbidden_path(const char *file, const char **forbidden) 186sane_forbidden_path(const char *file, const char **forbidden)
18{ 187{
@@ -263,6 +432,64 @@ version_ok(const char *arch)
263 return 1; 432 return 1;
264} 433}
265 434
435static Eina_List *
436search_intersect(Eina_List *list_in, Eina_List *list2)
437{
438 Eina_List *list = NULL, *ll;
439 const char *s, *ss;
440 int ok;
441
442 EINA_LIST_FREE(list_in, s)
443 {
444 ok = 0;
445 EINA_LIST_FOREACH(list2, ll, ss)
446 {
447 if (ss == s)
448 {
449 ok = 1;
450 break;
451 }
452 }
453 if (ok) list = eina_list_append(list, s);
454 else eina_stringshare_del(s);
455 }
456 return list;
457}
458
459static Eina_List *
460search_build(Eina_Hash *hash, const char *search)
461{
462 Eina_List *list = NULL, *tl, *l;
463 const char *s;
464 char *ts = strdup(search);
465 char *p, *end;
466 int i;
467
468 if (!ts) return NULL;
469 for (p = ts; *p; p++)
470 {
471 if (isspace(*p)) *p = 0;
472 end = p;
473 }
474 for (p = ts; p < end; p++)
475 {
476 if (!*p) continue;
477 tl = eina_hash_find(hash, p);
478 if (p == ts)
479 {
480 EINA_LIST_FOREACH(tl, l, s)
481 list = eina_list_append(list, eina_stringshare_add(s));
482 }
483 else
484 {
485 list = search_intersect(list, tl);
486 }
487 p += strlen(p);
488 }
489 free(ts);
490 return list;
491}
492
266static Eina_Bool 493static Eina_Bool
267_ipc_cb_add(void *data, int type, void *event) 494_ipc_cb_add(void *data, int type, void *event)
268{ 495{
@@ -321,9 +548,73 @@ _ipc_cb_dat(void *data, int type, void *event)
321 break; 548 break;
322 case M_QRY_LIST: 549 case M_QRY_LIST:
323 // e->data == category (none if all) 550 // e->data == category (none if all)
551 ecore_ipc_client_send(c->client, 10, M_ANS_START, 0, 0, 0, NULL, 0);
552 if ((e->size > 0) && (e->size < 1000))
553 {
554 Eina_List *list = NULL, *l;
555 const char *s;
556 Db *db = dbs_arch_find(c->arch);
557
558 if (db)
559 {
560 char *str = malloc(e->size + 1);
561 if (str)
562 {
563 memcpy(str, e->data, e->size);
564 str[e->size] = 0;
565 list = eina_hash_find(db->category_hash, str);
566 free(str);
567 EINA_LIST_FOREACH(list, l, s)
568 {
569 ecore_ipc_client_send(c->client, 10, M_ANS_DATA, 0, 0, 0, s, strlen(s));
570 }
571 }
572 }
573 }
574 else
575 {
576 Eina_List *list = NULL, *l;
577 const char *s;
578 Db *db = dbs_arch_find(c->arch);
579
580 if (db)
581 {
582 list = eina_hash_find(db->category_hash, "@");
583 EINA_LIST_FOREACH(list, l, s)
584 {
585 ecore_ipc_client_send(c->client, 10, M_ANS_DATA, 0, 0, 0, s, strlen(s));
586 }
587 }
588 }
589 ecore_ipc_client_send(c->client, 10, M_ANS_END, 0, 0, 0, NULL, 0);
324 break; 590 break;
325 case M_QRY_SEARCH: 591 case M_QRY_SEARCH:
326 // e->data == query string 592 // e->data == query string
593 ecore_ipc_client_send(c->client, 10, M_ANS_START, 0, 0, 0, NULL, 0);
594 if ((e->size > 0) && (e->size < 1000))
595 {
596 Eina_List *list = NULL;
597 const char *s;
598 Db *db = dbs_arch_find(c->arch);
599
600 if (db)
601 {
602 char *str = malloc(e->size + 1);
603 if (str)
604 {
605 memcpy(str, e->data, e->size);
606 str[e->size] = 0;
607 list = search_build(db->key_hash, str);
608 free(str);
609 EINA_LIST_FREE(list, s)
610 {
611 ecore_ipc_client_send(c->client, 10, M_ANS_DATA, 0, 0, 0, s, strlen(s));
612 eina_stringshare_del(s);
613 }
614 }
615 }
616 }
617 ecore_ipc_client_send(c->client, 10, M_ANS_END, 0, 0, 0, NULL, 0);
327 break; 618 break;
328 case M_QRY_GET: 619 case M_QRY_GET:
329 if ((e->size > 0) && (e->size < 1000)) 620 if ((e->size > 0) && (e->size < 1000))
@@ -380,7 +671,6 @@ _ipc_cb_dat(void *data, int type, void *event)
380 { 671 {
381 memcpy(arch, e->data, e->size); 672 memcpy(arch, e->data, e->size);
382 arch[e->size] = 0; 673 arch[e->size] = 0;
383 printf("set arch %s\n", arch);
384 if (arch_ok(arch)) 674 if (arch_ok(arch))
385 { 675 {
386 if (c->arch) free(c->arch); 676 if (c->arch) free(c->arch);
@@ -443,6 +733,8 @@ main(int argc, char **argv)
443 if (argc > 1) repodir = ecore_file_realpath(argv[1]); 733 if (argc > 1) repodir = ecore_file_realpath(argv[1]);
444 if (argc > 2) build_sh = ecore_file_realpath(argv[2]); 734 if (argc > 2) build_sh = ecore_file_realpath(argv[2]);
445 735
736 dbs_load();
737
446 if (ipc_init()) 738 if (ipc_init())
447 { 739 {
448 ecore_exe_run_priority_set(10); 740 ecore_exe_run_priority_set(10);
diff --git a/mrk.c b/mrk.c
index bb8e0d5..b6fbc59 100644
--- a/mrk.c
+++ b/mrk.c
@@ -1347,6 +1347,79 @@ package_downsrc(const char *name)
1347 return 1; 1347 return 1;
1348} 1348}
1349 1349
1350static int qry_op = 0;
1351static char *qry_data;
1352
1353static Eina_Bool
1354_ipc4_cb_add(void *data, int type, void *event)
1355{
1356 Ecore_Ipc_Event_Server_Add *e = event;
1357 char tmp[4096];
1358
1359 snprintf(tmp, sizeof(tmp), "%s-%s", os, arch);
1360 ecore_ipc_server_send(ipc, 10, M_ID_ARCH, 0, 0, 0,
1361 tmp, strlen(tmp));
1362 snprintf(tmp, sizeof(tmp), "%i.%i.%i",
1363 eina_version->major, eina_version->minor, eina_version->micro);
1364 ecore_ipc_server_send(ipc, 10, M_ID_VERSION, 0, 0, 0,
1365 tmp, strlen(tmp));
1366 ecore_ipc_server_send(ipc, 10, qry_op, 0, 0, 0,
1367 qry_data, qry_data ? strlen(qry_data) : 0);
1368 return EINA_TRUE;
1369}
1370
1371static Eina_Bool
1372_ipc4_cb_del(void *data, int type, void *event)
1373{
1374 Ecore_Ipc_Event_Server_Del *e = event;
1375 err("disconnect...");
1376 ecore_main_loop_quit();
1377 return EINA_TRUE;
1378}
1379
1380static Eina_Bool
1381_ipc4_cb_dat(void *data, int type, void *event)
1382{
1383 Ecore_Ipc_Event_Server_Data *e = event;
1384 if (e->major == 10)
1385 {
1386 switch (e->minor)
1387 {
1388 case M_ANS_START:
1389 break;
1390 case M_ANS_DATA:
1391 if ((e->data) && (e->size > 0) && (e->size <= 10000))
1392 {
1393 fwrite(e->data, e->size, 1, stdout);
1394 fwrite("\n", 1, 1, stdout);
1395 }
1396 break;
1397 case M_ANS_END:
1398 if (qry_data) free(qry_data);
1399 qry_data = NULL;
1400 ecore_main_loop_quit();
1401 break;
1402 default:
1403 break;
1404 }
1405 }
1406 return EINA_TRUE;
1407}
1408
1409static int
1410package_qry(int op, const char *opdat)
1411{
1412 ipc = ecore_ipc_server_connect(ECORE_IPC_REMOTE_SYSTEM, server, server_port, NULL);
1413 if (!ipc) return 0;
1414 ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_ADD, _ipc4_cb_add, NULL);
1415 ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_DEL, _ipc4_cb_del, NULL);
1416 ecore_event_handler_add(ECORE_IPC_EVENT_SERVER_DATA, _ipc4_cb_dat, NULL);
1417 qry_op = op;
1418 if (opdat) qry_data = strdup(opdat);
1419 ecore_main_loop_begin();
1420 return 1;
1421}
1422
1350int 1423int
1351main(int argc, char **argv) 1424main(int argc, char **argv)
1352{ 1425{
@@ -1369,8 +1442,8 @@ main(int argc, char **argv)
1369 " rel [FILE]\n" 1442 " rel [FILE]\n"
1370 " down PKGNAME\n" 1443 " down PKGNAME\n"
1371 " get PKGNAME\n" 1444 " get PKGNAME\n"
1372// " list [CATEGORY]\n" 1445 " list [CATEGORY]\n"
1373// " search KEY1 [KEY2] [KEY3] [...]\n" 1446 " search KEY1 [KEY2] [KEY3] [...]\n"
1374// " new\n" 1447// " new\n"
1375// " getsrc\n" 1448// " getsrc\n"
1376 " check\n" 1449 " check\n"
@@ -1456,9 +1529,36 @@ main(int argc, char **argv)
1456 } 1529 }
1457 else if (!strcmp(argv[1], "list")) 1530 else if (!strcmp(argv[1], "list"))
1458 { 1531 {
1532 if (argc < 3) package_qry(M_QRY_LIST, NULL);
1533 else package_qry(M_QRY_LIST, argv[2]);
1459 } 1534 }
1460 else if (!strcmp(argv[1], "search")) 1535 else if (!strcmp(argv[1], "search"))
1461 { 1536 {
1537 if (argc < 3) err("need search strings");
1538 else
1539 {
1540 int i;
1541 int len = 0;
1542 char *ts;
1543
1544 for (i = 2; i < argc; i++)
1545 {
1546 len += strlen(argv[i]);
1547 len++;
1548 }
1549 ts = malloc(len);
1550 if (ts)
1551 {
1552 ts[0] = 0;
1553 for (i = 2; i < argc; i++)
1554 {
1555 strcat(ts, argv[i]);
1556 if (i < (argc - 1)) strcat(ts, " ");
1557 }
1558 package_qry(M_QRY_SEARCH, ts);
1559 free(ts);
1560 }
1561 }
1462 } 1562 }
1463 else if (!strcmp(argv[1], "new")) 1563 else if (!strcmp(argv[1], "new"))
1464 { 1564 {