jstring Java_euphoria_psycho_comic_util_Utilities_request(JNIEnv *env, jstring host, jstring path) { const char *n_host = (*env)->GetStringUTFChars(env, host, 0); const char *n_path = (*env)->GetStringUTFChars(env, path, 0); LOGW("%s",n_host); Buffer *response = buffer_alloc(255); int status = 0; int sockfd = 0; struct addrinfo *res = NULL; status = init_connection(n_host, "80", &res); error_unless(status == 0, "Could not resolve host: %s\n", gai_strerror(status)); jstring result1 = (*env)->NewStringUTF(env, n_host); return result1; sockfd = make_connection(res); error_unless(sockfd > 0, "Could not make connection to '"); status = make_request(sockfd, n_host, n_path); error_unless(status > 0, "Sending request failed"); status = fetch_response(sockfd, &response, RECV_SIZE); error_unless(status >= 0, "Fetching response failed"); printf("%s\n", response->contents); close(sockfd); freeaddrinfo(res); jstring result = (*env)->NewStringUTF(env, response->contents); buffer_free(response); (*env)->ReleaseStringUTFChars(env, host, n_host); (*env)->ReleaseStringUTFChars(env, path, n_path); return result; error: if (sockfd > 0) { close(sockfd); } if (res != NULL) { freeaddrinfo(res); } (*env)->ReleaseStringUTFChars(env, host, n_host); (*env)->ReleaseStringUTFChars(env, path, n_path); return (*env)->NewStringUTF(env, "Error"); buffer_free(response); // return (*env)->NewStringUTF(env, "Hello from JNI ! Compiled with ABI " // ABI // "."); }
static int login_step1(const unsigned char password[MD5_DIGEST_LENGTH << 1]) { curl_data_t data_login = empty_curl_data; curl_header_t header_login = empty_curl_header; str_t number = conf_lookup(&robot.conf, str_from("QQ")).string; str_t cookie_str; char* url = malloc(sizeof("https://ssl.ptlogin2.qq.com/login?u=&p=&verifycode=&webqq_type=10&remember_uin=1&login2qq=1&aid=1003903&u1=http%3A%2F%2Fweb2.qq.com%2Floginproxy.html%3Flogin2qq%3D1%26webqq_type%3D10&h=1&ptredirect=0&ptlang=2052&daid=164&from_ui=1&pttype=1&dumy=&fp=loginerroralert&action=6-53-32873&mibao_css=m_webqq&t=4&g=1&js_type=0&js_ver=10077&login_sig=qBpuWCs9dlR9awKKmzdRhV8TZ8MfupdXF6zyHmnGUaEzun0bobwOhMh6m7FQjvWA") + (MD5_DIGEST_LENGTH << 1) + VERIFY_LEN + number.len); str_t* login_response = NULL; int rc = 1; size_t login_response_count = 0; url[0] = 0; strcpy(url, "https://ssl.ptlogin2.qq.com/login?u="); strncat(url, number.ptr, number.len); strcat(url, "&p="); strncat(url, (char*)password, MD5_DIGEST_LENGTH << 1); strcat(url, "&verifycode="); strncat(url, robot.verify_code, VERIFY_LEN); strcat(url, "&webqq_type=10&remember_uin=1&login2qq=1&aid=1003903&u1=http%3A%2F%2Fweb2.qq.com%2Floginproxy.html%3Flogin2qq%3D1%26webqq_type%3D10&h=1&ptredirect=0&ptlang=2052&daid=164&from_ui=1&pttype=1&dumy=&fp=loginerroralert&action=6-53-32873&mibao_css=m_webqq&t=4&g=1&js_type=0&js_ver=10077&login_sig=qBpuWCs9dlR9awKKmzdRhV8TZ8MfupdXF6zyHmnGUaEzun0bobwOhMh6m7FQjvWA"); cookie_str = cookie_to_str(&robot.cookie); rc = get_request_with_cookie(url, 1, "./pems/ssl.ptlogin2.qq.com.pem", cookie_str.ptr, &data_login, &header_login); if (!rc) { fprintf(stderr, "Call login error!!!!\n"); goto end; } merge_cookie_to_robot(&header_login); robot.ptwebqq = pair_array_lookup(&robot.cookie, str_from("ptwebqq")); login_response = fetch_response(data_login.data, &login_response_count); if (strcmp(login_response[4].ptr, "登录成功!") != 0) { rc = 0; goto end; } rc = login_proxy(login_response[2].ptr); end: curl_data_free(&data_login); pair_array_free(&header_login); str_free(cookie_str); free(url); str_array_free(login_response, login_response_count); return rc; }
static int want_image(int* want) { curl_data_t data_check = empty_curl_data; curl_header_t header_check = empty_curl_header; str_t number = conf_lookup(&robot.conf, str_from("QQ")).string; char* url = malloc(sizeof("https://ssl.ptlogin2.qq.com/check?uin=&appid=1003903&r=0.14233942252344134") + number.len); str_t* check_response = NULL; int rc = 1; size_t check_response_count = 0; url[0] = 0; strcpy(url, "https://ssl.ptlogin2.qq.com/check?uin="); strncat(url, number.ptr, number.len); strcat(url, "&appid=1003903&r=0.14233942252344134"); rc = get_request(url, 1, "./pems/ssl.ptlogin2.qq.com.pem", &data_check, &header_check); if (!rc) { fprintf(stderr, "Call check error!!!!\n"); goto end; } merge_cookie_to_robot(&header_check); check_response = fetch_response(data_check.data, &check_response_count); if (strcmp(check_response[0].ptr, "0") == 0) *want = 0; else if (strcmp(check_response[0].ptr, "2") == 0) { fprintf(stderr, "Invalid QQ Number!!!!\n"); goto end; } else *want = 1; memcpy(robot.verify_code, check_response[1].ptr, VERIFY_LEN); bits_from_str(check_response[2], robot.bits); end: curl_data_free(&data_check); pair_array_free(&header_check); free(url); str_array_free(check_response, check_response_count); return rc; }