diff options
Diffstat (limited to 'html.c')
| -rw-r--r-- | html.c | 103 |
1 files changed, 80 insertions, 23 deletions
| @@ -934,7 +934,7 @@ static xs_html *html_user_body(snac *user, int read_only) | |||
| 934 | } | 934 | } |
| 935 | } | 935 | } |
| 936 | else | 936 | else |
| 937 | if (xs_startswith(v, "gemini:/")) { | 937 | if (xs_startswith(v, "gemini:/") || xs_startswith(v, "xmpp:")) { |
| 938 | value = xs_html_tag("a", | 938 | value = xs_html_tag("a", |
| 939 | xs_html_attr("rel", "me"), | 939 | xs_html_attr("rel", "me"), |
| 940 | xs_html_attr("href", v), | 940 | xs_html_attr("href", v), |
| @@ -1034,6 +1034,23 @@ xs_html *html_top_controls(snac *snac) | |||
| 1034 | xs_html_attr("value", L("Boost"))), | 1034 | xs_html_attr("value", L("Boost"))), |
| 1035 | xs_html_text(" "), | 1035 | xs_html_text(" "), |
| 1036 | xs_html_text(L("(by URL)"))), | 1036 | xs_html_text(L("(by URL)"))), |
| 1037 | xs_html_tag("p", NULL), | ||
| 1038 | xs_html_tag("form", | ||
| 1039 | xs_html_attr("autocomplete", "off"), | ||
| 1040 | xs_html_attr("method", "post"), | ||
| 1041 | xs_html_attr("action", ops_action), | ||
| 1042 | xs_html_sctag("input", | ||
| 1043 | xs_html_attr("type", "text"), | ||
| 1044 | xs_html_attr("name", "id"), | ||
| 1045 | xs_html_attr("required", "required"), | ||
| 1046 | xs_html_attr("placeholder", "https:/" "/fedi.example.com/bob/...")), | ||
| 1047 | xs_html_text(" "), | ||
| 1048 | xs_html_sctag("input", | ||
| 1049 | xs_html_attr("type", "submit"), | ||
| 1050 | xs_html_attr("name", "action"), | ||
| 1051 | xs_html_attr("value", L("Like"))), | ||
| 1052 | xs_html_text(" "), | ||
| 1053 | xs_html_text(L("(by URL)"))), | ||
| 1037 | xs_html_tag("p", NULL))); | 1054 | xs_html_tag("p", NULL))); |
| 1038 | 1055 | ||
| 1039 | /** user settings **/ | 1056 | /** user settings **/ |
| @@ -2917,6 +2934,8 @@ int html_get_handler(const xs_dict *req, const char *q_path, | |||
| 2917 | int proxy = 0; | 2934 | int proxy = 0; |
| 2918 | const char *v; | 2935 | const char *v; |
| 2919 | 2936 | ||
| 2937 | const xs_dict *q_vars = xs_dict_get(req, "q_vars"); | ||
| 2938 | |||
| 2920 | xs *l = xs_split_n(q_path, "/", 2); | 2939 | xs *l = xs_split_n(q_path, "/", 2); |
| 2921 | v = xs_list_get(l, 1); | 2940 | v = xs_list_get(l, 1); |
| 2922 | 2941 | ||
| @@ -2925,6 +2944,23 @@ int html_get_handler(const xs_dict *req, const char *q_path, | |||
| 2925 | return HTTP_STATUS_NOT_FOUND; | 2944 | return HTTP_STATUS_NOT_FOUND; |
| 2926 | } | 2945 | } |
| 2927 | 2946 | ||
| 2947 | if (strcmp(v, "share-bridge") == 0) { | ||
| 2948 | /* temporary redirect for a post */ | ||
| 2949 | const char *login = xs_dict_get(q_vars, "login"); | ||
| 2950 | const char *content = xs_dict_get(q_vars, "content"); | ||
| 2951 | |||
| 2952 | if (xs_type(login) == XSTYPE_STRING && xs_type(content) == XSTYPE_STRING) { | ||
| 2953 | xs *b64 = xs_base64_enc(content, strlen(content)); | ||
| 2954 | |||
| 2955 | srv_log(xs_fmt("share-bridge for user '%s'", login)); | ||
| 2956 | |||
| 2957 | *body = xs_fmt("%s/%s/share?content=%s", srv_baseurl, login, b64); | ||
| 2958 | return HTTP_STATUS_SEE_OTHER; | ||
| 2959 | } | ||
| 2960 | else | ||
| 2961 | return HTTP_STATUS_NOT_FOUND; | ||
| 2962 | } | ||
| 2963 | |||
| 2928 | uid = xs_dup(v); | 2964 | uid = xs_dup(v); |
| 2929 | 2965 | ||
| 2930 | /* rss extension? */ | 2966 | /* rss extension? */ |
| @@ -2959,7 +2995,6 @@ int html_get_handler(const xs_dict *req, const char *q_path, | |||
| 2959 | int def_show = xs_number_get(xs_dict_get(srv_config, "max_timeline_entries")); | 2995 | int def_show = xs_number_get(xs_dict_get(srv_config, "max_timeline_entries")); |
| 2960 | int show = def_show; | 2996 | int show = def_show; |
| 2961 | 2997 | ||
| 2962 | const xs_dict *q_vars = xs_dict_get(req, "q_vars"); | ||
| 2963 | if ((v = xs_dict_get(q_vars, "skip")) != NULL) | 2998 | if ((v = xs_dict_get(q_vars, "skip")) != NULL) |
| 2964 | skip = atoi(v), cache = 0, save = 0; | 2999 | skip = atoi(v), cache = 0, save = 0; |
| 2965 | if ((v = xs_dict_get(q_vars, "show")) != NULL) | 3000 | if ((v = xs_dict_get(q_vars, "show")) != NULL) |
| @@ -3045,32 +3080,30 @@ int html_get_handler(const xs_dict *req, const char *q_path, | |||
| 3045 | q = url_acct; | 3080 | q = url_acct; |
| 3046 | } | 3081 | } |
| 3047 | else { | 3082 | else { |
| 3048 | /* if it's not already here, try to bring it to the user's timeline */ | 3083 | /* bring it to the user's timeline */ |
| 3049 | xs *md5 = xs_md5_hex(q, strlen(q)); | 3084 | xs *object = NULL; |
| 3050 | 3085 | int status; | |
| 3051 | if (!timeline_here(&snac, md5)) { | ||
| 3052 | xs *object = NULL; | ||
| 3053 | int status; | ||
| 3054 | 3086 | ||
| 3055 | status = activitypub_request(&snac, q, &object); | 3087 | status = activitypub_request(&snac, q, &object); |
| 3056 | snac_debug(&snac, 1, xs_fmt("Request searched URL %s %d", q, status)); | 3088 | snac_debug(&snac, 1, xs_fmt("Request searched URL %s %d", q, status)); |
| 3057 | 3089 | ||
| 3058 | if (valid_status(status)) { | 3090 | if (valid_status(status)) { |
| 3059 | /* got it; also request the actor */ | 3091 | /* got it; also request the actor */ |
| 3060 | const char *attr_to = get_atto(object); | 3092 | const char *attr_to = get_atto(object); |
| 3061 | 3093 | ||
| 3062 | if (!xs_is_null(attr_to)) { | 3094 | if (!xs_is_null(attr_to)) { |
| 3063 | status = actor_request(&snac, attr_to, &actor_obj); | 3095 | status = actor_request(&snac, attr_to, &actor_obj); |
| 3064 | 3096 | ||
| 3065 | snac_debug(&snac, 1, xs_fmt("Request author %s of %s %d", attr_to, q, status)); | 3097 | if (valid_status(status)) { |
| 3098 | /* reset the query string to be the real id */ | ||
| 3099 | url_acct = xs_dup(xs_dict_get(object, "id")); | ||
| 3100 | q = url_acct; | ||
| 3066 | 3101 | ||
| 3067 | if (valid_status(status)) { | 3102 | /* add the post to the timeline */ |
| 3068 | /* add the actor */ | 3103 | xs *md5 = xs_md5_hex(q, strlen(q)); |
| 3069 | actor_add(attr_to, actor_obj); | ||
| 3070 | 3104 | ||
| 3071 | /* add the post to the timeline */ | 3105 | if (!timeline_here(&snac, md5)) |
| 3072 | timeline_add(&snac, q, object); | 3106 | timeline_add(&snac, q, object); |
| 3073 | } | ||
| 3074 | } | 3107 | } |
| 3075 | } | 3108 | } |
| 3076 | } | 3109 | } |
| @@ -3473,6 +3506,30 @@ int html_get_handler(const xs_dict *req, const char *q_path, | |||
| 3473 | } | 3506 | } |
| 3474 | } | 3507 | } |
| 3475 | else | 3508 | else |
| 3509 | if (strcmp(p_path, "share") == 0) { /** direct post **/ | ||
| 3510 | if (!login(&snac, req)) { | ||
| 3511 | *body = xs_dup(uid); | ||
| 3512 | status = HTTP_STATUS_UNAUTHORIZED; | ||
| 3513 | } | ||
| 3514 | else { | ||
| 3515 | const char *b64 = xs_dict_get(q_vars, "content"); | ||
| 3516 | int sz; | ||
| 3517 | xs *content = xs_base64_dec(b64, &sz); | ||
| 3518 | xs *msg = msg_note(&snac, content, NULL, NULL, NULL, 0, NULL); | ||
| 3519 | xs *c_msg = msg_create(&snac, msg); | ||
| 3520 | |||
| 3521 | timeline_add(&snac, xs_dict_get(msg, "id"), msg); | ||
| 3522 | |||
| 3523 | enqueue_message(&snac, c_msg); | ||
| 3524 | |||
| 3525 | snac_debug(&snac, 1, xs_fmt("web action 'share' received")); | ||
| 3526 | |||
| 3527 | *body = xs_fmt("%s/admin", snac.actor); | ||
| 3528 | *b_size = strlen(*body); | ||
| 3529 | status = HTTP_STATUS_SEE_OTHER; | ||
| 3530 | } | ||
| 3531 | } | ||
| 3532 | else | ||
| 3476 | status = HTTP_STATUS_NOT_FOUND; | 3533 | status = HTTP_STATUS_NOT_FOUND; |
| 3477 | 3534 | ||
| 3478 | user_free(&snac); | 3535 | user_free(&snac); |
| @@ -3604,7 +3661,7 @@ int html_post_handler(const xs_dict *req, const char *q_path, | |||
| 3604 | enqueue_close_question(&snac, xs_dict_get(msg, "id"), end_secs); | 3661 | enqueue_close_question(&snac, xs_dict_get(msg, "id"), end_secs); |
| 3605 | } | 3662 | } |
| 3606 | else | 3663 | else |
| 3607 | msg = msg_note(&snac, content_2, to, in_reply_to, attach_list, priv); | 3664 | msg = msg_note(&snac, content_2, to, in_reply_to, attach_list, priv, NULL); |
| 3608 | 3665 | ||
| 3609 | if (sensitive != NULL) { | 3666 | if (sensitive != NULL) { |
| 3610 | msg = xs_dict_set(msg, "sensitive", xs_stock(XSTYPE_TRUE)); | 3667 | msg = xs_dict_set(msg, "sensitive", xs_stock(XSTYPE_TRUE)); |
| @@ -4038,7 +4095,7 @@ int html_post_handler(const xs_dict *req, const char *q_path, | |||
| 4038 | int c = 0; | 4095 | int c = 0; |
| 4039 | 4096 | ||
| 4040 | while (xs_list_next(ls, &v, &c)) { | 4097 | while (xs_list_next(ls, &v, &c)) { |
| 4041 | xs *msg = msg_note(&snac, "", actor, irt, NULL, 1); | 4098 | xs *msg = msg_note(&snac, "", actor, irt, NULL, 1, NULL); |
| 4042 | 4099 | ||
| 4043 | /* set the option */ | 4100 | /* set the option */ |
| 4044 | msg = xs_dict_append(msg, "name", v); | 4101 | msg = xs_dict_append(msg, "name", v); |