-
Notifications
You must be signed in to change notification settings - Fork 459
S3 Code Rewrite #1958
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
S3 Code Rewrite #1958
Conversation
hfile_s3.c
Outdated
|
|
||
|
|
||
| if (ret) { | ||
| fprintf(stderr, "Unable to open file.\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to do something like hfile_libcul's easy_errno() here.
Add code to read from S3 sources in the same style as the current writing code. Merge the s3_write.c code into hfile_s3.c to put all the S3 code in the same file. This should simplify the S3 code and give us a little more flexibility in how we use it.
| struct curl_slist *headers = NULL; | ||
|
|
||
| // add the scheme marker | ||
| ksprintf(&final_url, "s3w+%s", url.s); | ||
| if (auth->l) | ||
| if ((headers = curl_slist_append(headers, auth->s)) == NULL) | ||
| goto error; | ||
|
|
||
| if(final_url.l == 0) goto error; | ||
| if ((headers = curl_slist_append(headers, date->s)) == NULL) | ||
| goto error; | ||
|
|
||
| fp = hopen(final_url.s, mode, "va_list", argsp, | ||
| "s3_auth_callback", write_authorisation_callback, | ||
| "s3_auth_callback_data", ad, | ||
| "redirect_callback", redirect_endpoint_callback, | ||
| "set_region_callback", set_region, | ||
| NULL); | ||
| free(final_url.s); | ||
| if (content->l) | ||
| if ((headers = curl_slist_append(headers, content->s)) == NULL) | ||
| goto error; | ||
|
|
||
| if (fp == NULL) goto error; | ||
| if (range) { | ||
| if ((headers = curl_slist_append(headers, range->s)) == NULL) | ||
| goto error; | ||
| } | ||
|
|
||
| free(url.s); | ||
|
|
||
| return fp; | ||
| if (token->l) { | ||
| if ((headers = curl_slist_append(headers, token->s)) == NULL) | ||
| goto error; | ||
| } | ||
|
|
||
| error: | ||
| curl_easy_setopt(fp->curl, CURLOPT_HTTPHEADER, headers); | ||
|
|
||
| if (fp) hclose_abruptly(fp); | ||
| free(url.s); | ||
| free_auth_data(ad); | ||
| error: | ||
|
|
||
| return NULL; | ||
| return headers; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a risk of leaking headers here because curl_slist_append() can return NULL. In fact, gievn the number of times it's called, I'd be tempted to wrap it in a function that takes a struct curl_slist **, and returns a non-zero value on error so the dance needed to prevent loss of the pointer doesn't have to be repeated.
| static int set_region(void *adv, kstring_t *region) { | ||
| s3_auth_data *ad = (s3_auth_data *) adv; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Casting from a void * is no longer needed here.
| static int set_region(void *adv, kstring_t *region) { | |
| s3_auth_data *ad = (s3_auth_data *) adv; | |
| static int set_region(s3_auth_data *ad, kstring_t *region) { |
| return -1; | ||
| } | ||
|
|
||
| ret = set_region((void *)fp->au, ®ion); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This cast can be removed.
| #ifdef ENABLE_PLUGINS | ||
| // Embed version string for examination via strings(1) or what(1) | ||
| static const char id[] = | ||
| "@(#)hfile_s3 test plugin (htslib)\t" HTS_VERSION_TEXT; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a test any more!
Add code to read from S3 sources in the same style as the current writing code. Merge the s3_write.c code into hfile_s3.c to put all the S3 code in the same file.
This should simplify the S3 code and give us a little more flexibility in how we use it.
Still need to remove the old writing code (file removal and other modifications).