// 将包从数据库过滤回文件 void filterPackToFile() { printf("=============== 过滤数据包 ===============\n"); char filter[100]; printf("请输入过滤关键字:\n"); scanf("%s",filter); char desIP[100]; printf("请输入客户端IP:\n"); scanf("%s",desIP); char query[200]; strcpy(query,"select * from SSLTable_netease_music where protocol like '"); strcat(query,filter); strcat(query,"\%\' and destination like '"); strcat(query,desIP); strcat(query,"\%\' order by source"); printf(query); //char * query_test = "select * from SSLTableW1 where protocol like 'tls%' and destination like '172.24.%' order by source"; //printf(query_test); char fileName[100]; strcpy(fileName,"filterFile"); //strcat(fileName,filter); FILE * filterFile = fopen(fileName,"w+"); query_sql(query,filterFile); fclose(filterFile); }
int Grab::getGrabInfo(grab_t* grab_info) { UB_LOG_TRACE("Grab::getGrabInfo start"); string query_sql("SELECT `id`, `name`, `c_id`, `info`, `start_time`, `end_time`, `amount`, `probability` " "FROM `MCP`.`mcp_content_grab` " "WHERE `enable` = 1 AND `id` = " ); query_sql.append(toString(_id)); //DuokooMysql mysql; DuokooMysql mysql("grab_mysql"); int count=mysql.query(query_sql); if(count<0){ UB_LOG_FATAL( "sql[%s], [%s:%d]", query_sql.c_str(), __FILE__, __LINE__ ); return -5; }else if(count==0){ UB_LOG_FATAL( "Grab id[%d] has no record, [%s:%d]", _id, __FILE__, __LINE__ ); return -5; } _info.clear(); _info.id=atoi(mysql.getResult(0,0).c_str()); _info.name=mysql.getResult(0,1); _info.c_id=mysql.getResult(0,2); _info.info=mysql.getResult(0,3); _info.start_time=mysql.getResult(0,4); _info.end_time=mysql.getResult(0,5); _info.amount=atoi(mysql.getResult(0,6).c_str()); _info.probability=atof(mysql.getResult(0,7).c_str()); _info.send_amount=this->getSendAmount(); UB_LOG_NOTICE("name:[%s]",_info.name.c_str()); if(grab_info!=NULL){ *grab_info = _info; } UB_LOG_TRACE("Grab::getGrabInfo end"); return 0; }
int do_get_machinid_cmd(char* buf,int fd) { int username_size = buf[1]; int cnt; char cmd[60]; char user_name[20]; char machine_id[MACHINE_ID_LENGTH+2]; char datalength[2]; memcpy(user_name,&buf[2],username_size); user_name[username_size] = '\0'; printf("username=%s\n",user_name); snprintf(cmd,60,"select machine_id from user where user_name=\"%s\";",user_name); printf("cmd=%s\n",cmd); cnt = query_sql(cmd,machine_id,datalength); if(cnt) { printf("machine ID %s id length = %d\n",machine_id,strlen(machine_id)); if(strlen(machine_id) == MACHINE_ID_LENGTH) { return send_ok_toclient(fd,machine_id,MACHINE_ID_LENGTH); } } else printf("%s %d :sql return data count incorrect. cnt= %d\n",__func__,__LINE__,cnt); return -1; }
int main(int argc, char *argv[]) { /*测试下向里面插入数据*/ char *query; char *exe = "insert into stucent values('lala','hahhahah!');"; exe_sql(exe); /*测试下查询*/ query="select * from stucent;"; query_sql(query); return 0; }
//规定传输格式:程序包头(4)+ 标志终端类型(1) + 操作类型(1) // 操作所需参数个数(1)+ 每个参数的长度(参数个数) +数据 int do_login_cmd(char* buf,struct tcp_param *p)//login data order : 用户名长度用户名,密码长度 密码 { int username_size = buf[1]; int passwd_size = buf[2]; char cmd[100]; char user_name[20]; char user_passwd[20]; char service_passwd[20]; char datalength[2]; int cnt; if(buf[0] !=2 )return -1; memcpy(user_name,&buf[3],username_size); user_name[username_size] = '\0'; memcpy(user_passwd,&buf[3+username_size],passwd_size); user_passwd[passwd_size] = '\0'; snprintf(cmd,60,"select pass_wd from user where user_name=\"%s\";",user_name); printf("cmd=%s\n",cmd); if((cnt = query_sql(cmd,service_passwd,datalength)) == 1) { printf("user passwd %s\n",user_passwd); printf("service_pass %s\n",service_passwd); if(!strcmp(user_passwd,service_passwd)) { cnt = send_ok_toclient(p->fd,NULL,0); /* if(cnt)printf("send ok error\n"); if(p->kind == PC) snprintf(cmd,60,"update user set pc_ip=\"%s\" where user_name=\"%s\";",p->ip,user_name); else snprintf(cmd,60,"update user set android_ip=\"%s\" where user_name=\"%s\";",p->ip,user_name); printf("update ip cmd %s",cmd);*/ return cnt; } } else printf("%s %d :sql return data count incorrect.cnt= %d\n",__func__,__LINE__,cnt); return -1; }
int do_change_passwd_cmd(char* buf,struct tcp_param *p)//login data order : 用户名长度用户名,密码长度 密码 { int username_size = buf[1]; int passwd_size = buf[2]; int new_passwd_size = buf[3]; char cmd[100]; char user_name[20]; char user_passwd[20]; char service_passwd[20]; char datalength[2]; int cnt; //if(buf[0] !=2 )return -1; // printf("do change passwd\n"); memcpy(user_name,&buf[4],username_size); user_name[username_size] = '\0'; memcpy(user_passwd,&buf[4+username_size],passwd_size); user_passwd[passwd_size] = '\0'; snprintf(cmd,100,"select pass_wd from user where user_name=\"%s\";",user_name); printf("cmd=%s\n",cmd); if((cnt = query_sql(cmd,service_passwd,datalength)) == 1) { printf("username %s\n",user_passwd); printf("service_pass %s\n",service_passwd); if(!strcmp(user_passwd,service_passwd)) { printf("here we can change passwd\n"); memcpy(user_passwd,&buf[4+username_size+passwd_size],new_passwd_size);//put new passwd to there. snprintf(cmd,100,"update user set pass_wd=\"%s\" where user_name=\"%s\";",user_passwd,user_name); printf("new pass cmd = %s\n",cmd); cnt = update_sql(cmd); if(cnt == 0)cnt = send_ok_toclient(p->fd,NULL,0); if(cnt)printf("send ok error\n"); } } return cnt; }
int main(int argc,char *argv[]) { char* sql = "select * from stucent"; query_sql(sql); }