@@ -583,6 +583,37 @@ static SQLRETURN dbc_curl_init(esodbc_dbc_st *dbc)
583
583
INFOH (dbc , "no username provided: auth disabled." );
584
584
}
585
585
586
+ /* proxy parameters */
587
+ if (dbc -> proxy_url .cnt ) {
588
+ dbc -> curl_err = curl_easy_setopt (curl , CURLOPT_PROXY ,
589
+ dbc -> proxy_url .str );
590
+ if (dbc -> curl_err != CURLE_OK ) {
591
+ ERRH (dbc , "libcurl: failed to set the proxy URL." );
592
+ goto err ;
593
+ }
594
+ if (dbc -> proxy_uid .cnt ) {
595
+ dbc -> curl_err = curl_easy_setopt (curl , CURLOPT_PROXYUSERNAME ,
596
+ dbc -> proxy_uid .str );
597
+ if (dbc -> curl_err != CURLE_OK ) {
598
+ ERRH (dbc , "libcurl: failed to set the proxy username." );
599
+ goto err ;
600
+ }
601
+ if (dbc -> proxy_pwd .cnt ) {
602
+ dbc -> curl_err = curl_easy_setopt (curl , CURLOPT_PROXYPASSWORD ,
603
+ dbc -> proxy_pwd .str );
604
+ if (dbc -> curl_err != CURLE_OK ) {
605
+ ERRH (dbc , "libcurl: failed to set the proxy password." );
606
+ goto err ;
607
+ }
608
+ }
609
+ }
610
+ } else {
611
+ dbc -> curl_err = curl_easy_setopt (curl , CURLOPT_PROXY , "" );
612
+ if (dbc -> curl_err != CURLE_OK ) {
613
+ WARNH (dbc , "libcurl: failed to generally disable proxying." );
614
+ }
615
+ }
616
+
586
617
/* set the write call-back for answers */
587
618
dbc -> curl_err = curl_easy_setopt (curl , CURLOPT_WRITEFUNCTION ,
588
619
write_callback );
@@ -1130,7 +1161,7 @@ SQLRETURN config_dbc(esodbc_dbc_st *dbc, esodbc_dsn_attrs_st *attrs)
1130
1161
const static wstr_st http_prefix = WSTR_INIT ("http://" );
1131
1162
const static wstr_st https_prefix = WSTR_INIT ("https://" );
1132
1163
wstr_st prefix ;
1133
- int cnt , ipv6 ;
1164
+ int cnt , ipv6 , n ;
1134
1165
SQLBIGINT secure , timeout , max_body_size , max_fetch_size , varchar_limit ;
1135
1166
SQLWCHAR buff_url [ESODBC_MAX_URL_LEN ];
1136
1167
wstr_st url = (wstr_st ) {
@@ -1191,7 +1222,7 @@ SQLRETURN config_dbc(esodbc_dbc_st *dbc, esodbc_dsn_attrs_st *attrs)
1191
1222
1192
1223
if (secure ) {
1193
1224
if (! wstr_to_utf8 (& attrs -> ca_path , & dbc -> ca_path )) {
1194
- ERRNH (dbc , "failed to convert CA path `" LWPDL "` to UTF8." ,
1225
+ ERRH (dbc , "failed to convert CA path `" LWPDL "` to UTF8." ,
1195
1226
LWSTR (& attrs -> ca_path ));
1196
1227
SET_HDIAG (dbc , SQL_STATE_HY000 , "reading the CA file path "
1197
1228
"failed" , 0 );
@@ -1222,7 +1253,7 @@ SQLRETURN config_dbc(esodbc_dbc_st *dbc, esodbc_dsn_attrs_st *attrs)
1222
1253
url .cnt = (size_t )cnt ;
1223
1254
}
1224
1255
if (! wstr_to_utf8 (& url , & dbc -> close_url )) {
1225
- ERRNH (dbc , "failed to convert URL `" LWPDL "` to UTF8." , LWSTR (& url ));
1256
+ ERRH (dbc , "failed to convert URL `" LWPDL "` to UTF8." , LWSTR (& url ));
1226
1257
SET_HDIAG (dbc , SQL_STATE_HY000 , "server SQL URL's UTF8 conversion "
1227
1258
"failed" , 0 );
1228
1259
goto err ;
@@ -1233,7 +1264,7 @@ SQLRETURN config_dbc(esodbc_dbc_st *dbc, esodbc_dsn_attrs_st *attrs)
1233
1264
* dup'ed since libcurl needs the 0 terminator */
1234
1265
url .cnt -= sizeof (ELASTIC_SQL_CLOSE_SUBPATH ) - /*\0*/ 1 ;
1235
1266
if (! wstr_to_utf8 (& url , & dbc -> url )) {
1236
- ERRNH (dbc , "failed to convert URL `" LWPDL "` to UTF8." , LWSTR (& url ));
1267
+ ERRH (dbc , "failed to convert URL `" LWPDL "` to UTF8." , LWSTR (& url ));
1237
1268
SET_HDIAG (dbc , SQL_STATE_HY000 , "server SQL URL's UTF8 conversion "
1238
1269
"failed" , 0 );
1239
1270
goto err ;
@@ -1258,7 +1289,7 @@ SQLRETURN config_dbc(esodbc_dbc_st *dbc, esodbc_dsn_attrs_st *attrs)
1258
1289
url .cnt = (size_t )cnt ;
1259
1290
}
1260
1291
if (! wstr_to_utf8 (& url , & dbc -> root_url )) {
1261
- ERRNH (dbc , "failed to convert URL `" LWPDL "` to UTF8." , LWSTR (& url ));
1292
+ ERRH (dbc , "failed to convert URL `" LWPDL "` to UTF8." , LWSTR (& url ));
1262
1293
SET_HDIAG (dbc , SQL_STATE_HY000 , "server root URL's UTF8 conversion "
1263
1294
"failed" , 0 );
1264
1295
goto err ;
@@ -1312,6 +1343,74 @@ SQLRETURN config_dbc(esodbc_dbc_st *dbc, esodbc_dsn_attrs_st *attrs)
1312
1343
dbc -> timeout = (SQLUINTEGER )timeout ;
1313
1344
INFOH (dbc , "timeout: %lu." , dbc -> timeout );
1314
1345
1346
+ /*
1347
+ * proxy settings
1348
+ */
1349
+ if (wstr2bool (& attrs -> proxy_enabled )) {
1350
+ ipv6 = wcsnstr (attrs -> proxy_host .str , attrs -> proxy_host .cnt , L':' ) !=
1351
+ NULL ;
1352
+ cnt = swprintf (url .str , sizeof (buff_url )/sizeof (* buff_url ),
1353
+ L"" WPFWP_LDESC "://" WPFCP_DESC WPFWP_LDESC WPFCP_DESC ,
1354
+ LWSTR (& attrs -> proxy_type ),
1355
+ ipv6 ? "[" : "" , LWSTR (& attrs -> proxy_host ), ipv6 ? "]" : "" );
1356
+ if (cnt > 0 && attrs -> proxy_port .cnt ) {
1357
+ n = swprintf (url .str + cnt ,
1358
+ sizeof (buff_url )/sizeof (* buff_url ) - cnt ,
1359
+ L":" WPFWP_LDESC , LWSTR (& attrs -> proxy_port ));
1360
+ } else {
1361
+ n = 0 ;
1362
+ }
1363
+ if (cnt <= 0 || n < 0 ) {
1364
+ ERRNH (dbc , "failed to print proxy URL out of type: `" LWPDL "`, "
1365
+ "host: `" LWPDL "` and port: `" LWPDL "`." ,
1366
+ LWSTR (& attrs -> proxy_type ), LWSTR (& attrs -> proxy_host ),
1367
+ LWSTR (& attrs -> proxy_port ));
1368
+ SET_HDIAG (dbc , SQL_STATE_HY000 , "printing proxy URL failed" , 0 );
1369
+ goto err ;
1370
+ } else {
1371
+ url .cnt = cnt + n ;
1372
+ }
1373
+ if (! wstr_to_utf8 (& url , & dbc -> proxy_url )) {
1374
+ ERRH (dbc , "failed to convert URL `" LWPDL "` to UTF8." ,
1375
+ LWSTR (& url ));
1376
+ SET_HDIAG (dbc , SQL_STATE_HY000 , "proxy URL's UTF8 conversion "
1377
+ "failed" , 0 );
1378
+ goto err ;
1379
+ }
1380
+ INFOH (dbc , "proxy URL: `%s`." , dbc -> proxy_url .str );
1381
+
1382
+ if (wstr2bool (& attrs -> proxy_auth_enabled )) {
1383
+ if (attrs -> proxy_auth_uid .cnt ) {
1384
+ if (! wstr_to_utf8 (& attrs -> proxy_auth_uid , & dbc -> proxy_uid )) {
1385
+ ERRH (dbc , "failed to convert proxy user ID `" LWPDL "` to"
1386
+ " UTF8." , LWSTR (& attrs -> proxy_auth_uid ));
1387
+ SET_HDIAG (dbc , SQL_STATE_HY000 , "proxy UID's UTF8 "
1388
+ "conversion failed" , 0 );
1389
+ goto err ;
1390
+ }
1391
+ INFOH (dbc , "proxy UID: `%s`." , dbc -> proxy_uid .str );
1392
+
1393
+ if (attrs -> proxy_auth_pwd .cnt ) {
1394
+ if (! wstr_to_utf8 (& attrs -> proxy_auth_pwd ,
1395
+ & dbc -> proxy_pwd )) {
1396
+ ERRH (dbc , "failed to convert proxy password [%zu] `%s`"
1397
+ " to UTF8" , attrs -> proxy_auth_pwd .cnt ,
1398
+ ESODBC_PWD_VAL_SUBST );
1399
+ SET_HDIAG (dbc , SQL_STATE_HY000 , "proxy password's "
1400
+ "UTF8 conversion failed" , 0 );
1401
+ goto err ;
1402
+ }
1403
+ /* indicates the presence of a non-empty password */
1404
+ INFOH (dbc , "proxy PWD: " ESODBC_PWD_VAL_SUBST "." );
1405
+ }
1406
+ }
1407
+ } else {
1408
+ INFOH (dbc , "proxy authentication disabled." );
1409
+ }
1410
+ } else {
1411
+ INFOH (dbc , "proxy disabled." );
1412
+ }
1413
+
1315
1414
/*
1316
1415
* set max body size
1317
1416
*/
@@ -1513,6 +1612,21 @@ void cleanup_dbc(esodbc_dbc_st *dbc)
1513
1612
} else {
1514
1613
assert (dbc -> pwd .cnt == 0 );
1515
1614
}
1615
+ if (dbc -> proxy_url .str ) {
1616
+ free (dbc -> proxy_url .str );
1617
+ dbc -> proxy_url .str = NULL ;
1618
+ dbc -> proxy_url .cnt = 0 ;
1619
+ }
1620
+ if (dbc -> proxy_uid .str ) {
1621
+ free (dbc -> proxy_uid .str );
1622
+ dbc -> proxy_uid .str = NULL ;
1623
+ dbc -> proxy_uid .cnt = 0 ;
1624
+ }
1625
+ if (dbc -> proxy_pwd .str ) {
1626
+ free (dbc -> proxy_pwd .str );
1627
+ dbc -> proxy_pwd .str = NULL ;
1628
+ dbc -> proxy_pwd .cnt = 0 ;
1629
+ }
1516
1630
if (dbc -> fetch .str ) {
1517
1631
free (dbc -> fetch .str );
1518
1632
dbc -> fetch .str = NULL ;
0 commit comments