int httpserver_ev_handler(struct httpd_request *conn, enum httpd_event ev) { if (ev == HTTP_REQUEST) { LOGGER_DEBUG("[HttpServer]Recv Request:%s content:%s", conn->remote_ip, conn->body); char action[8] = {0}, platform[8] = {0}; httpd_get_post_var(conn, "action", action, sizeof(action)); httpd_get_post_var(conn, "platform", platform, sizeof(platform)); if (!strcmp(action, "1") && !strcmp(platform, "0")) { char guest[128], accesstoken[64]; httpd_get_post_var(conn, "guest", guest, sizeof(guest)); int64 uid = auth_verify_from_mydb_by_client(guest, accesstoken, sizeof(accesstoken)); char response[1024]; snprintf(response, sizeof(response), "uid=%lld&accesstoken=%s", uid, accesstoken); httpd_send_data(conn, response, strlen(response)); LOGGER_DEBUG("[HttpServer]Send Response:%s %s", conn->remote_ip, response); } else if (!strcmp(action, "2") && !strcmp(platform, "0")) { char uid[64], accesstoken[64]; httpd_get_post_var(conn, "userid", uid, sizeof(uid)); httpd_get_post_var(conn, "accesstoken", accesstoken, sizeof(accesstoken)); int ret = auth_verify_from_mydb_by_gate(atoll(uid), accesstoken); char response[32]; snprintf(response, sizeof(response), "result=%d", ret); httpd_send_data(conn, response, strlen(response)); LOGGER_DEBUG("[HttpServer]Send Response:%s %s", conn->remote_ip, response); } /*if (true) { httpd_send_data(conn, "0", 1); } else { httpd_send_data(conn, "1", 1); }*/ return 0; } else { return 1; } }
static void login_httpd_account(struct httpd_session_data *sd,const char* url) { char* userid = httpd_get_value(sd,"userid"); int userid_len = (int)strlen(userid); char* passwd = httpd_get_value(sd,"passwd"); int passwd_len = (int)strlen(passwd); char* gender = httpd_get_value(sd,"gender"); char* check = httpd_get_value(sd,"check"); const char* msg = ""; int i; do { if(httpd_get_method(sd) != HTTPD_METHOD_POST) { // POST以外お断り msg = "Illegal request."; break; } if(!httpd_new_account_flag) { msg = "Now stopping to create accounts on httpd."; break; } if(userid_len < 4 || userid_len > 23) { msg = "Please input UserID 4-23 bytes."; break; } for(i = 0; i < userid_len; i++) { if(!isalnum((unsigned char)userid[i])) break; } if(i != userid_len) { msg = "Illegal character found in UserID."; break; } if(check[0]) { // ID のチェックは userid だけでいい if(account_load_str(userid) == NULL) { msg = "OK : You can use UserID."; } else { msg = "NG : UserID is already used."; } break; } if(passwd_len < 4 || passwd_len > 23) { msg = "Please input Password 4-23 bytes."; break; } for(i = 0; i < passwd_len; i++) { if(!isalnum((unsigned char)passwd[i])) break; } if(i != passwd_len) { msg = "Illegal character found in Password."; break; } if(gender[0] != 'M' && gender[0] != 'F') { msg = "Gender error."; break; } if(!check[0]) { struct mmo_account ma; char buf[32]; memset(&ma,0,sizeof(ma)); strncpy(ma.userid,userid,24); strncpy(ma.pass ,passwd,24); ma.sex = gender[0]; strncpy(ma.mail ,"@" ,40); // 暫定 strncpy(ma.birth ,"000000", 7); sprintf(buf,"( httpd %08lx )",httpd_get_ip(sd)); if( !account_new(&ma,buf) ) { msg = "Account creation failed."; } else { msg = "Account successfully created."; } } } while(0); // HTTP/1.1で返すとアカウントを連続して作成する馬鹿がいそうなので、 // あえてHTTP/1.0扱いしている。 httpd_send_head(sd,200,"text/plain",-1); httpd_send_data(sd,(int)strlen(msg),msg); aFree(userid); aFree(passwd); aFree(gender); aFree(check); return; }