forked from mirrors/principia
Fix cURL -> webview token cookie transfer for principia-web
This commit is contained in:
parent
cc21cb0ea6
commit
8cdab6cb31
4 changed files with 18 additions and 62 deletions
|
|
@ -709,37 +709,11 @@ public class SDLActivity extends Activity implements DialogInterface.OnDismissLi
|
|||
public void run() {
|
||||
String community_host = PrincipiaBackend.getCommunityHost();
|
||||
if (SDLActivity.wv_cm != null) {
|
||||
String cookie_data = SDLActivity.wv_cm.getCookie("."+community_host);
|
||||
if (cookie_data != null) {
|
||||
String[] prev_cookies = cookie_data.split("; ");
|
||||
int uid = 1;
|
||||
for (String pc : prev_cookies) {
|
||||
String[] data = pc.split("=");
|
||||
if (data[0].startsWith("phpbb_") && data[0].endsWith("_u")) {
|
||||
try {
|
||||
uid = Integer.parseInt(data[1]);
|
||||
} catch (Exception e) { }
|
||||
}
|
||||
}
|
||||
String curl_token = PrincipiaBackend.getCookies();
|
||||
|
||||
// not logged in with webview already, fetch cookies from curl!
|
||||
if (uid <= 1) {
|
||||
String[] cd = PrincipiaBackend.getCookies().split("/");
|
||||
int u = 1;
|
||||
String k = null, sid = null;
|
||||
try {
|
||||
u = Integer.parseInt(cd[0]);
|
||||
k = cd[1];
|
||||
sid = cd[2];
|
||||
} catch (Exception e) { }
|
||||
|
||||
if (u != 1 && u != 0 && k != null && sid != null) {
|
||||
// we got relevant cookies from curl!
|
||||
SDLActivity.wv_cm.setCookie("."+community_host, "phpbb_ziao2_u="+u);
|
||||
SDLActivity.wv_cm.setCookie("."+community_host, "phpbb_ziao2_k="+k);
|
||||
SDLActivity.wv_cm.setCookie("."+community_host, "phpbb_ziao2_sid="+sid);
|
||||
}
|
||||
}
|
||||
if (curl_token != null) {
|
||||
// we got relevant cookies from curl!
|
||||
SDLActivity.wv_cm.setCookie("."+community_host, "_PRINCSECURITY="+curl_token);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4184,13 +4184,14 @@ principia::get_light_normal()
|
|||
#undef LIGHT_NORMAL_Z
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the community site login token from cURL, intended for the user to be automatically
|
||||
* logged into the Android webview.
|
||||
*/
|
||||
extern "C" void
|
||||
P_get_cookie_data(char **u, char **k, char **sid, char **l)
|
||||
P_get_cookie_data(char **token)
|
||||
{
|
||||
*u = 0;
|
||||
*k = 0;
|
||||
*sid = 0;
|
||||
*l = 0;
|
||||
*token = 0;
|
||||
|
||||
if (quitting) {
|
||||
return;
|
||||
|
|
@ -4212,32 +4213,16 @@ P_get_cookie_data(char **u, char **k, char **sid, char **l)
|
|||
|
||||
while (cookies) {
|
||||
int nt = 0;
|
||||
int found_u = 0;
|
||||
int found_k = 0;
|
||||
int found_sid = 0;
|
||||
int found_l = 0;
|
||||
int found_token = 0;
|
||||
char *d = cookies->data;
|
||||
tms_debugf("cookie: %s", d);
|
||||
while (*d != '\0') {
|
||||
if (nt == 5) {
|
||||
if (strncmp(d, "phpbb_ziao2_u", 13) == 0) {
|
||||
found_u = 1;
|
||||
}
|
||||
if (strncmp(d, "phpbb_ziao2_k", 13) == 0) {
|
||||
found_k = 1;
|
||||
}
|
||||
if (strncmp(d, "phpbb_ziao2_sid", 15) == 0) {
|
||||
found_sid = 1;
|
||||
}
|
||||
if (strncmp(d, "z2lia7e", 7) == 0) {
|
||||
found_l = 1;
|
||||
}
|
||||
if (strncmp(d, "_PRINCSECURITY", 14) == 0)
|
||||
found_token = 1;
|
||||
}
|
||||
if (nt == 6) {
|
||||
if (found_u) *u = d;
|
||||
if (found_sid) *sid = d;
|
||||
if (found_k) *k = d;
|
||||
if (found_l) *l = d;
|
||||
if (found_token) *token = d;
|
||||
break;
|
||||
}
|
||||
if (*d == '\t') nt++;
|
||||
|
|
|
|||
|
|
@ -311,7 +311,7 @@ void P_focus(int focus);
|
|||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
void P_get_cookie_data(char **u, char **k, char **sid, char **l);
|
||||
void P_get_cookie_data(char **token);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -940,13 +940,10 @@ Java_org_libsdl_app_PrincipiaBackend_getCommunityHost(JNIEnv *env, jclass jcls)
|
|||
extern "C" jstring
|
||||
Java_org_libsdl_app_PrincipiaBackend_getCookies(JNIEnv *env, jclass jcls)
|
||||
{
|
||||
char *u, *k, *sid, *l;
|
||||
P_get_cookie_data(&u, &k, &sid, &l);
|
||||
char *token;
|
||||
P_get_cookie_data(&token);
|
||||
|
||||
char data[512];
|
||||
snprintf(data, 511, "%s/%s/%s", u ? u : "1", k ? k : "", sid ? sid : "");
|
||||
|
||||
return env->NewStringUTF(data);
|
||||
return env->NewStringUTF(token);
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue