mirror of
https://github.com/falk-werner/webfuse-provider
synced 2026-03-02 04:09:18 +00:00
moved wf_url to core
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
#include "webfuse/core/message.h"
|
||||
#include "webfuse/core/message_queue.h"
|
||||
#include "webfuse/core/container_of.h"
|
||||
#include "webfuse/provider/impl/url.h"
|
||||
#include "webfuse/core/url.h"
|
||||
#include "webfuse/core/protocol_names.h"
|
||||
|
||||
#include "webfuse/core/timer/manager.h"
|
||||
@@ -297,8 +297,8 @@ void wfp_impl_client_protocol_connect(
|
||||
struct lws_context * context,
|
||||
char const * url)
|
||||
{
|
||||
struct wfp_impl_url url_data;
|
||||
bool const success = wfp_impl_url_init(&url_data, url);
|
||||
struct wf_url url_data;
|
||||
bool const success = wf_url_init(&url_data, url);
|
||||
if (success)
|
||||
{
|
||||
struct lws_client_connect_info info;
|
||||
@@ -316,7 +316,7 @@ void wfp_impl_client_protocol_connect(
|
||||
|
||||
lws_client_connect_via_info(&info);
|
||||
|
||||
wfp_impl_url_cleanup(&url_data);
|
||||
wf_url_cleanup(&url_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -1,125 +0,0 @@
|
||||
#include "webfuse/provider/impl/url.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct wfp_impl_url_protocol
|
||||
{
|
||||
char const * name;
|
||||
size_t name_length;
|
||||
int default_port;
|
||||
bool use_tls;
|
||||
};
|
||||
|
||||
static bool wfp_impl_url_readprotocol(
|
||||
struct wfp_impl_url * url,
|
||||
char const * * data)
|
||||
{
|
||||
static struct wfp_impl_url_protocol const known_protocols[] =
|
||||
{
|
||||
{"ws://", 5, 80, false},
|
||||
{"wss://", 6, 443, true}
|
||||
};
|
||||
static size_t const count = (sizeof(known_protocols) / sizeof(known_protocols[0]));
|
||||
|
||||
bool found = false;
|
||||
for(size_t i = 0; (!found) && (i < count); i++)
|
||||
{
|
||||
struct wfp_impl_url_protocol const * protocol = &known_protocols[i];
|
||||
if (0 == strncmp(*data, protocol->name, protocol->name_length))
|
||||
{
|
||||
url->port = protocol->default_port;
|
||||
url->use_tls = protocol->use_tls;
|
||||
*data = *data + protocol->name_length;
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
static bool wfp_impl_url_readhost(
|
||||
struct wfp_impl_url * url,
|
||||
char const * * data)
|
||||
{
|
||||
char * end = strpbrk(*data, ":/");
|
||||
bool const result = (NULL != end);
|
||||
|
||||
if (result)
|
||||
{
|
||||
size_t length = end - *data;
|
||||
url->host = strndup(*data, length);
|
||||
*data = end;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool wfp_impl_url_readport(
|
||||
struct wfp_impl_url * url,
|
||||
char const * * data)
|
||||
{
|
||||
bool result;
|
||||
|
||||
if (':' == **data)
|
||||
{
|
||||
*data = *data + 1;
|
||||
char * end = strchr(*data, '/');
|
||||
result = (NULL != end);
|
||||
|
||||
if (result)
|
||||
{
|
||||
url->port = atoi(*data);
|
||||
*data = end;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = ('/' == **data);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool wfp_impl_url_readpath(
|
||||
struct wfp_impl_url * url,
|
||||
char const * * data)
|
||||
{
|
||||
bool const result = ('/' == **data);
|
||||
url->path = strdup(*data);
|
||||
*data = NULL;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
bool wfp_impl_url_init(
|
||||
struct wfp_impl_url * url,
|
||||
char const * value)
|
||||
{
|
||||
memset(url, 0, sizeof(struct wfp_impl_url));
|
||||
char const * data = value;
|
||||
|
||||
bool const result =
|
||||
wfp_impl_url_readprotocol(url, &data) &&
|
||||
wfp_impl_url_readhost(url, &data) &&
|
||||
wfp_impl_url_readport(url, &data) &&
|
||||
wfp_impl_url_readpath(url, &data)
|
||||
;
|
||||
|
||||
if (!result)
|
||||
{
|
||||
wfp_impl_url_cleanup(url);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void wfp_impl_url_cleanup(
|
||||
struct wfp_impl_url * url)
|
||||
{
|
||||
free(url->host);
|
||||
free(url->path);
|
||||
memset(url, 0, sizeof(struct wfp_impl_url));
|
||||
}
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
#ifndef WF_PROVIDER_IMPL_URL_H
|
||||
#define WF_PROVIDER_IMPL_URL_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
struct wfp_impl_url
|
||||
{
|
||||
char * host;
|
||||
int port;
|
||||
char * path;
|
||||
bool use_tls;
|
||||
};
|
||||
|
||||
extern bool wfp_impl_url_init(
|
||||
struct wfp_impl_url * url,
|
||||
char const * value);
|
||||
|
||||
extern void wfp_impl_url_cleanup(
|
||||
struct wfp_impl_url * url);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user