mirror of https://github.com/adamdruppe/arsd.git
catching up (again)
This commit is contained in:
parent
48e3dc9ca7
commit
38c604356d
5
cgi.d
5
cgi.d
|
@ -477,7 +477,8 @@ class Cgi {
|
||||||
//if(authorization.length == 0) // if the std is there, use it
|
//if(authorization.length == 0) // if the std is there, use it
|
||||||
// authorization = getenv("HTTP_X_AUTHORIZATION");
|
// authorization = getenv("HTTP_X_AUTHORIZATION");
|
||||||
|
|
||||||
if(getenv("SERVER_PORT").length)
|
// the REDIRECT_HTTPS check is here because with an Apache hack, the port can become wrong
|
||||||
|
if(getenv("SERVER_PORT").length && getenv("REDIRECT_HTTPS") != "on")
|
||||||
port = to!int(getenv("SERVER_PORT"));
|
port = to!int(getenv("SERVER_PORT"));
|
||||||
else
|
else
|
||||||
port = 0; // this was probably called from the command line
|
port = 0; // this was probably called from the command line
|
||||||
|
@ -1360,7 +1361,7 @@ class Cgi {
|
||||||
return format("http%s://%s%s%s",
|
return format("http%s://%s%s%s",
|
||||||
https ? "s" : "",
|
https ? "s" : "",
|
||||||
host,
|
host,
|
||||||
port == defaultPort ? "" : ":" ~ to!string(port),
|
(!port || port == defaultPort) ? "" : ":" ~ to!string(port),
|
||||||
requestUri);
|
requestUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,19 @@ import std.string;
|
||||||
import std.array;
|
import std.array;
|
||||||
import std.conv;
|
import std.conv;
|
||||||
|
|
||||||
|
/// Like convertToUtf8, but if the encoding is unknown, it just strips all chars > 127 and calls it done instead of throwing
|
||||||
|
string convertToUtf8Lossy(immutable(ubyte)[] data, string dataCharacterEncoding) {
|
||||||
|
try {
|
||||||
|
return convertToUtf8(data, dataCharacterEncoding);
|
||||||
|
} catch(Exception e) {
|
||||||
|
string ret;
|
||||||
|
foreach(b; data)
|
||||||
|
if(b < 128)
|
||||||
|
ret ~= b;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Takes data from a given character encoding and returns it as UTF-8
|
/// Takes data from a given character encoding and returns it as UTF-8
|
||||||
string convertToUtf8(immutable(ubyte)[] data, string dataCharacterEncoding) {
|
string convertToUtf8(immutable(ubyte)[] data, string dataCharacterEncoding) {
|
||||||
// just to normalize the passed string...
|
// just to normalize the passed string...
|
||||||
|
|
16
database.d
16
database.d
|
@ -473,7 +473,10 @@ int updateOrInsert(Database db, string table, string[string] values, string wher
|
||||||
|
|
||||||
//cs ~= "`" ~ db.escape(column) ~ "`";
|
//cs ~= "`" ~ db.escape(column) ~ "`";
|
||||||
cs ~= "`" ~ column ~ "`"; // FIXME: possible insecure
|
cs ~= "`" ~ column ~ "`"; // FIXME: possible insecure
|
||||||
vs ~= "'" ~ db.escape(value) ~ "'";
|
if(value is null)
|
||||||
|
vs ~= "NULL";
|
||||||
|
else
|
||||||
|
vs ~= "'" ~ db.escape(value) ~ "'";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!outputted)
|
if(!outputted)
|
||||||
|
@ -499,7 +502,10 @@ int updateOrInsert(Database db, string table, string[string] values, string wher
|
||||||
else
|
else
|
||||||
outputted = true;
|
outputted = true;
|
||||||
|
|
||||||
updateSql ~= "`" ~ db.escape(column) ~ "` = '" ~ db.escape(value) ~ "'";
|
if(value is null)
|
||||||
|
updateSql ~= "`" ~ db.escape(column) ~ "` = NULL";
|
||||||
|
else
|
||||||
|
updateSql ~= "`" ~ db.escape(column) ~ "` = '" ~ db.escape(value) ~ "'";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!outputted)
|
if(!outputted)
|
||||||
|
@ -813,7 +819,11 @@ class DataObject {
|
||||||
if(where.length)
|
if(where.length)
|
||||||
where ~= " AND ";
|
where ~= " AND ";
|
||||||
|
|
||||||
where ~= keyField ~ " = '"~db.escape(key in fields ? fields[key] : null)~"'" ;
|
auto f = key in fields ? fields[key] : null;
|
||||||
|
if(f is null)
|
||||||
|
where ~= keyField ~ " = NULL";
|
||||||
|
else
|
||||||
|
where ~= keyField ~ " = '"~db.escape(f)~"'" ;
|
||||||
if(keyFieldToPass.length)
|
if(keyFieldToPass.length)
|
||||||
keyFieldToPass ~= ", ";
|
keyFieldToPass ~= ", ";
|
||||||
|
|
||||||
|
|
16
oauth.d
16
oauth.d
|
@ -288,7 +288,7 @@ import std.file;
|
||||||
/**
|
/**
|
||||||
Redirects the user to the authorize page on the provider's website.
|
Redirects the user to the authorize page on the provider's website.
|
||||||
*/
|
*/
|
||||||
void authorizeStepOne(Cgi cgi, OAuthParams params, string oauthCallback = null) {
|
void authorizeStepOne(Cgi cgi, OAuthParams params, string oauthCallback = null, string additionalOptions = null, string[string] additionalTokenArgs = null) {
|
||||||
if(oauthCallback is null) {
|
if(oauthCallback is null) {
|
||||||
oauthCallback = cgi.getCurrentCompleteUri();
|
oauthCallback = cgi.getCurrentCompleteUri();
|
||||||
if(oauthCallback.indexOf("?") == -1)
|
if(oauthCallback.indexOf("?") == -1)
|
||||||
|
@ -301,7 +301,13 @@ void authorizeStepOne(Cgi cgi, OAuthParams params, string oauthCallback = null)
|
||||||
if(oauthCallback.length)
|
if(oauthCallback.length)
|
||||||
args["oauth_callback"] = oauthCallback;
|
args["oauth_callback"] = oauthCallback;
|
||||||
|
|
||||||
auto ret = curlOAuth(params, params.baseUrl ~ params.requestTokenPath,
|
//foreach(k, v; additionalTokenArgs)
|
||||||
|
//args[k] = v;
|
||||||
|
|
||||||
|
auto moreArgs = encodeVariables(additionalTokenArgs);
|
||||||
|
if(moreArgs.length)
|
||||||
|
moreArgs = "?" ~ moreArgs;
|
||||||
|
auto ret = curlOAuth(params, params.baseUrl ~ params.requestTokenPath ~ moreArgs,
|
||||||
args, "POST", "", "");
|
args, "POST", "", "");
|
||||||
auto vals = decodeVariables(ret);
|
auto vals = decodeVariables(ret);
|
||||||
|
|
||||||
|
@ -320,7 +326,11 @@ void authorizeStepOne(Cgi cgi, OAuthParams params, string oauthCallback = null)
|
||||||
std.file.write("/tmp/oauth-token-secret-" ~ oauth_token,
|
std.file.write("/tmp/oauth-token-secret-" ~ oauth_token,
|
||||||
oauth_secret);
|
oauth_secret);
|
||||||
|
|
||||||
cgi.setResponseLocation(params.baseUrl ~ params.authorizePath ~ "?oauth_token=" ~ oauth_token);
|
// FIXME: make sure this doesn't break twitter etc
|
||||||
|
if("login_url" in vals) // apparently etsy does it this way...
|
||||||
|
cgi.setResponseLocation(vals["login_url"][0]);
|
||||||
|
else
|
||||||
|
cgi.setResponseLocation(params.baseUrl ~ params.authorizePath ~ "?" ~(additionalOptions.length ? (additionalOptions ~ "&") : "")~ "oauth_token=" ~ oauth_token);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
8
web.d
8
web.d
|
@ -1,5 +1,7 @@
|
||||||
module arsd.web;
|
module arsd.web;
|
||||||
|
|
||||||
|
// it would be nice to be able to add meta info to a returned envelope
|
||||||
|
|
||||||
enum RequirePost;
|
enum RequirePost;
|
||||||
enum RequireHttps;
|
enum RequireHttps;
|
||||||
enum NoAutomaticForm;
|
enum NoAutomaticForm;
|
||||||
|
@ -3140,6 +3142,12 @@ class Session {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void removeKey(string key) {
|
||||||
|
data.remove(key);
|
||||||
|
_hasData = true;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
/// get/set for strings
|
/// get/set for strings
|
||||||
@property string opDispatch(string name)(string v = null) if(name != "popFront") {
|
@property string opDispatch(string name)(string v = null) if(name != "popFront") {
|
||||||
if(v !is null)
|
if(v !is null)
|
||||||
|
|
Loading…
Reference in New Issue