Skip to content

Commit

Permalink
Merge branch 'KrzysztofCzajkaTURCOM-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
cyga committed Sep 5, 2017
2 parents 53d33cb + c8dcd76 commit 648e281
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -26,7 +26,7 @@ all: sql/$(EXTENSION)--$(EXTVERSION).sql
sql/$(EXTENSION)--$(EXTVERSION).sql: sql/$(EXTENSION).sql
cp $< $@

DATA = sql/$(EXTENSION)--$(EXTVERSION).sql
DATA = sql/$(EXTENSION)--*.sql
EXTRA_CLEAN = sql/$(EXTENSION)--$(EXTVERSION).sql
endif

Expand Down
2 changes: 2 additions & 0 deletions sql/www_fdw--0.1.8--0.1.9.sql
@@ -0,0 +1,2 @@
ALTER TYPE WWWFdwOptions ADD ATTRIBUTE username text;
ALTER TYPE WWWFdwOptions ADD ATTRIBUTE password text;
2 changes: 2 additions & 0 deletions sql/www_fdw--0.1.9--0.1.8.sql
@@ -0,0 +1,2 @@
ALTER TYPE WWWFdwOptions DROP ATTRIBUTE username ;
ALTER TYPE WWWFdwOptions DROP ATTRIBUTE password ;
43 changes: 23 additions & 20 deletions sql/www_fdw.sql
Expand Up @@ -2,28 +2,31 @@

-- type needed for callbacks
CREATE TYPE WWWFdwOptions AS (
uri text,
uri_select text,
uri_insert text,
uri_delete text,
uri_update text,
uri_callback text,
method_select text,
method_insert text,
method_delete text,
method_update text,
request_user_agent text,
request_serialize_callback text,
request_serialize_type text,
uri text,
uri_select text,
uri_insert text,
uri_delete text,
uri_update text,
uri_callback text,
method_select text,
method_insert text,
method_delete text,
method_update text,
request_user_agent text,
request_user_header text,
request_serialize_callback text,
request_serialize_type text,
request_serialize_human_readable text,
response_type text,
response_type text,
response_deserialize_callback text,
response_iterate_callback text,
ssl_cert text,
ssl_key text,
cainfo text,
proxy text,
cookie text
response_iterate_callback text,
ssl_cert text,
ssl_key text,
cainfo text,
proxy text,
cookie text,
username text,
password text
);
-- type needed for returning post options in serialize_request_callback
CREATE TYPE WWWFdwPostParameters AS (
Expand Down
30 changes: 28 additions & 2 deletions src/www_fdw.c 100644 → 100755
Expand Up @@ -80,7 +80,8 @@ static struct WWW_fdw_option valid_options[] =
{ "cainfo", ForeignServerRelationId },
{ "proxy", ForeignServerRelationId },
{ "cookie", ForeignServerRelationId },

{ "username", ForeignServerRelationId },
{ "password", ForeignServerRelationId },
/* Sentinel */
{ NULL, InvalidOid }
};
Expand Down Expand Up @@ -110,6 +111,8 @@ typedef struct WWW_fdw_options
char* cainfo;
char* proxy;
char* cookie;
char* username;
char* password;
} WWW_fdw_options;

typedef struct Reply
Expand Down Expand Up @@ -236,6 +239,8 @@ www_fdw_validator(PG_FUNCTION_ARGS)
char *cainfo = NULL;
char *proxy = NULL;
char *cookie = NULL;
char *username = NULL;
char *password = NULL;

d("www_fdw_validator routine");

Expand Down Expand Up @@ -322,6 +327,8 @@ www_fdw_validator(PG_FUNCTION_ARGS)
if(parse_parameter("cainfo", &cainfo, def)) continue;
if(parse_parameter("proxy", &proxy, def)) continue;
if(parse_parameter("cookie", &cookie, def)) continue;
if(parse_parameter("username", &username, def)) continue;
if(parse_parameter("password", &password, def)) continue;
}

PG_RETURN_VOID();
Expand Down Expand Up @@ -1418,7 +1425,9 @@ get_www_fdw_options(WWW_fdw_options *opts, Oid *opts_type, Datum *opts_value)
opts->ssl_key,
opts->cainfo,
opts->proxy,
opts->cookie
opts->cookie,
opts->username,
opts->password
};
TupleDesc tuple_desc;
AttInMetadata* aim;
Expand Down Expand Up @@ -1787,6 +1796,15 @@ www_begin(ForeignScanState *node, int eflags)
curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, url.data);
curl_easy_setopt(curl, CURLOPT_USERAGENT, opts->request_user_agent);
if ( opts->username )
{
curl_easy_setopt(curl, CURLOPT_USERNAME, opts->username );
}
if ( opts->password )
{
curl_easy_setopt(curl, CURLOPT_PASSWORD, opts->password );
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
}
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_error_buffer);

if(opts->request_user_header)
Expand Down Expand Up @@ -2231,6 +2249,8 @@ get_options(Oid foreigntableid, WWW_fdw_options *opts)
opts->cainfo = NULL;
opts->proxy = NULL;
opts->cookie = NULL;
opts->username = NULL;
opts->password = NULL;

/* Loop through the options, and get the server/port */
foreach(lc, options)
Expand Down Expand Up @@ -2302,6 +2322,12 @@ get_options(Oid foreigntableid, WWW_fdw_options *opts)

if (strcmp(def->defname, "cookie") == 0)
opts->cookie = defGetString(def);

if (strcmp(def->defname, "username") == 0)
opts->username = defGetString(def);

if (strcmp(def->defname, "password") == 0)
opts->password = defGetString(def);
}

/* Default values, if required */
Expand Down
2 changes: 1 addition & 1 deletion www_fdw.control
@@ -1,5 +1,5 @@
# www_fdw extension
comment = 'WWW FDW - extension for handling different web services'
default_version = '0.1.8'
default_version = '0.1.9'
module_pathname = '$libdir/www_fdw'
relocatable = true

0 comments on commit 648e281

Please sign in to comment.