-
Notifications
You must be signed in to change notification settings - Fork 8
/
pg_curl.c
3062 lines (2965 loc) · 130 KB
/
pg_curl.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <postgres.h>
#include <catalog/pg_type.h>
#include <fmgr.h>
#include <lib/stringinfo.h>
#if PG_VERSION_NUM < 90300
#include <libpq/pqsignal.h>
#endif
#include <miscadmin.h>
#include <signal.h>
#include <utils/builtins.h>
#include <utils/guc.h>
#include <utils/hsearch.h>
#include <utils/memutils.h>
#if PG_VERSION_NUM >= 160000
#include <varatt.h>
#endif
#include <curl/curl.h>
#include <pthread.h>
#define EXTENSION(function) Datum (function)(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(function); Datum (function)(PG_FUNCTION_ARGS)
#define NUMCONN 16
PG_MODULE_MAGIC;
typedef struct {
NameData conname; // !!! always first !!! //
char errbuf[CURL_ERROR_SIZE];
CURLcode errcode;
CURL *easy;
CURLM *multi;
#if CURL_AT_LEAST_VERSION(7, 56, 0)
curl_mime *mime;
#endif
int try;
#if PG_VERSION_NUM >= 90500
MemoryContextCallback easy_cleanup;
#endif
StringInfoData data_in;
StringInfoData data_out;
StringInfoData debug;
StringInfoData header_in;
StringInfoData header_out;
StringInfoData postfield;
StringInfoData readdata;
StringInfoData url;
struct curl_slist *header;
struct curl_slist *postquote;
struct curl_slist *prequote;
struct curl_slist *quote;
#if CURL_AT_LEAST_VERSION(7, 20, 0)
struct curl_slist *recipient;
#endif
} pg_curl_t;
typedef struct {
MemoryContext context;
#if PG_VERSION_NUM >= 90500
MemoryContextCallback cleanup;
#endif
struct {
int requested;
pqsigfunc handler;
} interrupt;
} pg_curl_global_t;
static bool pg_curl_transaction = true;
static CURLM *multi = NULL;
static HTAB *pg_curl_hash = NULL;
#if PG_VERSION_NUM >= 90500
static MemoryContextCallback multi_cleanup = {0};
#endif
static pg_curl_global_t pg_curl_global = {0};
static pg_curl_t pg_curl = {0};
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static void pg_curl_interrupt_handler(int sig) { pg_curl_global.interrupt.requested = sig; }
static int pg_curl_ec(CURLcode ec) {
if (ec < 10) return errcode(MAKE_SQLSTATE('X','E','0','0','0'+ec));
if (ec < 100) return errcode(MAKE_SQLSTATE('X','E','0','0'+ec/10,'0'+ec%10));
if (ec < 1000) return errcode(MAKE_SQLSTATE('X','E','0'+ec/100,'0'+(ec%100)/10,'0'+(ec%100)%10));
return errcode(MAKE_SQLSTATE('X','E','0','0','0'));
}
static int pg_curl_mc(CURLMcode mc) {
if (mc < 10) return errcode(MAKE_SQLSTATE('X','E','0','0','0'+mc));
if (mc < 100) return errcode(MAKE_SQLSTATE('X','E','0','0'+mc/10,'0'+mc%10));
if (mc < 1000) return errcode(MAKE_SQLSTATE('X','E','0'+mc/100,'0'+(mc%100)/10,'0'+(mc%100)%10));
return errcode(MAKE_SQLSTATE('X','M','0','0','0'));
}
#if CURL_AT_LEAST_VERSION(7, 12, 0)
static void *pg_curl_malloc_callback(size_t size) {
void *result;
pthread_mutex_lock(&mutex);
PG_TRY(); {
result = size ? MemoryContextAlloc(pg_curl_global.context, size) : NULL;
} PG_CATCH(); {
pthread_mutex_unlock(&mutex);
PG_RE_THROW();
} PG_END_TRY();
pthread_mutex_unlock(&mutex);
return result;
}
static void pg_curl_free_callback(void *ptr) {
pthread_mutex_lock(&mutex);
PG_TRY(); {
if (ptr) pfree(ptr);
} PG_CATCH(); {
pthread_mutex_unlock(&mutex);
PG_RE_THROW();
} PG_END_TRY();
pthread_mutex_unlock(&mutex);
}
static void *pg_curl_realloc_callback(void *ptr, size_t size) {
void *result;
pthread_mutex_lock(&mutex);
PG_TRY(); {
result = (ptr && size) ? repalloc(ptr, size) : (size ? MemoryContextAlloc(pg_curl_global.context, size) : ptr);
} PG_CATCH(); {
pthread_mutex_unlock(&mutex);
PG_RE_THROW();
} PG_END_TRY();
pthread_mutex_unlock(&mutex);
return result;
}
static char *pg_curl_strdup_callback(const char *str) {
char *result;
pthread_mutex_lock(&mutex);
PG_TRY(); {
result = MemoryContextStrdup(pg_curl_global.context, str);
} PG_CATCH(); {
pthread_mutex_unlock(&mutex);
PG_RE_THROW();
} PG_END_TRY();
pthread_mutex_unlock(&mutex);
return result;
}
static void *pg_curl_calloc_callback(size_t nmemb, size_t size) {
void *result;
pthread_mutex_lock(&mutex);
PG_TRY(); {
result = MemoryContextAllocZero(pg_curl_global.context, nmemb * size);
} PG_CATCH(); {
pthread_mutex_unlock(&mutex);
PG_RE_THROW();
} PG_END_TRY();
pthread_mutex_unlock(&mutex);
return result;
}
#endif
static void pg_curl_hash_init(void) {
if (!pg_curl_hash) {
HASHCTL ctl = {
.keysize = sizeof(NameData),
.entrysize = sizeof(pg_curl_t),
};
pg_curl_hash = hash_create("Connection name hash", NUMCONN, &ctl, HASH_ELEM);
}
}
#if PG_VERSION_NUM >= 90500
static void pg_curl_global_cleanup(void *arg) {
if (!pg_curl_global.context) return;
pqsignal(SIGINT, pg_curl_global.interrupt.handler);
#if CURL_AT_LEAST_VERSION(7, 8, 0)
curl_global_cleanup();
#endif
pg_curl_global.context = NULL;
}
#endif
static void pg_curl_multi_remove_handle(pg_curl_t *curl) {
CURLMcode mc;
if (!curl || !curl->easy || !curl->multi) return;
if ((mc = curl_multi_remove_handle(curl->multi, curl->easy)) != CURLM_OK) ereport(ERROR, (pg_curl_mc(mc), errmsg("%s", curl_multi_strerror(mc))));
curl->multi = NULL;
}
#if PG_VERSION_NUM >= 90500
static void pg_curl_easy_cleanup(void *arg) {
pg_curl_t *curl = arg;
if (!curl || !curl->easy) return;
#if CURL_AT_LEAST_VERSION(7, 56, 0)
curl_mime_free(curl->mime);
curl->mime = NULL;
#endif
curl_slist_free_all(curl->header);
curl->header = NULL;
curl_slist_free_all(curl->postquote);
curl->postquote = NULL;
curl_slist_free_all(curl->prequote);
curl->prequote = NULL;
curl_slist_free_all(curl->quote);
curl->quote = NULL;
#if CURL_AT_LEAST_VERSION(7, 20, 0)
curl_slist_free_all(curl->recipient);
curl->recipient = NULL;
#endif
pg_curl_multi_remove_handle(curl);
curl_easy_cleanup(curl->easy);
curl->easy = NULL;
if (NameStr(curl->conname)[0] && !hash_search(pg_curl_hash, NameStr(curl->conname), HASH_REMOVE, NULL)) ereport(ERROR, (errcode(ERRCODE_UNDEFINED_OBJECT), errmsg("undefined connection name")));
}
#endif
static void pg_curl_global_init(void) {
MemoryContext oldMemoryContext;
if (pg_curl_global.context) return;
#if PG_VERSION_NUM >= 90500
pg_curl_global.context = pg_curl_transaction ? TopTransactionContext : TopMemoryContext;
#else
pg_curl_global.context = TopMemoryContext;
#endif
oldMemoryContext = MemoryContextSwitchTo(pg_curl_global.context);
#if CURL_AT_LEAST_VERSION(7, 12, 0)
if (curl_global_init_mem(CURL_GLOBAL_ALL, pg_curl_malloc_callback, pg_curl_free_callback, pg_curl_realloc_callback, pg_curl_strdup_callback, pg_curl_calloc_callback)) ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("curl_global_init_mem")));
#elif CURL_AT_LEAST_VERSION(7, 8, 0)
if (curl_global_init(CURL_GLOBAL_ALL)) ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("curl_global_init")));
#endif
pg_curl_global.interrupt.requested = 0;
pg_curl_global.interrupt.handler = pqsignal(SIGINT, pg_curl_interrupt_handler);
#if PG_VERSION_NUM >= 90500
pg_curl_global.cleanup.func = pg_curl_global_cleanup;
MemoryContextRegisterResetCallback(pg_curl_global.context, &pg_curl_global.cleanup);
#endif
MemoryContextSwitchTo(oldMemoryContext);
}
#if PG_VERSION_NUM >= 90500
static void pg_curl_multi_cleanup(void *arg) {
CURLMcode mc;
CURLM *multi = arg;
if (!multi) return;
if ((mc = curl_multi_cleanup(multi)) != CURLM_OK) ereport(ERROR, (pg_curl_mc(mc), errmsg("%s", curl_multi_strerror(mc))));
}
#endif
static void pg_curl_multi_init(void) {
if (multi) return;
if (!(multi = curl_multi_init())) ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("!curl_multi_init")));
#if PG_VERSION_NUM >= 90500
multi_cleanup.arg = multi;
multi_cleanup.func = pg_curl_multi_cleanup;
MemoryContextRegisterResetCallback(pg_curl_global.context, &multi_cleanup);
#endif
}
static pg_curl_t *pg_curl_easy_init(NameData *conname) {
MemoryContext oldMemoryContext;
pg_curl_t *curl;
pg_curl_global_init();
oldMemoryContext = MemoryContextSwitchTo(pg_curl_global.context);
pg_curl_multi_init();
if (!conname) curl = &pg_curl; else {
bool found;
pg_curl_hash_init();
curl = hash_search(pg_curl_hash, NameStr(*conname), HASH_ENTER, &found);
if (!found) {
MemSet(curl, 0, sizeof(*curl));
curl->conname = *conname;
}
}
if (curl->easy) return curl;
if (!(curl->easy = curl_easy_init())) ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("!curl_easy_init")));
initStringInfo(&curl->data_in);
initStringInfo(&curl->data_out);
initStringInfo(&curl->debug);
initStringInfo(&curl->header_in);
initStringInfo(&curl->header_out);
initStringInfo(&curl->postfield);
initStringInfo(&curl->readdata);
initStringInfo(&curl->url);
#if PG_VERSION_NUM >= 90500
curl->easy_cleanup.arg = curl;
curl->easy_cleanup.func = pg_curl_easy_cleanup;
MemoryContextRegisterResetCallback(pg_curl_global.context, &curl->easy_cleanup);
#endif
MemoryContextSwitchTo(oldMemoryContext);
return curl;
}
#define PG_CONNAME(arg) (PG_NARGS() < arg + 1 || PG_ARGISNULL(arg)) ? NULL : PG_GETARG_NAME(arg)
EXTENSION(pg_curl_easy_header_reset) {
NameData *conname = PG_CONNAME(0);
pg_curl_t *curl = pg_curl_easy_init(conname);
curl_slist_free_all(curl->header);
curl->header = NULL;
PG_RETURN_VOID();
}
EXTENSION(pg_curl_easy_mime_reset) {
#if CURL_AT_LEAST_VERSION(7, 56, 0)
NameData *conname = PG_CONNAME(0);
pg_curl_t *curl = pg_curl_easy_init(conname);
curl_mime_free(curl->mime);
curl->mime = NULL;
PG_RETURN_VOID();
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_mime_reset requires curl 7.56.0 or later")));
#endif
}
EXTENSION(pg_curl_easy_postquote_reset) {
NameData *conname = PG_CONNAME(0);
pg_curl_t *curl = pg_curl_easy_init(conname);
curl_slist_free_all(curl->postquote);
curl->postquote = NULL;
PG_RETURN_VOID();
}
EXTENSION(pg_curl_easy_prequote_reset) {
NameData *conname = PG_CONNAME(0);
pg_curl_t *curl = pg_curl_easy_init(conname);
curl_slist_free_all(curl->prequote);
curl->prequote = NULL;
PG_RETURN_VOID();
}
EXTENSION(pg_curl_easy_quote_reset) {
NameData *conname = PG_CONNAME(0);
pg_curl_t *curl = pg_curl_easy_init(conname);
curl_slist_free_all(curl->quote);
curl->quote = NULL;
PG_RETURN_VOID();
}
EXTENSION(pg_curl_easy_recipient_reset) {
#if CURL_AT_LEAST_VERSION(7, 20, 0)
NameData *conname = PG_CONNAME(0);
pg_curl_t *curl = pg_curl_easy_init(conname);
curl_slist_free_all(curl->recipient);
curl->recipient = NULL;
PG_RETURN_VOID();
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_recipient_reset requires curl 7.20.0 or later")));
#endif
}
EXTENSION(pg_curl_easy_reset) {
NameData *conname = PG_CONNAME(0);
pg_curl_t *curl = pg_curl_easy_init(conname);
MemSet(curl->errbuf, 0, sizeof(*curl->errbuf));
curl->errcode = CURLE_OK;
pg_curl_easy_header_reset(fcinfo);
pg_curl_easy_postquote_reset(fcinfo);
pg_curl_easy_prequote_reset(fcinfo);
pg_curl_easy_quote_reset(fcinfo);
#if CURL_AT_LEAST_VERSION(7, 56, 0)
pg_curl_easy_mime_reset(fcinfo);
#endif
#if CURL_AT_LEAST_VERSION(7, 20, 0)
pg_curl_easy_recipient_reset(fcinfo);
#endif
#if CURL_AT_LEAST_VERSION(7, 12, 1)
curl_easy_reset(curl->easy);
#endif
resetStringInfo(&curl->data_in);
resetStringInfo(&curl->data_out);
resetStringInfo(&curl->debug);
resetStringInfo(&curl->header_in);
resetStringInfo(&curl->header_out);
resetStringInfo(&curl->postfield);
resetStringInfo(&curl->readdata);
resetStringInfo(&curl->url);
pg_curl_multi_remove_handle(curl);
PG_RETURN_VOID();
}
EXTENSION(pg_curl_easy_escape) {
#if CURL_AT_LEAST_VERSION(7, 15, 4)
text *string;
char *escape;
NameData *conname = PG_CONNAME(1);
pg_curl_t *curl = pg_curl_easy_init(conname);
if (PG_ARGISNULL(0)) ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("curl_easy_escape requires argument string")));
string = PG_GETARG_TEXT_PP(0);
if (!(escape = curl_easy_escape(curl->easy, VARDATA_ANY(string), VARSIZE_ANY_EXHDR(string)))) PG_RETURN_NULL();
PG_FREE_IF_COPY(string, 0);
string = cstring_to_text(escape);
curl_free(escape);
PG_RETURN_TEXT_P(string);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_escape requires curl 7.15.4 or later")));
#endif
}
EXTENSION(pg_curl_easy_unescape) {
#if CURL_AT_LEAST_VERSION(7, 15, 4)
text *url;
char *unescape;
int outlength;
NameData *conname = PG_CONNAME(1);
pg_curl_t *curl = pg_curl_easy_init(conname);
if (PG_ARGISNULL(0)) ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("curl_easy_unescape requires argument url")));
url = PG_GETARG_TEXT_PP(0);
if (!(unescape = curl_easy_unescape(curl->easy, VARDATA_ANY(url), VARSIZE_ANY_EXHDR(url), &outlength))) PG_RETURN_NULL();
PG_FREE_IF_COPY(url, 0);
url = cstring_to_text_with_len(unescape, outlength);
curl_free(unescape);
PG_RETURN_TEXT_P(url);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_unescape requires curl 7.15.4 or later")));
#endif
}
EXTENSION(pg_curl_header_append) {
char *name, *value;
StringInfoData buf;
NameData *conname = PG_CONNAME(2);
pg_curl_t *curl = pg_curl_easy_init(conname);
struct curl_slist *temp = curl->header;
if (PG_ARGISNULL(0)) ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("curl_header_append requires argument name")));
name = TextDatumGetCString(PG_GETARG_DATUM(0));
if (PG_ARGISNULL(1)) ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("curl_header_append requires argument value")));
value = TextDatumGetCString(PG_GETARG_DATUM(1));
initStringInfo(&buf);
appendStringInfo(&buf, "%s: %s", name, value);
if ((temp = curl_slist_append(temp, buf.data))) curl->header = temp; else ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("!curl_slist_append")));
pfree(name);
pfree(value);
pfree(buf.data);
PG_RETURN_BOOL(temp != NULL);
}
EXTENSION(pg_curl_postquote_append) {
char *command;
NameData *conname = PG_CONNAME(1);
pg_curl_t *curl = pg_curl_easy_init(conname);
struct curl_slist *temp = curl->postquote;
if (PG_ARGISNULL(0)) ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("curl_postquote_append requires argument command")));
command = TextDatumGetCString(PG_GETARG_DATUM(0));
if ((temp = curl_slist_append(temp, command))) curl->postquote = temp; else ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("!curl_slist_append")));
pfree(command);
PG_RETURN_BOOL(temp != NULL);
}
EXTENSION(pg_curl_prequote_append) {
char *command;
NameData *conname = PG_CONNAME(1);
pg_curl_t *curl = pg_curl_easy_init(conname);
struct curl_slist *temp = curl->prequote;
if (PG_ARGISNULL(0)) ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("curl_prequote_append requires argument command")));
command = TextDatumGetCString(PG_GETARG_DATUM(0));
if ((temp = curl_slist_append(temp, command))) curl->prequote = temp; else ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("!curl_slist_append")));
pfree(command);
PG_RETURN_BOOL(temp != NULL);
}
EXTENSION(pg_curl_quote_append) {
char *command;
NameData *conname = PG_CONNAME(1);
pg_curl_t *curl = pg_curl_easy_init(conname);
struct curl_slist *temp = curl->quote;
if (PG_ARGISNULL(0)) ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("curl_quote_append requires argument command")));
command = TextDatumGetCString(PG_GETARG_DATUM(0));
if ((temp = curl_slist_append(temp, command))) curl->quote = temp; else ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("!curl_slist_append")));
pfree(command);
PG_RETURN_BOOL(temp != NULL);
}
EXTENSION(pg_curl_recipient_append) {
#if CURL_AT_LEAST_VERSION(7, 20, 0)
char *email;
NameData *conname = PG_CONNAME(1);
pg_curl_t *curl = pg_curl_easy_init(conname);
struct curl_slist *temp = curl->recipient;
if (PG_ARGISNULL(0)) ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("curl_recipient_append requires argument email")));
email = TextDatumGetCString(PG_GETARG_DATUM(0));
if ((temp = curl_slist_append(temp, email))) curl->recipient = temp; else ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("!curl_slist_append")));
pfree(email);
PG_RETURN_BOOL(temp != NULL);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_recipient_append requires curl 7.20.0 or later")));
#endif
}
static Datum pg_curl_mime_data_or_file(PG_FUNCTION_ARGS, curl_mimepart *part) {
#if CURL_AT_LEAST_VERSION(7, 56, 0)
char *name = NULL, *file = NULL, *type = NULL, *code = NULL, *head = NULL;
CURLcode ec = CURL_LAST;
if (!PG_ARGISNULL(1)) name = TextDatumGetCString(PG_GETARG_DATUM(1));
if (!PG_ARGISNULL(2)) file = TextDatumGetCString(PG_GETARG_DATUM(2));
if (!PG_ARGISNULL(3)) type = TextDatumGetCString(PG_GETARG_DATUM(3));
if (!PG_ARGISNULL(4)) code = TextDatumGetCString(PG_GETARG_DATUM(4));
if (!PG_ARGISNULL(5)) head = TextDatumGetCString(PG_GETARG_DATUM(5));
if (name && ((ec = curl_mime_name(part, name)) != CURLE_OK)) ereport(ERROR, (pg_curl_ec(ec), errmsg("%s", curl_easy_strerror(ec))));
if (file && ((ec = curl_mime_filename(part, file)) != CURLE_OK)) ereport(ERROR, (pg_curl_ec(ec), errmsg("%s", curl_easy_strerror(ec))));
if (type && ((ec = curl_mime_type(part, type)) != CURLE_OK)) ereport(ERROR, (pg_curl_ec(ec), errmsg("%s", curl_easy_strerror(ec))));
if (code && ((ec = curl_mime_encoder(part, code)) != CURLE_OK)) ereport(ERROR, (pg_curl_ec(ec), errmsg("%s", curl_easy_strerror(ec))));
if (head) {
struct curl_slist *headers = NULL;
if (!(headers = curl_slist_append(headers, head))) ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("!curl_slist_append")));
if ((ec = curl_mime_headers(part, headers, true)) != CURLE_OK) ereport(ERROR, (pg_curl_ec(ec), errmsg("%s", curl_easy_strerror(ec))));
}
if (name) pfree(name);
if (file) pfree(file);
if (type) pfree(type);
if (code) pfree(code);
if (head) pfree(head);
PG_RETURN_BOOL(ec == CURLE_OK);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_mime_data requires curl 7.56.0 or later")));
#endif
}
EXTENSION(pg_curl_mime_data_text) {
#if CURL_AT_LEAST_VERSION(7, 56, 0)
CURLcode ec = CURL_LAST;
curl_mimepart *part;
NameData *conname = PG_CONNAME(6);
pg_curl_t *curl = pg_curl_easy_init(conname);
if (!curl->mime && !(curl->mime = curl_mime_init(curl->easy))) ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("!curl_mime_init")));
if (!(part = curl_mime_addpart(curl->mime))) ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("!curl_mime_addpart")));
if (!PG_ARGISNULL(0)) {
text *data = PG_GETARG_TEXT_PP(0);
if ((ec = curl_mime_data(part, VARDATA_ANY(data), VARSIZE_ANY_EXHDR(data))) != CURLE_OK) ereport(ERROR, (pg_curl_ec(ec), errmsg("%s", curl_easy_strerror(ec))));
PG_FREE_IF_COPY(data, 0);
}
return pg_curl_mime_data_or_file(fcinfo, part);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_mime_data requires curl 7.56.0 or later")));
#endif
}
EXTENSION(pg_curl_mime_data_bytea) {
#if CURL_AT_LEAST_VERSION(7, 56, 0)
CURLcode ec = CURL_LAST;
curl_mimepart *part;
NameData *conname = PG_CONNAME(6);
pg_curl_t *curl = pg_curl_easy_init(conname);
if (!curl->mime && !(curl->mime = curl_mime_init(curl->easy))) ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("!curl_mime_init")));
if (!(part = curl_mime_addpart(curl->mime))) ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("!curl_mime_addpart")));
if (!PG_ARGISNULL(0)) {
bytea *data = PG_GETARG_BYTEA_PP(0);
if ((ec = curl_mime_data(part, VARDATA_ANY(data), VARSIZE_ANY_EXHDR(data))) != CURLE_OK) ereport(ERROR, (pg_curl_ec(ec), errmsg("%s", curl_easy_strerror(ec))));
PG_FREE_IF_COPY(data, 0);
}
return pg_curl_mime_data_or_file(fcinfo, part);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_mime_data requires curl 7.56.0 or later")));
#endif
}
EXTENSION(pg_curl_mime_file) {
#if CURL_AT_LEAST_VERSION(7, 56, 0)
CURLcode ec = CURL_LAST;
curl_mimepart *part;
NameData *conname = PG_CONNAME(6);
pg_curl_t *curl = pg_curl_easy_init(conname);
if (PG_ARGISNULL(0)) ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("curl_mime_file requires argument data")));
if (!curl->mime && !(curl->mime = curl_mime_init(curl->easy))) ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("!curl_mime_init")));
if (!(part = curl_mime_addpart(curl->mime))) ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("!curl_mime_addpart")));
if (!PG_ARGISNULL(0)) {
char *data = TextDatumGetCString(PG_GETARG_DATUM(0));
if ((ec = curl_mime_filedata(part, data)) != CURLE_OK) ereport(ERROR, (pg_curl_ec(ec), errmsg("%s", curl_easy_strerror(ec))));
pfree(data);
}
return pg_curl_mime_data_or_file(fcinfo, part);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_mime_file requires curl 7.56.0 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_postfields) {
CURLcode ec = CURLE_OK;
bytea *parameter;
NameData *conname = PG_CONNAME(1);
pg_curl_t *curl = pg_curl_easy_init(conname);
if (PG_ARGISNULL(0)) ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("curl_easy_setopt_postfields requires argument parameter")));
parameter = PG_GETARG_BYTEA_PP(0);
resetStringInfo(&curl->postfield);
resetStringInfo(&curl->readdata);
appendBinaryStringInfo(&curl->postfield, VARDATA_ANY(parameter), VARSIZE_ANY_EXHDR(parameter));
PG_FREE_IF_COPY(parameter, 0);
PG_RETURN_BOOL(ec == CURLE_OK);
}
EXTENSION(pg_curl_easy_setopt_readdata) {
CURLcode ec = CURLE_OK;
bytea *parameter;
NameData *conname = PG_CONNAME(1);
pg_curl_t *curl = pg_curl_easy_init(conname);
if (PG_ARGISNULL(0)) ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("curl_easy_setopt_readdata requires argument parameter")));
parameter = PG_GETARG_BYTEA_PP(0);
resetStringInfo(&curl->postfield);
resetStringInfo(&curl->readdata);
appendBinaryStringInfo(&curl->readdata, VARDATA_ANY(parameter), VARSIZE_ANY_EXHDR(parameter));
PG_FREE_IF_COPY(parameter, 0);
PG_RETURN_BOOL(ec == CURLE_OK);
}
EXTENSION(pg_curl_easy_setopt_url) {
CURLcode ec = CURLE_OK;
text *parameter;
NameData *conname = PG_CONNAME(1);
pg_curl_t *curl = pg_curl_easy_init(conname);
if (PG_ARGISNULL(0)) ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("curl_easy_setopt_url requires argument parameter")));
parameter = PG_GETARG_TEXT_PP(0);
resetStringInfo(&curl->url);
appendBinaryStringInfo(&curl->url, VARDATA_ANY(parameter), VARSIZE_ANY_EXHDR(parameter));
PG_FREE_IF_COPY(parameter, 0);
PG_RETURN_BOOL(ec == CURLE_OK);
}
static Datum pg_curl_postfield_or_url_append(PG_FUNCTION_ARGS, pg_curl_t *curl, StringInfoData *buf) {
char *escape;
CURLcode ec = CURLE_OK;
text *name = PG_GETARG_TEXT_PP(0);
if (buf->len && buf->data[buf->len - 1] != '?') appendStringInfoChar(buf, '&');
if (!(escape = curl_easy_escape(curl->easy, VARDATA_ANY(name), VARSIZE_ANY_EXHDR(name)))) ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("curl_easy_escape failed")));
appendStringInfoString(buf, escape);
PG_FREE_IF_COPY(name, 0);
if (!PG_ARGISNULL(1)) {
text *value = PG_GETARG_TEXT_PP(1);
appendStringInfoChar(buf, '=');
if (VARSIZE_ANY_EXHDR(value)) {
if (!(escape = curl_easy_escape(curl->easy, VARDATA_ANY(value), VARSIZE_ANY_EXHDR(value)))) ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("curl_easy_escape failed")));
appendStringInfoString(buf, escape);
}
PG_FREE_IF_COPY(value, 1);
}
PG_RETURN_BOOL(ec == CURLE_OK);
}
EXTENSION(pg_curl_postfield_append) {
NameData *conname = PG_CONNAME(2);
pg_curl_t *curl = pg_curl_easy_init(conname);
if (PG_ARGISNULL(0)) ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("pg_curl_postfield_append requires argument name")));
resetStringInfo(&curl->readdata);
return pg_curl_postfield_or_url_append(fcinfo, curl, &curl->postfield);
}
EXTENSION(pg_curl_url_append) {
NameData *conname = PG_CONNAME(2);
pg_curl_t *curl = pg_curl_easy_init(conname);
if (PG_ARGISNULL(0)) ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("pg_curl_url_append requires argument name")));
return pg_curl_postfield_or_url_append(fcinfo, curl, &curl->url);
}
#if CURL_AT_LEAST_VERSION(7, 71, 0)
static Datum pg_curl_easy_setopt_blob(PG_FUNCTION_ARGS, CURLoption option) {
CURLcode ec = CURLE_OK;
bytea *parameter;
struct curl_blob blob;
NameData *conname = PG_CONNAME(1);
pg_curl_t *curl = pg_curl_easy_init(conname);
if (PG_ARGISNULL(0)) ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("curl_easy_setopt_* requires argument parameter")));
parameter = PG_GETARG_BYTEA_PP(0);
blob.data = VARDATA_ANY(parameter);
blob.flags = CURL_BLOB_COPY;
blob.len = VARSIZE_ANY_EXHDR(parameter);
if ((ec = curl_easy_setopt(curl->easy, option, &blob)) != CURLE_OK) ereport(ERROR, (pg_curl_ec(ec), errmsg("%s", curl_easy_strerror(ec))));
PG_FREE_IF_COPY(parameter, 0);
PG_RETURN_BOOL(ec == CURLE_OK);
}
#endif
static Datum pg_curl_easy_setopt_char(PG_FUNCTION_ARGS, CURLoption option) {
CURLcode ec = CURL_LAST;
char *parameter;
NameData *conname = PG_CONNAME(1);
pg_curl_t *curl = pg_curl_easy_init(conname);
if (PG_ARGISNULL(0)) ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("curl_easy_setopt_* requires argument parameter")));
parameter = TextDatumGetCString(PG_GETARG_DATUM(0));
if ((ec = curl_easy_setopt(curl->easy, option, parameter)) != CURLE_OK) ereport(ERROR, (pg_curl_ec(ec), errmsg("%s", curl_easy_strerror(ec))));
pfree(parameter);
PG_RETURN_BOOL(ec == CURLE_OK);
}
static int pg_debug_callback(CURL *handle, curl_infotype type, char *data, size_t size, void *userptr) {
pg_curl_t *curl = userptr;
if (size) switch (type) {
case CURLINFO_DATA_OUT: appendBinaryStringInfo(&curl->data_out, data, size); break;
case CURLINFO_HEADER_IN: fwrite("< ", sizeof("< ") - 1, 1, stderr); fwrite(data, size, 1, stderr); break;
case CURLINFO_HEADER_OUT: fwrite("> ", sizeof("> ") - 1, 1, stderr); fwrite(data, size, 1, stderr); appendBinaryStringInfo(&curl->header_out, data, size); break;
case CURLINFO_TEXT: fwrite("* ", sizeof("* ") - 1, 1, stderr); fwrite(data, size, 1, stderr); appendBinaryStringInfo(&curl->debug, data, size); break;
default: break;
}
return 0;
}
EXTENSION(pg_curl_easy_setopt_abstract_unix_socket) {
#if CURL_AT_LEAST_VERSION(7, 53, 0)
return pg_curl_easy_setopt_char(fcinfo, CURLOPT_ABSTRACT_UNIX_SOCKET);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_abstract_unix_socket requires curl 7.53.0 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_accept_encoding) {
#if CURL_AT_LEAST_VERSION(7, 21, 6)
return pg_curl_easy_setopt_char(fcinfo, CURLOPT_ACCEPT_ENCODING);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_accept_encoding requires curl 7.21.6 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_cainfo_blob) {
#if CURL_AT_LEAST_VERSION(7, 77, 0)
return pg_curl_easy_setopt_blob(fcinfo, CURLOPT_CAINFO_BLOB);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_cainfo_blob requires curl 7.77.0 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_cainfo) {
#if CURL_AT_LEAST_VERSION(7, 60, 0)
return pg_curl_easy_setopt_char(fcinfo, CURLOPT_CAINFO);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_cainfo requires curl 7.60.0 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_capath) {
#if CURL_AT_LEAST_VERSION(7, 56, 0)
return pg_curl_easy_setopt_char(fcinfo, CURLOPT_CAPATH);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_capath requires curl 7.56.0 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_cookiefile) { return pg_curl_easy_setopt_char(fcinfo, CURLOPT_COOKIEFILE); }
EXTENSION(pg_curl_easy_setopt_cookiejar) { return pg_curl_easy_setopt_char(fcinfo, CURLOPT_COOKIEJAR); }
EXTENSION(pg_curl_easy_setopt_cookielist) {
#if CURL_AT_LEAST_VERSION(7, 14, 1)
return pg_curl_easy_setopt_char(fcinfo, CURLOPT_COOKIELIST);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_cookielist requires curl 7.14.1 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_cookie) { return pg_curl_easy_setopt_char(fcinfo, CURLOPT_COOKIE); }
EXTENSION(pg_curl_easy_setopt_crlfile) {
#if CURL_AT_LEAST_VERSION(7, 19, 0)
return pg_curl_easy_setopt_char(fcinfo, CURLOPT_CRLFILE);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_crlfile requires curl 7.19.0 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_customrequest) {
#if CURL_AT_LEAST_VERSION(7, 26, 0)
return pg_curl_easy_setopt_char(fcinfo, CURLOPT_CUSTOMREQUEST);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_customrequest requires curl 7.26.0 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_default_protocol) {
#if CURL_AT_LEAST_VERSION(7, 45, 0)
return pg_curl_easy_setopt_char(fcinfo, CURLOPT_DEFAULT_PROTOCOL);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_default_protocol requires curl 7.45.0 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_dns_interface) {
#if CURL_AT_LEAST_VERSION(7, 33, 0)
return pg_curl_easy_setopt_char(fcinfo, CURLOPT_DNS_INTERFACE);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_dns_interface requires curl 7.33.0 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_dns_local_ip4) {
#if CURL_AT_LEAST_VERSION(7, 33, 0)
return pg_curl_easy_setopt_char(fcinfo, CURLOPT_DNS_LOCAL_IP4);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_dns_local_ip4 requires curl 7.33.0 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_dns_local_ip6) {
#if CURL_AT_LEAST_VERSION(7, 33, 0)
return pg_curl_easy_setopt_char(fcinfo, CURLOPT_DNS_LOCAL_IP6);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_dns_local_ip6 requires curl 7.33.0 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_dns_servers) {
#if CURL_AT_LEAST_VERSION(7, 24, 0)
return pg_curl_easy_setopt_char(fcinfo, CURLOPT_DNS_SERVERS);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("url_easy_setopt_dns_servers requires curl 7.24.0 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_doh_url) {
#if CURL_AT_LEAST_VERSION(7, 62, 0)
return pg_curl_easy_setopt_char(fcinfo, CURLOPT_DOH_URL);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_doh_url requires curl 7.62.0 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_egdsocket) {
#if CURL_AT_LEAST_VERSION(7, 84, 0)
ereport(ERROR, (errcode(ERRCODE_WARNING_DEPRECATED_FEATURE), errmsg("curl_easy_setopt_egdsocket deprecated: since 7.84.0. Serves no purpose anymore")));
#else
return pg_curl_easy_setopt_char(fcinfo, CURLOPT_EGDSOCKET);
#endif
}
EXTENSION(pg_curl_easy_setopt_ftp_account) {
#if CURL_AT_LEAST_VERSION(7, 13, 0)
return pg_curl_easy_setopt_char(fcinfo, CURLOPT_FTP_ACCOUNT);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_ftp_account requires curl 7.13.0 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_ftp_alternative_to_user) {
#if CURL_AT_LEAST_VERSION(7, 15, 5)
return pg_curl_easy_setopt_char(fcinfo, CURLOPT_FTP_ALTERNATIVE_TO_USER);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_ftp_alternative_to_user requires curl 7.15.5 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_ftpport) {
#if CURL_AT_LEAST_VERSION(7, 19, 5)
return pg_curl_easy_setopt_char(fcinfo, CURLOPT_FTPPORT);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_ftpport requires curl 7.19.5 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_interface) {
#if CURL_AT_LEAST_VERSION(7, 24, 0)
return pg_curl_easy_setopt_char(fcinfo, CURLOPT_INTERFACE);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_interface requires curl 7.24.0 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_issuercert_blob) {
#if CURL_AT_LEAST_VERSION(7, 71, 0)
return pg_curl_easy_setopt_blob(fcinfo, CURLOPT_ISSUERCERT_BLOB);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_issuercert_blob requires curl 7.71.0 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_issuercert) { return pg_curl_easy_setopt_char(fcinfo, CURLOPT_ISSUERCERT); }
EXTENSION(pg_curl_easy_setopt_keypasswd) {
#if CURL_AT_LEAST_VERSION(7, 16, 5)
return pg_curl_easy_setopt_char(fcinfo, CURLOPT_KEYPASSWD);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_keypasswd requires curl 7.16.5 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_krblevel) {
#if CURL_AT_LEAST_VERSION(7, 16, 4)
return pg_curl_easy_setopt_char(fcinfo, CURLOPT_KRBLEVEL);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_krblevel requires curl 7.16.4 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_login_options) {
#if CURL_AT_LEAST_VERSION(7, 34, 0)
return pg_curl_easy_setopt_char(fcinfo, CURLOPT_LOGIN_OPTIONS);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_login_options requires curl 7.34.0 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_mail_auth) {
#if CURL_AT_LEAST_VERSION(7, 25, 0)
return pg_curl_easy_setopt_char(fcinfo, CURLOPT_MAIL_AUTH);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_mail_auth requires curl 7.25.0 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_mail_from) {
#if CURL_AT_LEAST_VERSION(7, 20, 0)
return pg_curl_easy_setopt_char(fcinfo, CURLOPT_MAIL_FROM);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_mail_from requires curl 7.20.0 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_noproxy) {
#if CURL_AT_LEAST_VERSION(7, 19, 4)
return pg_curl_easy_setopt_char(fcinfo, CURLOPT_NOPROXY);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_noproxy requires curl 7.19.4 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_password) {
#if CURL_AT_LEAST_VERSION(7, 19, 1)
return pg_curl_easy_setopt_char(fcinfo, CURLOPT_PASSWORD);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_password requires curl 7.19.1 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_pinnedpublickey) {
#if CURL_AT_LEAST_VERSION(7, 39, 0)
return pg_curl_easy_setopt_char(fcinfo, CURLOPT_PINNEDPUBLICKEY);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_pinnedpublickey requires curl 7.39.0 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_pre_proxy) {
#if CURL_AT_LEAST_VERSION(7, 52, 0)
return pg_curl_easy_setopt_char(fcinfo, CURLOPT_PRE_PROXY);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_pre_proxy requires curl 7.52.0 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_protocols_str) {
#if CURL_AT_LEAST_VERSION(7, 85, 0)
return pg_curl_easy_setopt_char(fcinfo, CURLOPT_PROTOCOLS_STR);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_protocols_str requires curl 7.85.0 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_proxy_cainfo_blob) {
#if CURL_AT_LEAST_VERSION(7, 77, 0)
return pg_curl_easy_setopt_blob(fcinfo, CURLOPT_PROXY_CAINFO_BLOB);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_proxy_cainfo_blob requires curl 7.77.0 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_proxy_cainfo) {
#if CURL_AT_LEAST_VERSION(7, 52, 0)
return pg_curl_easy_setopt_char(fcinfo, CURLOPT_PROXY_CAINFO);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_proxy_cainfo requires curl 7.52.0 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_proxy_capath) {
#if CURL_AT_LEAST_VERSION(7, 52, 0)
return pg_curl_easy_setopt_char(fcinfo, CURLOPT_PROXY_CAPATH);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_proxy_capath requires curl 7.52.0 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_proxy_crlfile) {
#if CURL_AT_LEAST_VERSION(7, 52, 0)
return pg_curl_easy_setopt_char(fcinfo, CURLOPT_PROXY_CRLFILE);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_proxy_crlfile requires curl 7.52.0 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_proxy_issuercert_blob) {
#if CURL_AT_LEAST_VERSION(7, 71, 0)
return pg_curl_easy_setopt_blob(fcinfo, CURLOPT_PROXY_ISSUERCERT_BLOB);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_proxy_issuercert_blob requires curl 7.71.0 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_proxy_issuercert) {
#if CURL_AT_LEAST_VERSION(7, 71, 0)
return pg_curl_easy_setopt_blob(fcinfo, CURLOPT_PROXY_ISSUERCERT);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_proxy_issuercert requires curl 7.71.0 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_proxy_keypasswd) {
#if CURL_AT_LEAST_VERSION(7, 52, 0)
return pg_curl_easy_setopt_char(fcinfo, CURLOPT_PROXY_KEYPASSWD);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_proxy_keypasswd requires curl 7.52.0 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_proxypassword) {
#if CURL_AT_LEAST_VERSION(7, 19, 1)
return pg_curl_easy_setopt_char(fcinfo, CURLOPT_PROXYPASSWORD);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_proxypassword requires curl 7.19.1 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_proxy_pinnedpublickey) {
#if CURL_AT_LEAST_VERSION(7, 52, 0)
return pg_curl_easy_setopt_char(fcinfo, CURLOPT_PROXY_PINNEDPUBLICKEY);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_proxy_pinnedpublickey requires curl 7.52.0 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_proxy_service_name) {
#if CURL_AT_LEAST_VERSION(7, 43, 0)
return pg_curl_easy_setopt_char(fcinfo, CURLOPT_PROXY_SERVICE_NAME);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_proxy_service_name requires curl 7.43.0 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_proxy) {
#if CURL_AT_LEAST_VERSION(7, 14, 1)
return pg_curl_easy_setopt_char(fcinfo, CURLOPT_PROXY);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_proxy requires curl 7.14.1 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_proxy_sslcert_blob) {
#if CURL_AT_LEAST_VERSION(7, 71, 0)
return pg_curl_easy_setopt_blob(fcinfo, CURLOPT_PROXY_SSLCERT_BLOB);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_proxy_sslcert_blob requires curl 7.71.0 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_proxy_sslcert) {
#if CURL_AT_LEAST_VERSION(7, 52, 0)
return pg_curl_easy_setopt_char(fcinfo, CURLOPT_PROXY_SSLCERT);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_proxy_sslcert requires curl 7.52.0 or later")));
#endif
}
EXTENSION(pg_curl_easy_setopt_proxy_sslcerttype) {
#if CURL_AT_LEAST_VERSION(7, 52, 0)
return pg_curl_easy_setopt_char(fcinfo, CURLOPT_PROXY_SSLCERTTYPE);
#else
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("curl_easy_setopt_proxy_sslcerttype requires curl 7.52.0 or later")));