[Commits] 29a6121: Add an option to specify port number

Sergei Petrunia psergey at askmonty.org
Sat Sep 5 20:05:44 EEST 2020


revision-id: 29a6121396da9fc73e3deee7695f7cb95f7121fe (libmarias3-3.1.2-3-g29a6121)
parent(s): d172e86c16224b4e0229ca6f102e662a2315aeff
author: Sergei Petrunia
committer: Sergei Petrunia
timestamp: 2020-09-05 20:05:44 +0300
message:

Add an option to specify port number

---
 libmarias3/marias3.h |  3 ++-
 src/marias3.c        | 14 ++++++++++++++
 src/request.c        |  3 +++
 src/structs.h        |  1 +
 4 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/libmarias3/marias3.h b/libmarias3/marias3.h
index abe255b..a6f2bf3 100644
--- a/libmarias3/marias3.h
+++ b/libmarias3/marias3.h
@@ -80,7 +80,8 @@ enum ms3_set_option_t
   MS3_OPT_DISABLE_SSL_VERIFY,
   MS3_OPT_BUFFER_CHUNK_SIZE,
   MS3_OPT_FORCE_LIST_VERSION,
-  MS3_OPT_FORCE_PROTOCOL_VERSION
+  MS3_OPT_FORCE_PROTOCOL_VERSION,
+  MS3_OPT_PORT_NUMBER
 };
 
 typedef enum ms3_set_option_t ms3_set_option_t;
diff --git a/src/marias3.c b/src/marias3.c
index 581b181..cebcbb0 100644
--- a/src/marias3.c
+++ b/src/marias3.c
@@ -166,6 +166,7 @@ ms3_st *ms3_init(const char *s3key, const char *s3secret,
   ms3->s3key = ms3_cstrdup(s3key);
   ms3->s3secret = ms3_cstrdup(s3secret);
   ms3->region = ms3_cstrdup(region);
+  ms3->port = 0; /* The default value */
 
   if (base_domain && strlen(base_domain))
   {
@@ -534,6 +535,19 @@ uint8_t ms3_set_option(ms3_st *ms3, ms3_set_option_t option, void *value)
       break;
     }
 
+    case MS3_OPT_PORT_NUMBER:
+    {
+      int port_number;
+
+      if (!value)
+      {
+        return MS3_ERR_PARAMETER;
+      }
+      memcpy(&port_number, (void*)value, sizeof(int));
+
+      ms3->port = port_number;
+      break;
+    }
     default:
       return MS3_ERR_PARAMETER;
   }
diff --git a/src/request.c b/src/request.c
index 425367b..80a32d0 100644
--- a/src/request.c
+++ b/src/request.c
@@ -775,6 +775,9 @@ uint8_t execute_request(ms3_st *ms3, command_t cmd, const char *bucket,
     curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
   }
 
+  if (ms3->port)
+    curl_easy_setopt(curl, CURLOPT_PORT, (long)ms3->port);
+
   curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, header_callback);
   curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, body_callback);
   curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&mem);
diff --git a/src/structs.h b/src/structs.h
index 8d30a57..de80b53 100644
--- a/src/structs.h
+++ b/src/structs.h
@@ -42,6 +42,7 @@ struct ms3_st
   char *s3secret;
   char *region;
   char *base_domain;
+  int port; // 0 means "Use default"
   size_t buffer_chunk_size;
   CURL *curl;
   char *last_error;


More information about the commits mailing list