8
8
#include "http-get/http-get.h"
9
9
#include "registry-internal.h"
10
10
#include <curl/curl.h>
11
- #include <string.h>
12
11
#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
+ }
13
22
14
23
/**
15
24
* 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) {
21
30
char * input = strdup (html );
22
31
char * line = input ;
23
32
char * category = NULL ;
24
- while ((line = strtok (line , "\n" ))) {
33
+ while ((line = string_split (line , '\n' ))) {
25
34
char * dash_position = strstr (line , "-" );
26
35
// The line starts with a dash, so we expect a package.
27
36
if (dash_position != NULL && dash_position - line < 4 ) {
@@ -58,14 +67,14 @@ static list_t *gitlab_registry_parse(const char *hostname, const char *html) {
58
67
list_t * gitlab_registry_fetch (const char * url , const char * hostname , const char * secret ) {
59
68
http_get_response_t * res ;
60
69
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 );
62
77
}
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 );
69
78
if (!res -> ok ) {
70
79
return NULL ;
71
80
}
0 commit comments