88#include "http-get/http-get.h"
99#include "registry-internal.h"
1010#include <curl/curl.h>
11- #include <string.h>
1211#include <strdup/strdup.h>
12+ #include <string.h>
13+
14+ static char * string_split (char * in , char sep ) {
15+ char * next_sep = strchr (in , sep );
16+ if (next_sep == NULL ) {
17+ return next_sep ;
18+ }
19+ * next_sep = '\0' ;
20+ return next_sep + sizeof (char );
21+ }
1322
1423/**
1524 * Parse a list of packages from the given `html`
@@ -21,7 +30,7 @@ static list_t *gitlab_registry_parse(const char *hostname, const char *html) {
2130 char * input = strdup (html );
2231 char * line = input ;
2332 char * category = NULL ;
24- while ((line = strtok (line , "\n" ))) {
33+ while ((line = string_split (line , '\n' ))) {
2534 char * dash_position = strstr (line , "-" );
2635 // The line starts with a dash, so we expect a package.
2736 if (dash_position != NULL && dash_position - line < 4 ) {
@@ -58,14 +67,14 @@ static list_t *gitlab_registry_parse(const char *hostname, const char *html) {
5867list_t * gitlab_registry_fetch (const char * url , const char * hostname , const char * secret ) {
5968 http_get_response_t * res ;
6069 if (secret == NULL ) {
61- return NULL ;
70+ res = http_get (url , NULL , 0 );
71+ } else {
72+ char * key = "PRIVATE-TOKEN" ;
73+ unsigned int size = strlen (key ) + strlen (secret ) + 2 ;
74+ char * authentication_header = malloc (size );
75+ snprintf (authentication_header , size , "%s:%s" , key , secret );
76+ res = http_get (url , & authentication_header , 1 );
6277 }
63-
64- char * key = "PRIVATE-TOKEN" ;
65- unsigned int size = strlen (key ) + strlen (secret ) + 2 ;
66- char * authentication_header = malloc (size );
67- snprintf (authentication_header , size , "%s:%s" , key , secret );
68- res = http_get (url , & authentication_header , 1 );
6978 if (!res -> ok ) {
7079 return NULL ;
7180 }
0 commit comments