Skip to content
This repository has been archived by the owner on Mar 12, 2019. It is now read-only.

Commit

Permalink
Merge pull request #164 from versine/master
Browse files Browse the repository at this point in the history
Allow connection using hostname instead of ip
  • Loading branch information
jpmens authored Oct 12, 2016
2 parents 189fe5d + e249b1e commit c840e6d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions be-http.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,17 @@ static int http_post(void *handle, char *uri, const char *clientid, const char *

//_log(LOG_NOTICE, "u=%s p=%s t=%s acc=%d", username, password, topic, acc);

url = (char *)malloc(strlen(conf->ip) + strlen(uri) + 20);
url = (char *)malloc(strlen(conf->hostname) + strlen(uri) + 20);
if (url == NULL) {
_fatal("ENOMEM");
return (FALSE);
}

// enable the https
if (strcmp(conf->with_tls, "true") == 0){
sprintf(url, "https://%s:%d%s", conf->ip, conf->port, uri);
sprintf(url, "https://%s:%d%s", conf->hostname, conf->port, uri);
}else{
sprintf(url, "http://%s:%d%s", conf->ip, conf->port, uri);
sprintf(url, "http://%s:%d%s", conf->hostname, conf->port, uri);
}

char* escaped_username = curl_easy_escape(curl, username, 0);
Expand Down Expand Up @@ -223,7 +223,7 @@ static int http_post(void *handle, char *uri, const char *clientid, const char *
void *be_http_init()
{
struct http_backend *conf;
char *ip;
char *hostname;
char *getuser_uri;
char *superuser_uri;
char *aclcheck_uri;
Expand All @@ -233,8 +233,8 @@ void *be_http_init()
return (NULL);
}

if ((ip = p_stab("http_ip")) == NULL) {
_fatal("Mandatory parameter `http_ip' missing");
if ((hostname = p_stab("http_ip")) == NULL && (hostname = p_stab("http_hostname")) == NULL) {
_fatal("Mandatory parameter: one of either `http_ip' or `http_hostname' required");
return (NULL);
}
if ((getuser_uri = p_stab("http_getuser_uri")) == NULL) {
Expand All @@ -251,7 +251,7 @@ void *be_http_init()
}

conf = (struct http_backend *)malloc(sizeof(struct http_backend));
conf->ip = ip;
conf->hostname = hostname;
conf->port = p_stab("http_port") == NULL ? 80 : atoi(p_stab("http_port"));
if (p_stab("http_hostname") != NULL) {
conf->hostheader = (char *)malloc(128);
Expand Down
2 changes: 1 addition & 1 deletion be-http.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#define METHOD_ACLCHECK 3

struct http_backend {
char *ip;
char *hostname;
int port;
char *hostheader;
char *getuser_uri;
Expand Down

0 comments on commit c840e6d

Please sign in to comment.