mirror of
git://git.psyced.org/git/psyced
synced 2024-08-15 03:25:10 +00:00
no stream object necessary
This commit is contained in:
commit
bc54f4b3c2
5 changed files with 34 additions and 14 deletions
|
@ -30,6 +30,7 @@ volatile string http_message;
|
||||||
volatile int http_status, port, fetching, ssl;
|
volatile int http_status, port, fetching, ssl;
|
||||||
volatile string buffer, thehost, url, fetched, host, resource, method;
|
volatile string buffer, thehost, url, fetched, host, resource, method;
|
||||||
volatile mixed rbody;
|
volatile mixed rbody;
|
||||||
|
volatile int stream;
|
||||||
|
|
||||||
int parse_status(string all);
|
int parse_status(string all);
|
||||||
int parse_header(string all);
|
int parse_header(string all);
|
||||||
|
@ -37,9 +38,10 @@ int buffer_content(string all);
|
||||||
|
|
||||||
string qHost() { return thehost; }
|
string qHost() { return thehost; }
|
||||||
|
|
||||||
varargs void fetch(string murl, string meth, mixed body, mapping hdrs) {
|
varargs void fetch(string murl, string meth, mixed body, mapping hdrs, int strm) {
|
||||||
method = meth || "GET";
|
method = meth || "GET";
|
||||||
rbody = body;
|
rbody = body;
|
||||||
|
stream = strm;
|
||||||
if (hdrs) rheaders += hdrs;
|
if (hdrs) rheaders += hdrs;
|
||||||
if (url != murl) {
|
if (url != murl) {
|
||||||
// accept.c does this for us:
|
// accept.c does this for us:
|
||||||
|
@ -183,9 +185,16 @@ int parse_header(string all) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int buffer_content(string all) {
|
int buffer_content(string data) {
|
||||||
P2(("%O body %O\n", ME, all))
|
P2(("%O body %O\n", ME, data))
|
||||||
buffer += all + "\n";
|
if (stream) {
|
||||||
|
mixed *waiter;
|
||||||
|
foreach (waiter : qToArray(ME)) {
|
||||||
|
funcall(waiter[0], data, waiter[1] ? fheaders : copy(fheaders), http_status, 1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
buffer += data + "\n";
|
||||||
|
}
|
||||||
next_input_to(#'buffer_content);
|
next_input_to(#'buffer_content);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -198,8 +207,12 @@ disconnected(remainder) {
|
||||||
//if (headers["etag"])
|
//if (headers["etag"])
|
||||||
// rheaders["if-none-match"] = headers["etag"]; // heise does not work with etag
|
// rheaders["if-none-match"] = headers["etag"]; // heise does not work with etag
|
||||||
|
|
||||||
fetched = buffer;
|
if (stream) {
|
||||||
if (remainder) fetched += remainder;
|
fetched = remainder;
|
||||||
|
} else {
|
||||||
|
fetched = buffer;
|
||||||
|
if (remainder) fetched += remainder;
|
||||||
|
}
|
||||||
fheaders = headers;
|
fheaders = headers;
|
||||||
buffer = headers = 0;
|
buffer = headers = 0;
|
||||||
switch (http_status) {
|
switch (http_status) {
|
||||||
|
|
|
@ -25,7 +25,7 @@ volatile int authorized = 0;
|
||||||
oauth_success() {}
|
oauth_success() {}
|
||||||
oauth_error() {}
|
oauth_error() {}
|
||||||
|
|
||||||
varargs void fetch(object ua, string url, string method, mapping post, mapping oauth) {
|
varargs void fetch(object ua, string url, string method, mapping post, mapping oauth, int stream) {
|
||||||
P3((">> oauth:fetch(%O, %O, %O)\n", url, method, oauth))
|
P3((">> oauth:fetch(%O, %O, %O)\n", url, method, oauth))
|
||||||
unless (method) method = "GET";
|
unless (method) method = "GET";
|
||||||
unless (post) post = ([]);
|
unless (post) post = ([]);
|
||||||
|
@ -53,7 +53,7 @@ varargs void fetch(object ua, string url, string method, mapping post, mapping o
|
||||||
foreach (string key, string value : oauth)
|
foreach (string key, string value : oauth)
|
||||||
p += (strlen(p) ? "," : "") + key + "=\"" + urlencode(to_string(value)) + "\"";
|
p += (strlen(p) ? "," : "") + key + "=\"" + urlencode(to_string(value)) + "\"";
|
||||||
|
|
||||||
ua->fetch(url, method, post, (["authorization": "OAuth " + p]));
|
ua->fetch(url, method, post, (["authorization": "OAuth " + p]), stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
void parse_request_token(string body, mapping headers, int http_status) {
|
void parse_request_token(string body, mapping headers, int http_status) {
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
inherit NET_PATH "twitter/client";
|
inherit NET_PATH "twitter/client";
|
||||||
|
|
||||||
object load(object usr, string key, string secret, string request, string access, string authorize) {
|
object load(object usr, mapping opts) {
|
||||||
name = "identica";
|
name = "identica";
|
||||||
display_name = "identi.ca";
|
display_name = "identi.ca";
|
||||||
api_base_url = "http://identi.ca/api";
|
api_base_url = "http://identi.ca/api";
|
||||||
|
@ -20,5 +20,5 @@ object load(object usr, string key, string secret, string request, string access
|
||||||
access_token_url = api_base_url + "/oauth/access_token";
|
access_token_url = api_base_url + "/oauth/access_token";
|
||||||
authorize_url = api_base_url + "/oauth/authorize";
|
authorize_url = api_base_url + "/oauth/authorize";
|
||||||
|
|
||||||
return ::load(usr, key, secret, request, access, authorize);
|
return ::load(usr, opts);
|
||||||
}
|
}
|
||||||
|
|
|
@ -763,7 +763,12 @@ checkPassword(try, method, salt, args, cb, varargs cbargs) {
|
||||||
if (IS_NEWBIE) ARETURN(1) // could auto-register here..
|
if (IS_NEWBIE) ARETURN(1) // could auto-register here..
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
if (!try || try == "" || (method != "hmac-sha1-shared") && v("password") == "") ARETURN(0)
|
if (!try || try == "" || (
|
||||||
|
#ifdef AUTH_HMAC_SECRET
|
||||||
|
// tg's website integration use case
|
||||||
|
method != "hmac-sha1-shared" &&
|
||||||
|
#endif
|
||||||
|
v("password") == "")) ARETURN(0)
|
||||||
|
|
||||||
switch(method) {
|
switch(method) {
|
||||||
#if __EFUN_DEFINED__(sha1)
|
#if __EFUN_DEFINED__(sha1)
|
||||||
|
|
|
@ -28,6 +28,8 @@ persistent mixed lastid;
|
||||||
|
|
||||||
volatile string api_url = "https://api.twitter.com/1";
|
volatile string api_url = "https://api.twitter.com/1";
|
||||||
volatile string userstream_url = "https://userstream.twitter.com/2";
|
volatile string userstream_url = "https://userstream.twitter.com/2";
|
||||||
|
volatile string name = "twitter";
|
||||||
|
volatile string display_name = "twitter";
|
||||||
|
|
||||||
volatile int status_max_len = 140;
|
volatile int status_max_len = 140;
|
||||||
volatile int send_to_user = 0;
|
volatile int send_to_user = 0;
|
||||||
|
@ -72,7 +74,7 @@ object load(object usr, mapping opts) {
|
||||||
void check_status_update(string body, string headers, int http_status) {
|
void check_status_update(string body, string headers, int http_status) {
|
||||||
P3(("twitter/client:parse_status_update(%O, %O, %O)\n", body, headers, http_status))
|
P3(("twitter/client:parse_status_update(%O, %O, %O)\n", body, headers, http_status))
|
||||||
if (http_status != R_OK)
|
if (http_status != R_OK)
|
||||||
sendmsg(user, "_failure_update_twitter", "Unable to post status update on twitter.");
|
sendmsg(user, "_failure_update_"+ name, "Unable to post status update on [_name].", (["_name": display_name]));
|
||||||
}
|
}
|
||||||
|
|
||||||
void status_update(string text) {
|
void status_update(string text) {
|
||||||
|
@ -249,9 +251,9 @@ user_stream() {
|
||||||
P3(("twitter/client:user_stream()\n"))
|
P3(("twitter/client:user_stream()\n"))
|
||||||
if (!authorized) return enqueue(ME, ({ #'user_stream })); //'}));
|
if (!authorized) return enqueue(ME, ({ #'user_stream })); //'}));
|
||||||
friends = 0;
|
friends = 0;
|
||||||
object user_ua = clone_object(NET_PATH "http/stream");
|
object user_ua = clone_object(NET_PATH "http/fetch");
|
||||||
user_ua->content(#'user_stream_data, 1, 1); //');
|
user_ua->content(#'user_stream_data, 1, 1); //');
|
||||||
fetch(user_ua, userstream_url + "/user.json");
|
fetch(user_ua, userstream_url + "/user.json", "GET", 0, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
oauth_success() {
|
oauth_success() {
|
||||||
|
|
Loading…
Reference in a new issue