mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-09 19:50:26 +03:00
Some tweaks to previous patch.
This commit is contained in:
parent
100c9cf569
commit
26840e0dc0
@ -1277,7 +1277,7 @@ xs_dict *msg_actor(snac *snac)
|
|||||||
xs *k2 = encode_html(k);
|
xs *k2 = encode_html(k);
|
||||||
xs *v2 = NULL;
|
xs *v2 = NULL;
|
||||||
|
|
||||||
if (xs_startswith(v, "http")) {
|
if (xs_startswith(v, "https:/") || xs_startswith(v, "http:/")) {
|
||||||
xs *t = encode_html(v);
|
xs *t = encode_html(v);
|
||||||
v2 = xs_fmt("<a href=\"%s\" rel=\"me\">%s</a>", t, t);
|
v2 = xs_fmt("<a href=\"%s\" rel=\"me\">%s</a>", t, t);
|
||||||
}
|
}
|
||||||
@ -1369,7 +1369,7 @@ xs_dict *msg_follow(snac *snac, const char *q)
|
|||||||
|
|
||||||
xs *url_or_uid = xs_strip_i(xs_str_new(q));
|
xs *url_or_uid = xs_strip_i(xs_str_new(q));
|
||||||
|
|
||||||
if (xs_startswith(url_or_uid, "http"))
|
if (xs_startswith(url_or_uid, "https:/") || xs_startswith(url_or_uid, "http:/"))
|
||||||
actor = xs_dup(url_or_uid);
|
actor = xs_dup(url_or_uid);
|
||||||
else
|
else
|
||||||
if (!valid_status(webfinger_request(url_or_uid, &actor, NULL)) || actor == NULL) {
|
if (!valid_status(webfinger_request(url_or_uid, &actor, NULL)) || actor == NULL) {
|
||||||
|
6
data.c
6
data.c
@ -60,15 +60,17 @@ int srv_open(char *basedir, int auto_upgrade)
|
|||||||
char *host;
|
char *host;
|
||||||
char *prefix;
|
char *prefix;
|
||||||
char *dbglvl;
|
char *dbglvl;
|
||||||
|
char *proto;
|
||||||
|
|
||||||
host = xs_dict_get(srv_config, "host");
|
host = xs_dict_get(srv_config, "host");
|
||||||
prefix = xs_dict_get(srv_config, "prefix");
|
prefix = xs_dict_get(srv_config, "prefix");
|
||||||
dbglvl = xs_dict_get(srv_config, "dbglevel");
|
dbglvl = xs_dict_get(srv_config, "dbglevel");
|
||||||
|
proto = xs_dict_get_def(srv_config, "protocol", "https");
|
||||||
|
|
||||||
if (host == NULL || prefix == NULL)
|
if (host == NULL || prefix == NULL)
|
||||||
error = xs_str_new("ERROR: cannot get server data");
|
error = xs_str_new("ERROR: cannot get server data");
|
||||||
else {
|
else {
|
||||||
srv_baseurl = xs_fmt("http://%s%s", host, prefix);
|
srv_baseurl = xs_fmt("%s:/" "/%s%s", proto, host, prefix);
|
||||||
|
|
||||||
dbglevel = (int) xs_number_get(dbglvl);
|
dbglevel = (int) xs_number_get(dbglvl);
|
||||||
|
|
||||||
@ -1990,7 +1992,7 @@ xs_list *inbox_list(void)
|
|||||||
|
|
||||||
xs_str *_instance_block_fn(const char *instance)
|
xs_str *_instance_block_fn(const char *instance)
|
||||||
{
|
{
|
||||||
xs *s = xs_replace(instance, "http:/" "/", "");
|
xs *s = xs_replace(instance, "http:/" "/", "");
|
||||||
xs *s1 = xs_replace(s, "https:/" "/", "");
|
xs *s1 = xs_replace(s, "https:/" "/", "");
|
||||||
xs *l = xs_split(s1, "/");
|
xs *l = xs_split(s1, "/");
|
||||||
char *p = xs_list_get(l, 0);
|
char *p = xs_list_get(l, 0);
|
||||||
|
2
html.c
2
html.c
@ -813,7 +813,7 @@ static xs_html *html_user_body(snac *user, int read_only)
|
|||||||
while (xs_dict_next(metadata, &k, &v, &c)) {
|
while (xs_dict_next(metadata, &k, &v, &c)) {
|
||||||
xs_html *value;
|
xs_html *value;
|
||||||
|
|
||||||
if (xs_startswith(v, "http")) {
|
if (xs_startswith(v, "https:/") || xs_startswith(v, "http:/")) {
|
||||||
/* is this link validated? */
|
/* is this link validated? */
|
||||||
xs *verified_link = NULL;
|
xs *verified_link = NULL;
|
||||||
xs_number *val_time = xs_dict_get(val_links, v);
|
xs_number *val_time = xs_dict_get(val_links, v);
|
||||||
|
20
mastoapi.c
20
mastoapi.c
@ -156,7 +156,7 @@ const char *login_page = ""
|
|||||||
"</head>\n"
|
"</head>\n"
|
||||||
"<body><h1>%s OAuth identify</h1>\n"
|
"<body><h1>%s OAuth identify</h1>\n"
|
||||||
"<div style=\"background-color: red; color: white\">%s</div>\n"
|
"<div style=\"background-color: red; color: white\">%s</div>\n"
|
||||||
"<form method=\"post\" action=\"http:/" "/%s/%s\">\n"
|
"<form method=\"post\" action=\"%s:/" "/%s/%s\">\n"
|
||||||
"<p>Login: <input type=\"text\" name=\"login\"></p>\n"
|
"<p>Login: <input type=\"text\" name=\"login\"></p>\n"
|
||||||
"<p>Password: <input type=\"password\" name=\"passwd\"></p>\n"
|
"<p>Password: <input type=\"password\" name=\"passwd\"></p>\n"
|
||||||
"<input type=\"hidden\" name=\"redir\" value=\"%s\">\n"
|
"<input type=\"hidden\" name=\"redir\" value=\"%s\">\n"
|
||||||
@ -193,11 +193,12 @@ int oauth_get_handler(const xs_dict *req, const char *q_path,
|
|||||||
|
|
||||||
if (app != NULL) {
|
if (app != NULL) {
|
||||||
const char *host = xs_dict_get(srv_config, "host");
|
const char *host = xs_dict_get(srv_config, "host");
|
||||||
|
const char *proto = xs_dict_get_def(srv_config, "protocol", "https");
|
||||||
|
|
||||||
if (xs_is_null(state))
|
if (xs_is_null(state))
|
||||||
state = "";
|
state = "";
|
||||||
|
|
||||||
*body = xs_fmt(login_page, host, host, "", host, "oauth/x-snac-login",
|
*body = xs_fmt(login_page, host, host, "", proto, host, "oauth/x-snac-login",
|
||||||
ruri, cid, state, USER_AGENT);
|
ruri, cid, state, USER_AGENT);
|
||||||
*ctype = "text/html";
|
*ctype = "text/html";
|
||||||
status = 200;
|
status = 200;
|
||||||
@ -213,8 +214,9 @@ int oauth_get_handler(const xs_dict *req, const char *q_path,
|
|||||||
else
|
else
|
||||||
if (strcmp(cmd, "/x-snac-get-token") == 0) { /** **/
|
if (strcmp(cmd, "/x-snac-get-token") == 0) { /** **/
|
||||||
const char *host = xs_dict_get(srv_config, "host");
|
const char *host = xs_dict_get(srv_config, "host");
|
||||||
|
const char *proto = xs_dict_get_def(srv_config, "protocol", "https");
|
||||||
|
|
||||||
*body = xs_fmt(login_page, host, host, "", host, "oauth/x-snac-get-token",
|
*body = xs_fmt(login_page, host, host, "", proto, host, "oauth/x-snac-get-token",
|
||||||
"", "", "", USER_AGENT);
|
"", "", "", USER_AGENT);
|
||||||
*ctype = "text/html";
|
*ctype = "text/html";
|
||||||
status = 200;
|
status = 200;
|
||||||
@ -265,11 +267,11 @@ int oauth_post_handler(const xs_dict *req, const char *q_path,
|
|||||||
const char *redir = xs_dict_get(args, "redir");
|
const char *redir = xs_dict_get(args, "redir");
|
||||||
const char *cid = xs_dict_get(args, "cid");
|
const char *cid = xs_dict_get(args, "cid");
|
||||||
const char *state = xs_dict_get(args, "state");
|
const char *state = xs_dict_get(args, "state");
|
||||||
|
const char *host = xs_dict_get(srv_config, "host");
|
||||||
const char *host = xs_dict_get(srv_config, "host");
|
const char *proto = xs_dict_get_def(srv_config, "protocol", "https");
|
||||||
|
|
||||||
/* by default, generate another login form with an error */
|
/* by default, generate another login form with an error */
|
||||||
*body = xs_fmt(login_page, host, host, "LOGIN INCORRECT", host, "oauth/x-snac-login",
|
*body = xs_fmt(login_page, host, host, "LOGIN INCORRECT", proto, host, "oauth/x-snac-login",
|
||||||
redir, cid, state, USER_AGENT);
|
redir, cid, state, USER_AGENT);
|
||||||
*ctype = "text/html";
|
*ctype = "text/html";
|
||||||
status = 200;
|
status = 200;
|
||||||
@ -450,11 +452,11 @@ int oauth_post_handler(const xs_dict *req, const char *q_path,
|
|||||||
if (strcmp(cmd, "/x-snac-get-token") == 0) { /** **/
|
if (strcmp(cmd, "/x-snac-get-token") == 0) { /** **/
|
||||||
const char *login = xs_dict_get(args, "login");
|
const char *login = xs_dict_get(args, "login");
|
||||||
const char *passwd = xs_dict_get(args, "passwd");
|
const char *passwd = xs_dict_get(args, "passwd");
|
||||||
|
const char *host = xs_dict_get(srv_config, "host");
|
||||||
const char *host = xs_dict_get(srv_config, "host");
|
const char *proto = xs_dict_get_def(srv_config, "protocol", "https");
|
||||||
|
|
||||||
/* by default, generate another login form with an error */
|
/* by default, generate another login form with an error */
|
||||||
*body = xs_fmt(login_page, host, host, "LOGIN INCORRECT", host, "oauth/x-snac-get-token",
|
*body = xs_fmt(login_page, host, host, "LOGIN INCORRECT", proto, host, "oauth/x-snac-get-token",
|
||||||
"", "", "", USER_AGENT);
|
"", "", "", USER_AGENT);
|
||||||
*ctype = "text/html";
|
*ctype = "text/html";
|
||||||
status = 200;
|
status = 200;
|
||||||
|
@ -19,7 +19,7 @@ int webfinger_request_signed(snac *snac, const char *qs, char **actor, char **us
|
|||||||
xs_str *host = NULL;
|
xs_str *host = NULL;
|
||||||
xs *resource = NULL;
|
xs *resource = NULL;
|
||||||
|
|
||||||
if (xs_startswith(qs, "http")) {
|
if (xs_startswith(qs, "https:/") || xs_startswith(qs, "http:/")) {
|
||||||
/* actor query: pick the host */
|
/* actor query: pick the host */
|
||||||
xs *s1 = xs_replace_n(qs, "http:/" "/", "", 1);
|
xs *s1 = xs_replace_n(qs, "http:/" "/", "", 1);
|
||||||
xs *s = xs_replace_n(s1, "https:/" "/", "", 1);
|
xs *s = xs_replace_n(s1, "https:/" "/", "", 1);
|
||||||
@ -70,7 +70,9 @@ int webfinger_request_signed(snac *snac, const char *qs, char **actor, char **us
|
|||||||
&payload, &p_size, &ctype);
|
&payload, &p_size, &ctype);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
xs *url = xs_fmt("http:/" "/%s/.well-known/webfinger?resource=%s", host, resource);
|
const char *proto = xs_dict_get_def(srv_config, "protocol", "https");
|
||||||
|
|
||||||
|
xs *url = xs_fmt("%s:/" "/%s/.well-known/webfinger?resource=%s", proto, host, resource);
|
||||||
|
|
||||||
if (snac == NULL)
|
if (snac == NULL)
|
||||||
xs_http_request("GET", url, headers, NULL, 0, &status, &payload, &p_size, 0);
|
xs_http_request("GET", url, headers, NULL, 0, &status, &payload, &p_size, 0);
|
||||||
@ -140,7 +142,7 @@ int webfinger_get_handler(xs_dict *req, char *q_path,
|
|||||||
snac snac;
|
snac snac;
|
||||||
int found = 0;
|
int found = 0;
|
||||||
|
|
||||||
if (xs_startswith(resource, "https")) {
|
if (xs_startswith(resource, "https:/") || xs_startswith(resource, "http:/")) {
|
||||||
/* actor search: find a user with this actor */
|
/* actor search: find a user with this actor */
|
||||||
xs *l = xs_split(resource, "/");
|
xs *l = xs_split(resource, "/");
|
||||||
char *uid = xs_list_get(l, -1);
|
char *uid = xs_list_get(l, -1);
|
||||||
|
Loading…
Reference in New Issue
Block a user