1717#include "http-get/http-get.h"
1818#include "logger/logger.h"
1919#include "parson/parson.h"
20+ #include "registry-manager.h"
21+ #include "registry/wiki-registry.h"
2022#include "strdup/strdup.h"
2123#include "tempdir/tempdir.h"
2224#include "version.h"
23- #include "registry/wiki-registry.h"
25+ #include <clib-secrets.h>
2426#include <stdio.h>
2527#include <stdlib.h>
2628#include <string.h>
2729#include <time.h>
30+ #include <url/url.h>
2831
2932#define CLIB_WIKI_URL "https://github.com/clibs/clib/wiki/Packages"
3033
@@ -72,13 +75,13 @@ static int matches(int count, char *args[], wiki_package_ptr_t pkg) {
7275 char * href = NULL ;
7376 int rc = 0 ;
7477
75- name = clib_package_parse_name (wiki_package_get_repo (pkg ));
78+ name = clib_package_parse_name (wiki_package_get_id (pkg ));
7679 COMPARE (name );
7780
7881 description = strdup (wiki_package_get_description (pkg ));
7982 COMPARE (description );
8083
81- repo = strdup (wiki_package_get_repo (pkg ));
84+ repo = strdup (wiki_package_get_id (pkg ));
8285 COMPARE (repo );
8386
8487 href = strdup (wiki_package_get_href (pkg ));
@@ -123,7 +126,7 @@ static char *wiki_html_cache() {
123126static void display_package (const wiki_package_ptr_t pkg ,
124127 cc_color_t fg_color_highlight ,
125128 cc_color_t fg_color_text ) {
126- cc_fprintf (fg_color_highlight , stdout , " %s\n" , wiki_package_get_repo (pkg ));
129+ cc_fprintf (fg_color_highlight , stdout , " %s\n" , wiki_package_get_id (pkg ));
127130 printf (" url: " );
128131 cc_fprintf (fg_color_text , stdout , "%s\n" , wiki_package_get_href (pkg ));
129132 printf (" desc: " );
@@ -136,7 +139,7 @@ static void add_package_to_json(const wiki_package_ptr_t pkg,
136139 JSON_Value * json_pkg_root = json_value_init_object ();
137140 JSON_Object * json_pkg = json_value_get_object (json_pkg_root );
138141
139- json_object_set_string (json_pkg , "repo" , wiki_package_get_repo (pkg ));
142+ json_object_set_string (json_pkg , "repo" , wiki_package_get_id (pkg ));
140143 json_object_set_string (json_pkg , "href" , wiki_package_get_href (pkg ));
141144 json_object_set_string (json_pkg , "description" , wiki_package_get_description (pkg ));
142145 json_object_set_string (json_pkg , "category" , wiki_package_get_category (pkg ));
@@ -176,26 +179,11 @@ int main(int argc, char *argv[]) {
176179
177180 // We search the local manifest for extra registries.
178181 // It is important to give the extra registries preference over the default registry.
179- clib_package_t * package = clib_package_load_local_manifest (0 );
180- wiki_registry_ptr_t * registries = malloc ((package -> registries -> len + 1 ) * sizeof (wiki_registry_ptr_t ));
181- int registry_count = 0 ;
182-
183- list_iterator_t * registry_iterator = list_iterator_new (package -> registries , LIST_HEAD );
184- list_node_t * node ;
185- while ((node = list_iterator_next (registry_iterator ))) {
186- registries [registry_count ] = wiki_registry_create (node -> val );
187- if (!wiki_registry_fetch (registries [registry_count ])) {
188- printf ("SEARCH, could not list packages from. %s\n" , wiki_registry_get_url (registries [registry_count ]));
189- } else {
190- registry_count ++ ;
191- }
192- }
193- list_iterator_destroy (registry_iterator );
182+ clib_secrets_t secrets = clib_secrets_load_from_file ("clib_secrets.json" );
194183
195- // And add the default registry.
196- //registries[registry_count] = wiki_registry_create(CLIB_WIKI_URL);
197- //wiki_registry_fetch(registries[registry_count]);
198- //registry_count++;
184+ clib_package_t * package = clib_package_load_local_manifest (0 );
185+ registries_t registries = registry_manager_init_registries (package -> registries , secrets );
186+ registry_manager_fetch_registries (registries );
199187
200188 // TODO, implement caching for the new registries.
201189 /*
@@ -210,10 +198,12 @@ int main(int argc, char *argv[]) {
210198 debug(&debugger, "found %zu packages", pkgs->len);
211199 */
212200
213- for (int i = 0 ; i < registry_count ; i ++ ) {
214- printf ("SEARCH: packages from %s\n" , wiki_registry_get_url (registries [i ]));
201+ registry_iterator_t it = registry_iterator_new (registries );
202+ wiki_registry_ptr_t registry = NULL ;
203+ while ((registry = registry_iterator_next (it ))) {
204+ printf ("SEARCH: packages from %s\n" , wiki_registry_get_url (registry ));
215205 wiki_package_ptr_t pkg ;
216- wiki_registry_iterator_t it = wiki_registry_iterator_new (registries [ i ] );
206+ wiki_registry_iterator_t it = wiki_registry_iterator_new (registry );
217207
218208 JSON_Array * json_list = NULL ;
219209 JSON_Value * json_list_root = NULL ;
@@ -233,7 +223,7 @@ int main(int argc, char *argv[]) {
233223 display_package (pkg , fg_color_highlight , fg_color_text );
234224 }
235225 } else {
236- debug (& debugger , "skipped package %s" , wiki_package_get_repo (pkg ));
226+ debug (& debugger , "skipped package %s" , wiki_package_get_id (pkg ));
237227 }
238228 }
239229
@@ -246,7 +236,6 @@ int main(int argc, char *argv[]) {
246236 }
247237
248238 wiki_registry_iterator_destroy (it );
249- wiki_registry_free (registries [i ]);
250239 }
251240 command_free (& program );
252241 return 0 ;
0 commit comments