source: titan/titan/ipkg.h @ 45557

Last change on this file since 45557 was 45473, checked in by obi, 3 years ago

remove atemio url

File size: 13.0 KB
Line 
1#ifndef OIPKG_H
2#define OIPKG_H
3
4struct ipkg
5{
6        char* name;
7        char* desc;
8        char* version;
9        char* section;
10        char* showname;
11        int done;
12        struct ipkg* prev;
13        struct ipkg* next;
14};
15
16struct ipkg *ipkg = NULL;
17
18void debugipkg()
19{
20        struct ipkg *node = ipkg;
21       
22        while(node != NULL)
23        {
24                if(node->name != NULL)
25                        printf("pkg name: %s\n", node->name);
26                if(node->desc != NULL)
27                        printf("pkg desc: %s\n", node->desc);
28                if(node->version != NULL)
29                        printf("pkg version: %s\n", node->version);
30                if(node->section != NULL)
31                        printf("pkg section: %s\n", node->section);
32                if(node->showname != NULL)
33                        printf("pkg showname: %s\n", node->showname);
34                node = node->next;
35        }
36}
37
38struct ipkg* addipkg(char *name, char* desc, char* version, char* section, char* showname, struct ipkg* last)
39{
40        //debug(1000, "in");
41        struct ipkg *newnode = NULL, *prev = NULL, *node = ipkg;
42
43        newnode = (struct ipkg*)malloc(sizeof(struct ipkg));   
44        if(newnode == NULL)
45        {
46                err("no memory");
47                return NULL;
48        }
49        memset(newnode, 0, sizeof(struct ipkg));
50
51        newnode->name = ostrcat(name, NULL, 0, 0);
52        newnode->desc = ostrcat(desc, NULL, 0, 0);
53        newnode->version = ostrcat(version, NULL, 0, 0);
54        newnode->section = ostrcat(section, NULL, 0, 0);
55        newnode->showname = ostrcat(showname, NULL, 0, 0);
56
57        if(last == NULL)
58        {
59                while(node != NULL)
60                {
61                        prev = node;
62                        node = node->next;
63                }
64        }
65        else
66        {
67                prev = last;
68                node = last->next;
69        }
70
71        if(prev == NULL)
72                ipkg = newnode;
73        else
74        {
75                prev->next = newnode;
76                newnode->prev = prev;
77        }
78        newnode->next = node;
79        if(node != NULL) node->prev = newnode;
80
81        //debug(1000, "out");
82        return newnode;
83}
84
85void delipkg(struct ipkg* ipkgnode)
86{
87        //debug(1000, "in");
88        struct ipkg *node = ipkg, *prev = ipkg;
89
90        while(node != NULL)
91        {
92                if(node == ipkgnode)
93                {
94                        if(node == ipkg)
95                        {
96                                ipkg = node->next;
97                                if(ipkg != NULL)
98                                        ipkg->prev = NULL;
99                        }
100                        else
101                        {
102                                prev->next = node->next;
103                                if(node->next != NULL)
104                                        node->next->prev = prev;
105                        }
106
107                        free(node->name);
108                        node->name = NULL;
109
110                        free(node->desc);
111                        node->desc = NULL;
112
113                        free(node->version);
114                        node->version = NULL;
115
116                        free(node->section);
117                        node->section = NULL;
118
119                        free(node->showname);
120                        node->showname = NULL;
121
122                        free(node);
123                        node = NULL;
124                        break;
125                }
126
127                prev = node;
128                node = node->next;
129        }
130        //debug(1000, "out");
131}
132
133void freeipkg()
134{
135        debug(1000, "in");
136        struct ipkg *node = ipkg, *prev = ipkg;
137
138        while(node != NULL)
139        {
140                prev = node;
141                node = node->next;
142                if(prev != NULL)
143                        delipkg(prev);
144        }
145        debug(1000, "out");
146}
147
148int ipkg_list_cb(char *name, char *desc, char *version, pkg_state_status_t status, void *userdata)
149{
150        int count = 0;
151#ifndef SIMULATE
152        char* tmpstr = NULL;
153        struct splitstr* ret = NULL;
154       
155        tmpstr = ostrcat(name, NULL, 0, 0);
156        ret = strsplit(tmpstr, "-", &count);
157
158        if(count >= 4)
159        {
160                if(desc)
161                        addipkg(name, desc, version, (&ret[2])->part, (&ret[3])->part, NULL);
162                else
163                        addipkg(name, NULL, version, (&ret[2])->part, (&ret[3])->part, NULL);
164        }
165
166        free(ret); ret = NULL;
167        free(tmpstr); tmpstr = NULL;
168#endif
169
170        return 0;
171}
172
173int ipkg_status_cb(char *name, int istatus, char *desc, void *userdata)
174{
175        addipkg(name, desc, NULL, NULL, NULL, NULL);
176        return 0;
177}
178
179int ipkg_update(void)
180{
181        unlink("/var/usr/lib/ipkg/cross");
182        unlink("/var/usr/lib/ipkg/secret");
183        unlink("/var/usr/lib/ipkg/titan");             
184        int err = 0;
185#ifndef SIMULATE
186        args_t args;
187
188        args_init(&args);
189        err = ipkg_lists_update(&args);
190        args_deinit(&args);
191#endif
192        return err;
193}
194
195int ipkg_packages_list_installed(args_t *args, const char *packages, ipkg_list_callback cblist, void *userdata)
196{
197        int err = 0;
198#ifndef SIMULATE
199        ipkg_cmd_t *cmd;
200        ipkg_conf_t ipkg_conf;
201
202        err = ipkg_conf_init(&ipkg_conf, args);
203        if(err)
204        {
205                return err;
206        }
207
208        ipkg_cb_list = cblist;
209        /* we need to do this because of static declarations,
210         * maybe a good idea to change */
211        cmd = ipkg_cmd_find("list_installed");
212        if(packages)
213                err = ipkg_cmd_exec(cmd, &ipkg_conf, 1, &packages, userdata);
214        else
215                err = ipkg_cmd_exec(cmd, &ipkg_conf, 0, NULL, userdata);
216        ipkg_cb_list = NULL;
217        ipkg_conf_deinit(&ipkg_conf);
218#endif
219        return(err);
220}
221
222int ipkg_list_installed(void)
223{
224        int err = 0;
225#ifndef SIMULATE
226        args_t args;
227       
228        args_init(&args);
229        err = ipkg_packages_list_installed(&args, NULL, ipkg_list_cb, NULL);
230        args_deinit(&args);
231#endif
232        return err;
233}
234
235int ipkg_list(void)
236{
237        int err = 0;
238#ifndef SIMULATE
239        args_t args;
240       
241        args_init(&args);
242        err = ipkg_packages_list(&args, NULL, ipkg_list_cb, NULL);
243        args_deinit(&args);
244#endif
245        return err;
246}
247
248int ipkg_status(const char* package)
249{
250        int err = 0;
251#ifndef SIMULATE
252        args_t args;
253
254        args_init(&args);
255        err = ipkg_packages_status(&args, package, ipkg_status_cb, NULL);
256        args_deinit(&args);
257#endif
258        return err;
259}
260
261int ipkg_info(const char* package)
262{
263        int err = 0;
264#ifndef SIMULATE
265        args_t args;
266
267        args_init(&args);
268        err = ipkg_packages_info(&args, package, ipkg_status_cb, NULL);
269        args_deinit(&args);
270#endif
271        return err;
272}
273
274int ipkg_install(const char* package)
275{
276        debug(130, "package: %s", package);
277
278        int err = 0;
279#ifndef SIMULATE
280        args_t args;
281       
282        args_init(&args);
283        debug(130, "package1: %s", package);
284        err = ipkg_packages_install(&args, package);
285        debug(130, "package2: %s", package);
286        args_deinit(&args);
287        debug(130, "package3: %s", package);
288#endif 
289        return err;
290}
291
292int ipkg_remove(const char* package, int purge)
293{
294        int err = 0;
295#ifndef SIMULATE
296        args_t args;
297
298        args_init(&args);
299        err = ipkg_packages_remove(&args, package, purge);
300        args_deinit(&args);
301#endif
302        return err;
303}
304
305int ipkg_upgrade(void)
306{
307        int err = 0;
308#ifndef SIMULATE
309        args_t args;
310
311        args_init(&args);
312        err = ipkg_packages_upgrade(&args);
313        args_deinit(&args);
314#endif
315        return err;
316}
317
318int ipkg_download(ipkg_conf_t *conf, const char *src, const char *filename)
319{
320        int err = 0, count = 0, i = 0, withoutgui = 0;
321        char* tmpip = NULL, *ip = NULL, *pos = NULL, *path = NULL, *tmpstr = NULL;
322        struct splitstr* ret = NULL;
323
324        if(src == NULL) return 1;
325
326        debug(130, "src: %s", src);
327        tmpip = string_replace("http://", "", (char*)src, 0);
328
329        if(tmpip != NULL)
330                pos = strchr(tmpip, '/');
331        if(pos != NULL)
332        {
333                pos[0] = '\0';
334                path = pos + 1;
335        }
336
337        tmpstr = ostrcat("", path, 0, 0);
338        ret = strsplit(tmpstr, "/", &count);
339       
340        for(i = 0; i < count; i++)
341        {
342                if(ostrcmp("Packages.gz", (&ret[i])->part) == 0)
343                        withoutgui = 1;
344        }
345        free(ret); ret = NULL;
346        free(tmpstr); tmpstr = NULL;
347
348        ip = ostrcat(tmpip, NULL, 0, 0);
349
350        debug(130, "ip: %s", ip);
351        debug(130, "path: %s", path);
352       
353        if(withoutgui == 1)
354        {
355                if(ostrcmp("97.74.32.10", ip) == 0)
356                {
357                        if(ostrcmp((char*)src, "//97.74.32.10/svn/ipk/sh4/titan") != 0)         
358                        {
359                                textbox(_("Message"), _("check your Secret Feed !"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 5, 0);               
360                                free(tmpip); tmpip = NULL;
361                                free(ip); ip = NULL;
362                                return 1;
363                        }
364                }
365
366                char* checkpath = ostrcat(path, NULL, 0, 0);
367                checkpath = string_replace_all("/", ".", checkpath, 1);
368                checkpath = string_replace_all("-", ".", checkpath, 1);
369
370                char* checkfile = NULL;
371                checkfile = ostrcat("/tmp/Packages.", ip, 0, 0);
372                checkfile = ostrcat(checkfile, ".", 1, 0);
373                checkfile = ostrcat(checkfile, checkpath, 1, 0);
374                free(checkpath), checkpath = NULL;
375                debug(130, "checkfile: %s", checkfile);
376       
377                if(ostrcmp("97.74.32.10", ip) == 0)
378                {
379                        free(ip);
380                        ip = ostrcat("openaaf.dyndns.tv", NULL, 0, 0);
381                }
382
383                if(!file_exist(checkfile)) // +status.ipkg = date + 1day
384                {
385                        char* tmppath = NULL;
386                        tmppath = ostrcat(tmppath, path, 1, 0);
387                        tmppath = string_replace("Packages.gz", "Packages.preview.tar.gz", tmppath, 1);
388                        gethttp(ip, tmppath, 80, "/tmp/Packages.preview.tar.gz", HTTPAUTH, 5000, NULL, 0);
389                        free(tmppath); tmppath = NULL;
390                       
391                        system("tar -zxvf /tmp/Packages.preview.tar.gz -C /tmp");
392                        unlink("/tmp/Packages.preview.tar.gz");
393                        writesys(checkfile, ".", 1);
394                }
395
396                free(checkfile); checkfile = NULL;             
397                gethttp(ip, path, 80, (char*)filename, HTTPAUTH, 5000, NULL, 0);
398        }
399        else
400        {
401                if(ostrcmp("97.74.32.10", ip) == 0)
402                {
403                        free(ip);
404                        ip = ostrcat("openaaf.dyndns.tv", NULL, 0, 0);
405                }
406               
407                err = screendownload("Download", ip, path, 80, (char*)filename, HTTPAUTH, 5000, 0);
408                struct skin* load = getscreen("loading");
409                drawscreen(load, 0, 0);
410        }
411
412        free(tmpip); tmpip = NULL;
413        free(ip); ip = NULL;
414
415        return err;
416}
417
418int ipkg_files(const char* package)
419{
420        int err = 0;
421#ifndef SIMULATE
422        args_t args;
423
424        args_init(&args);
425        err = ipkg_package_files(&args, package, ipkg_list_cb, NULL);
426        args_deinit(&args);
427#endif
428        return err;
429}
430
431int ipkg_search(const char* package)
432{
433        int err = 0;
434#ifndef SIMULATE
435        args_t args;
436
437        args_init(&args);
438        err = ipkg_file_search(&args, package, ipkg_list_cb, NULL);
439        args_deinit(&args);
440#endif
441        return err;
442}
443
444char* get_ipk_section()
445{
446        struct ipkg *node = ipkg;
447        char* sectionlist = NULL;
448        char* namelist = NULL;
449        char* tmpstr = NULL;
450        while(node != NULL)
451        {
452                if(node->name != NULL && node->section != NULL)
453                {
454                        tmpstr = ostrcat("-", node->section, 0, 0);
455                        tmpstr = ostrcat(tmpstr, "-", 1, 0);
456                        if(ostrstr(namelist, tmpstr) == NULL)
457                        {
458                                namelist = ostrcat(namelist, node->name, 1, 0);
459                                namelist = ostrcat(namelist, " ", 1, 0);
460                                sectionlist = ostrcat(sectionlist, node->section, 1, 0);
461                                sectionlist = ostrcat(sectionlist, "\n", 1, 0);
462                        }
463                        free(tmpstr), tmpstr = NULL;
464                }
465                node = node->next;
466        }
467        free(namelist), namelist = NULL;
468        return sectionlist;
469}
470
471int findsectiondone(char* section)
472{
473        struct ipkg* node = ipkg;
474       
475        if(node == NULL || section == NULL) return 1;
476       
477        while(node != NULL)
478        {
479                if(node->done == 1 && ostrcmp(section, node->section) == 0)
480                        return 1;
481                node = node->next;
482        }
483
484        return 0;
485}
486
487//flag 0: show section
488//flag 1: show entrys
489//flag 2: show entrys for remove
490struct menulist* ipkmenulist(struct menulist* mlist, char* paramskinname, char* skintitle, char* paramskinpath, char* section, int showpng, int flag)
491{
492        int skip = 0;
493        struct ipkg* node = ipkg, *ipkg_installed = NULL, *node_installed = NULL;
494        struct menulist* tmpmlist = NULL;
495        char* tmpstr = NULL, *tmpinfo = NULL, *tmppic = NULL;
496       
497        if(node == NULL) return NULL;
498       
499        if(flag == 1)
500        {
501                ipkg = NULL;
502                ipkg_list_installed();
503                ipkg_installed = ipkg;
504                ipkg = node;
505        }
506       
507        while(node != NULL)
508        {
509                if(flag == 0 || flag == 2)
510                {
511                        if(flag == 0)
512                        {
513                                //check if section have seen
514                                if(findsectiondone(node->section) == 1)
515                                {
516                                        node = node->next;
517                                        continue;
518                                }
519                        }
520               
521                        tmppic = ostrcat(node->section, ".png", 0, 0);
522               
523                        if(flag == 0)
524                        {
525                                node->done = 1;
526                                addmenulist(&mlist, node->section, NULL, tmppic, 0, 0);
527                        }
528                       
529                        if(flag == 2)
530                        {
531                                tmpstr = ostrcat(tmpstr, node->section, 1, 0);
532                                tmpstr = ostrcat(tmpstr, "-", 1, 0);
533                                tmpstr = ostrcat(tmpstr, node->showname, 1, 0);
534                                addmenulist(&mlist, tmpstr, NULL, tmppic, 0, 0);
535                                free(tmpstr); tmpstr = NULL;
536                        }
537                       
538                        free(tmppic); tmppic = NULL;
539                }
540               
541                if(flag == 1)
542                {
543                        //check if ipkg is installed
544                        node_installed = ipkg_installed;
545                        skip = 0;
546                        while(node_installed != NULL)
547                        {
548                                if(ostrcmp(node->section, node_installed->section) == 0 && ostrcmp(node->showname, node_installed->showname) == 0)
549                                {
550                                        skip = 1;
551                                        break;
552                                }
553                                node_installed = node_installed->next;
554                        }
555                       
556                        //check if ipkg is in section
557                        if(section != NULL && ostrcmp(node->section, section) != 0)
558                                skip = 1;
559
560                        if(skip == 1)
561                        {
562                                node = node->next;
563                                continue;
564                        }
565                       
566                        tmpstr = ostrcat(tmpstr, node->showname, 1, 0);
567                        tmpstr = ostrcat(tmpstr, " v.", 1, 0);
568                        tmpstr = ostrcat(tmpstr, node->version, 1, 0);
569
570                        tmpinfo = ostrcat(tmpinfo, "\nSection: ", 1, 0);
571                        tmpinfo = ostrcat(tmpinfo, node->section, 1, 0);
572                        tmpinfo = ostrcat(tmpinfo, "\nDescription:\n", 1, 0);
573                        if(node->desc != NULL)
574                                tmpinfo = ostrcat(tmpinfo, node->desc, 1, 0);
575                        else
576                                tmpinfo = ostrcat(tmpinfo, _("no description found"), 1, 0);
577                       
578                        tmppic = ostrcat(tmppic, node->showname, 1, 0);
579                        if(tmppic != NULL)
580                        {
581                                char* pos = strchr(tmppic, '.');
582                                if(pos != NULL) pos[0] = '\0';
583                                tmppic = ostrcat("titan-pluginpreview-", tmppic, 0, 1);
584                                tmppic = ostrcat(tmppic, ".png", 1, 0);
585                        }
586
587                        tmpmlist = addmenulist(&mlist, tmpstr, tmpinfo, tmppic, 0, 0);
588                        changemenulistparam(tmpmlist, node->showname, NULL);
589                        free(tmpstr); tmpstr = NULL;
590                        free(tmpinfo); tmpinfo = NULL;
591                        free(tmppic); tmppic = NULL;
592                }
593               
594                node = node->next;
595        }
596       
597        if(flag == 1)
598        {
599                node = ipkg;
600                ipkg = ipkg_installed;
601                freeipkg();
602                ipkg = node;
603        }
604
605        return menulistbox(mlist, paramskinname, skintitle, paramskinpath, "/skin/plugin.png", showpng, 0);
606}
607
608char* get_ipk_tmpinstall(char* path, char* ipk)
609{
610        debug(130, "in");
611
612        unlink("/var/usr/lib/ipkg/cross");
613        unlink("/var/usr/lib/ipkg/secret");
614        unlink("/var/usr/lib/ipkg/titan");     
615
616        char* cmd = NULL, *tmpstr = NULL;
617        cmd = ostrcat(cmd, "ipkg install ", 1, 0);
618        cmd = ostrcat(cmd, path, 1, 0);
619        cmd = ostrcat(cmd, "/", 1, 0);
620        cmd = ostrcat(cmd, ipk, 1, 0);
621
622        tmpstr = command(cmd);
623
624        debug(130, "out %s",cmd);
625        free(cmd); cmd = NULL;
626        return tmpstr;
627}
628
629char* get_ipk_tmplistinstall(char* path)
630{
631        debug(130, "in");
632        char* cmd = NULL, *tmpstr = NULL;
633
634        cmd = ostrcat(cmd, "ls ", 1, 0);
635        cmd = ostrcat(cmd, path, 1, 0);
636        cmd = ostrcat(cmd, " | grep '\\.ipk'", 1, 0);
637
638        tmpstr = command(cmd);
639
640        debug(130, "out %s",cmd);
641        free(cmd); cmd = NULL;
642        return tmpstr;
643}
644
645#endif
646
Note: See TracBrowser for help on using the repository browser.