@@ -77,6 +77,57 @@ static void ignore_sigpipe ()
7777 fprintf (stderr, gettext (" Failed to install SIGPIPE handler: %s\n " ), strerror (errno));
7878}
7979
80+ static long get_file_size (const char *filename)
81+ {
82+ FILE *fp;
83+
84+ fp = fopen (filename, " rb" );
85+ if (fp)
86+ {
87+ long size;
88+
89+ if ((0 != fseek (fp, 0 , SEEK_END)) || (-1 == (size = ftell (fp))))
90+ size = 0 ;
91+
92+ fclose (fp);
93+
94+ return size;
95+ }
96+ else
97+ return 0 ;
98+ }
99+
100+ static char * load_file (const char *filename)
101+ {
102+ FILE *fp;
103+ char *buffer;
104+ long size;
105+
106+ size = get_file_size (filename);
107+ if (size == 0 )
108+ return NULL ;
109+
110+ fp = fopen (filename, " rb" );
111+ if (!fp)
112+ return NULL ;
113+
114+ buffer = (char *) malloc (size);
115+ if (!buffer)
116+ {
117+ fclose (fp);
118+ return NULL ;
119+ }
120+
121+ if (size != (int ) fread (buffer, 1 , size, fp))
122+ {
123+ free (buffer);
124+ buffer = NULL ;
125+ }
126+
127+ fclose (fp);
128+ return buffer;
129+ }
130+
80131// LOGGING DELEGATE
81132LoggingDelegate::LoggingDelegate () {}
82133
@@ -100,6 +151,25 @@ Unescaper::~Unescaper() {}
100151
101152void Unescaper::unescape (char * s) const {}
102153
154+ // WEBSERVER CREATOR
155+ CreateWebserver& CreateWebserver::httpsMemKey (const std::string& httpsMemKey)
156+ {
157+ _httpsMemKey = load_file (httpsMemKey.c_str ());
158+ return *this ;
159+ }
160+
161+ CreateWebserver& CreateWebserver::httpsMemCert (const std::string& httpsMemCert)
162+ {
163+ _httpsMemCert = load_file (httpsMemCert.c_str ());
164+ return *this ;
165+ }
166+
167+ CreateWebserver& CreateWebserver::httpsMemTrust (const std::string& httpsMemTrust)
168+ {
169+ _httpsMemTrust = load_file (httpsMemTrust.c_str ());
170+ return *this ;
171+ }
172+
103173// WEBSERVER
104174Webserver::Webserver
105175(
@@ -245,14 +315,14 @@ bool Webserver::start(bool blocking)
245315 iov.push_back (gen (MHD_OPTION_THREAD_STACK_SIZE, maxThreadStackSize));
246316 if (nonceNcSize != 0 )
247317 iov.push_back (gen (MHD_OPTION_NONCE_NC_SIZE, nonceNcSize));
248- if (httpsMemKey != " " )
249- iov.push_back (gen (MHD_OPTION_HTTPS_MEM_KEY, ( intptr_t )httpsMemKey.c_str ()));
250- if (httpsMemCert != " " )
251- iov.push_back (gen (MHD_OPTION_HTTPS_MEM_CERT, ( intptr_t )httpsMemCert.c_str ()));
252- if (httpsMemTrust != " " )
253- iov.push_back (gen (MHD_OPTION_HTTPS_MEM_TRUST, ( intptr_t )httpsMemTrust.c_str ()));
254- if (httpsPriorities != " " )
255- iov.push_back (gen (MHD_OPTION_HTTPS_PRIORITIES, ( intptr_t )httpsPriorities.c_str ()));
318+ if (useSsl )
319+ iov.push_back (gen (MHD_OPTION_HTTPS_MEM_KEY, 0 , ( void * )httpsMemKey.c_str ()));
320+ if (useSsl )
321+ iov.push_back (gen (MHD_OPTION_HTTPS_MEM_CERT, 0 , ( void * )httpsMemCert.c_str ()));
322+ if (httpsMemTrust != " " && useSsl )
323+ iov.push_back (gen (MHD_OPTION_HTTPS_MEM_TRUST, 0 , ( void * )httpsMemTrust.c_str ()));
324+ if (httpsPriorities != " " && useSsl )
325+ iov.push_back (gen (MHD_OPTION_HTTPS_PRIORITIES, 0 , ( void * )httpsPriorities.c_str ()));
256326 if (digestAuthRandom != " " )
257327 iov.push_back (gen (MHD_OPTION_DIGEST_AUTH_RANDOM, digestAuthRandom.size (), (char *)digestAuthRandom.c_str ()));
258328 if (credType != HttpUtils::NONE)
0 commit comments