| 109 if(!file) { |
109 if(!file) { |
| 110 return (cxmutstr){NULL,0}; |
110 return (cxmutstr){NULL,0}; |
| 111 } |
111 } |
| 112 |
112 |
| 113 CxBuffer buf; |
113 CxBuffer buf; |
| 114 cxBufferInit(&buf, NULL, 1024, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND); |
114 cxBufferInit(&buf, cxDefaultAllocator, NULL, 1024, CX_BUFFER_AUTO_EXTEND); |
| 115 cx_stream_copy(file, &buf, (cx_read_func)fread, (cx_write_func)cxBufferWrite); |
115 cx_stream_copy(file, &buf, (cx_read_func)fread, (cx_write_func)cxBufferWrite); |
| 116 fclose(file); |
116 fclose(file); |
| 117 |
117 |
| 118 return cx_mutstrn(buf.space, buf.size); |
118 return cx_mutstrn(buf.space, buf.size); |
| 119 } |
119 } |
| 341 |
341 |
| 342 /* |
342 /* |
| 343 * The list secrets->location contains urls or repo names as |
343 * The list secrets->location contains urls or repo names as |
| 344 * location strings. We need a list, that contains only urls |
344 * location strings. We need a list, that contains only urls |
| 345 */ |
345 */ |
| 346 CxList *locations = cxLinkedListCreate(cxDefaultAllocator, (cx_compare_func)cmp_url_cred_entry, CX_STORE_POINTERS); |
346 CxList *locations = cxLinkedListCreate(cxDefaultAllocator, CX_STORE_POINTERS); |
| 347 cxDefineDestructor(locations, free_cred_location); |
347 cxSetCompareFunc(locations, (cx_compare_func)cmp_url_cred_entry); |
| |
348 cxSetDestructor(locations, free_cred_location); |
| 348 CxIterator i = cxListIterator(secrets->locations); |
349 CxIterator i = cxListIterator(secrets->locations); |
| 349 cx_foreach(PwdIndexEntry*, e, i) { |
350 cx_foreach(PwdIndexEntry*, e, i) { |
| 350 CxIterator entry_iter = cxListIterator(e->locations); |
351 CxIterator entry_iter = cxListIterator(e->locations); |
| 351 cx_foreach(char *, loc, entry_iter) { |
352 cx_foreach(char *, loc, entry_iter) { |
| 352 cxmutstr rpath; |
353 cxmutstr rpath; |
| 362 cxListSort(locations); |
363 cxListSort(locations); |
| 363 |
364 |
| 364 // create full request url string and remove protocol prefix |
365 // create full request url string and remove protocol prefix |
| 365 cxmutstr req_url_proto = util_concat_path_s(cx_strcast(repo->url.value), cx_str(path)); |
366 cxmutstr req_url_proto = util_concat_path_s(cx_strcast(repo->url.value), cx_str(path)); |
| 366 cxstring req_url = cx_strcast(req_url_proto); |
367 cxstring req_url = cx_strcast(req_url_proto); |
| 367 if(cx_strprefix(req_url, CX_STR("http://"))) { |
368 if(cx_strprefix(req_url, "http://")) { |
| 368 req_url = cx_strsubs(req_url, 7); |
369 req_url = cx_strsubs(req_url, 7); |
| 369 } else if(cx_strprefix(req_url, CX_STR("https://"))) { |
370 } else if(cx_strprefix(req_url, "https://")) { |
| 370 req_url = cx_strsubs(req_url, 8); |
371 req_url = cx_strsubs(req_url, 8); |
| 371 } |
372 } |
| 372 |
373 |
| 373 // iterate over sorted locations and check if a location is a prefix |
374 // iterate over sorted locations and check if a location is a prefix |
| 374 // of the requested url |
375 // of the requested url |
| 376 i = cxListIterator(locations); |
377 i = cxListIterator(locations); |
| 377 cx_foreach(CredLocation*, cred, i) { |
378 cx_foreach(CredLocation*, cred, i) { |
| 378 cxstring cred_url = cx_str(cred->location); |
379 cxstring cred_url = cx_str(cred->location); |
| 379 |
380 |
| 380 // remove protocol prefix |
381 // remove protocol prefix |
| 381 if(cx_strprefix(cred_url, CX_STR("http://"))) { |
382 if(cx_strprefix(cred_url, "http://")) { |
| 382 cred_url = cx_strsubs(cred_url, 7); |
383 cred_url = cx_strsubs(cred_url, 7); |
| 383 } else if(cx_strprefix(cred_url, CX_STR("https://"))) { |
384 } else if(cx_strprefix(cred_url, "https://")) { |
| 384 cred_url = cx_strsubs(cred_url, 8); |
385 cred_url = cx_strsubs(cred_url, 8); |
| 385 } |
386 } |
| 386 |
387 |
| 387 if(cx_strprefix(req_url, cred_url)) { |
388 if(cx_strprefix(req_url, cred_url)) { |
| 388 id = cred->id; |
389 id = cred->id; |