Skip to content

Commit f11acf8

Browse files
committed
Protect curl global variable
Add prefix to avoid clashes with other programs.
1 parent 3169566 commit f11acf8

File tree

5 files changed

+27
-27
lines changed

5 files changed

+27
-27
lines changed

src/fetch_anthropic.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ acl_fetch_anthropic(config_t *config, const char *prompt, int history_length)
9090
{
9191
CURLcode res;
9292

93-
if (!curl && initialize(config) < 0)
93+
if (!acl_curl && initialize(config) < 0)
9494
return NULL;
9595

9696
if (config->general_verbose)
@@ -166,13 +166,13 @@ acl_fetch_anthropic(config_t *config, const char *prompt, int history_length)
166166

167167
acl_write_log(config, json_request.ptr);
168168

169-
curl_easy_setopt(curl, CURLOPT_URL, config->anthropic_endpoint);
170-
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
171-
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, acl_string_write);
172-
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &json_response);
173-
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json_request.ptr);
169+
curl_easy_setopt(acl_curl, CURLOPT_URL, config->anthropic_endpoint);
170+
curl_easy_setopt(acl_curl, CURLOPT_HTTPHEADER, headers);
171+
curl_easy_setopt(acl_curl, CURLOPT_WRITEFUNCTION, acl_string_write);
172+
curl_easy_setopt(acl_curl, CURLOPT_WRITEDATA, &json_response);
173+
curl_easy_setopt(acl_curl, CURLOPT_POSTFIELDS, json_request.ptr);
174174

175-
res = curl_easy_perform(curl);
175+
res = curl_easy_perform(acl_curl);
176176

177177
if (res != CURLE_OK) {
178178
free(json_request.ptr);

src/fetch_llamacpp.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ acl_fetch_llamacpp(config_t *config, const char *prompt, int history_length)
101101
{
102102
CURLcode res;
103103

104-
if (!curl && initialize(config) < 0)
104+
if (!acl_curl && initialize(config) < 0)
105105
return NULL;
106106

107107
if (config->general_verbose)
@@ -179,13 +179,13 @@ acl_fetch_llamacpp(config_t *config, const char *prompt, int history_length)
179179

180180
acl_write_log(config, json_request.ptr);
181181

182-
curl_easy_setopt(curl, CURLOPT_URL, config->llamacpp_endpoint);
183-
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
184-
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, acl_string_write);
185-
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &json_response);
186-
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json_request.ptr);
182+
curl_easy_setopt(acl_curl, CURLOPT_URL, config->llamacpp_endpoint);
183+
curl_easy_setopt(acl_curl, CURLOPT_HTTPHEADER, headers);
184+
curl_easy_setopt(acl_curl, CURLOPT_WRITEFUNCTION, acl_string_write);
185+
curl_easy_setopt(acl_curl, CURLOPT_WRITEDATA, &json_response);
186+
curl_easy_setopt(acl_curl, CURLOPT_POSTFIELDS, json_request.ptr);
187187

188-
res = curl_easy_perform(curl);
188+
res = curl_easy_perform(acl_curl);
189189

190190
if (res != CURLE_OK) {
191191
free(json_request.ptr);

src/fetch_openai.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ acl_fetch_openai(config_t *config, const char *prompt, int history_length)
8787
{
8888
CURLcode res;
8989

90-
if (!curl && initialize(config) < 0)
90+
if (!acl_curl && initialize(config) < 0)
9191
return NULL;
9292

9393
if (config->general_verbose)
@@ -144,13 +144,13 @@ acl_fetch_openai(config_t *config, const char *prompt, int history_length)
144144

145145
acl_write_log(config, json_request.ptr);
146146

147-
curl_easy_setopt(curl, CURLOPT_URL, config->openai_endpoint);
148-
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
149-
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, acl_string_write);
150-
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &json_response);
151-
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json_request.ptr);
147+
curl_easy_setopt(acl_curl, CURLOPT_URL, config->openai_endpoint);
148+
curl_easy_setopt(acl_curl, CURLOPT_HTTPHEADER, headers);
149+
curl_easy_setopt(acl_curl, CURLOPT_WRITEFUNCTION, acl_string_write);
150+
curl_easy_setopt(acl_curl, CURLOPT_WRITEDATA, &json_response);
151+
curl_easy_setopt(acl_curl, CURLOPT_POSTFIELDS, json_request.ptr);
152152

153-
res = curl_easy_perform(curl);
153+
res = curl_easy_perform(acl_curl);
154154

155155
if (res != CURLE_OK) {
156156
free(json_request.ptr);

src/support.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#include "support.h"
3838

3939
static FILE *logfile;
40-
CURL *curl;
40+
CURL *acl_curl;
4141

4242
// Exit with the specified formatted error message
4343
void
@@ -253,7 +253,7 @@ timestamp(FILE *f)
253253
}
254254

255255
/*
256-
* Initialize curl connections
256+
* Initialize Curl connections
257257
* Return 0 on success -1 on error
258258
*/
259259
int
@@ -282,10 +282,10 @@ curl_initialize(config_t *config)
282282

283283
curl_global_init(CURL_GLOBAL_DEFAULT);
284284

285-
curl = curl_easy_init();
286-
if (!curl)
285+
acl_curl = curl_easy_init();
286+
if (!acl_curl)
287287
acl_readline_printf("\nCURL initialization failed.\n");
288-
return curl ? 0 : -1;
288+
return acl_curl ? 0 : -1;
289289
}
290290

291291
// Write the specified string to the logfile, if enabled

src/support.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
#include "config.h"
2727

28-
extern CURL *curl;
28+
extern CURL *acl_curl;
2929

3030
int acl_safe_asprintf(char **strp, const char *fmt, ...);
3131
char *acl_safe_strdup(const char *s);

0 commit comments

Comments
 (0)