/* Initialise MYSQL Connection , execute queries to get fields and records and convert this to json i.e. field-name, field-value pairs. */ void init_conn(httpd *server) { httpVar *var1,*var2,*var3,*var4; var1 = httpdGetVariableByName(server,"server"); var2 = httpdGetVariableByName(server,"user"); var3 = httpdGetVariableByName(server,"pass"); var4 = httpdGetVariableByName(server,"db"); if(var1!=NULL && var2!=NULL && var3!=NULL && var4!=NULL) { char *serv = var1->value; char *user = var2->value; char *password = var3->value; char *database = var4->value; char *error = (char*)malloc(MAX_VALUE_LENGTH); conn = mysql_init(NULL); /* Connect to datababase */ if (!mysql_real_connect(conn, serv, user, password, database, 0, NULL, 0)) { httpdPrintf(server,"%s",mysql_error(conn)); } else { httpdPrintf(server,"Connection Successful"); mysql_query(conn,"ALTER TABLE details ADD COLUMN num INT AUTO_INCREMENT UNIQUE"); init_json(); } } return; }
void dummy_html(httpd *server) { httpdPrintf(server, "Welcome to the httpd queralyzer"); httpdPrintf(server, "<P><FORM ACTION=query METHOD=POST>\n"); httpdPrintf(server, "Enter your query <INPUT NAME=query SIZE=4096>\n"); httpdPrintf(server, "<INPUT TYPE=SUBMIT VALUE=Click!><P></FORM>\n" ); return; }
void table_data_html(httpd *server) { TableMetaData *tableData = new TableMetaData[10]; //currently hard coded int tableCount=0; if (!strcmp(httpdRequestMethodName(server), "GET")) { std::string getTableDataString; get_tableData(tableData, &tableCount); if(tableData==NULL) return; JsonSerializer::serialize(tableData, getTableDataString); httpdPrintf(server, "%s\n", getTableDataString.c_str()); /* for (int i=0; i<tableCount; i++) { std::string eachTable; JsonSerializer::serialize(tableData+i, eachTable); getTableDataString+=eachTable; if(i<tableCount-1) getTableDataString+=","; } std::string output ="["; output+=getTableDataString; output+="]"; std::cout<<output<<std::endl; httpdPrintf(server, "%s\n", output.c_str()); */ } else if (!strcmp(httpdRequestMethodName(server), "POST")) { httpVar *updateString; updateString = httpdGetVariableByName(server, "tablemetadata"); char *updateTableDataString = updateString->value; if (updateTableDataString == NULL) { httpdPrintf(server,"Missing table meta data information"); } std::string updateTableData; updateTableData.copy(updateTableDataString, strlen(updateTableDataString)); if(!JsonSerializer::deserialize(tableData, updateTableData)) { httpdPrintf(server,"Problem with updating Table Meta Data"); } else { //to be implemented //set_tableData(tableData, 0); } } tableCount=0; delete [] tableData; return; }
void query_html(httpd *server) { char* query_op; httpVar *variable; /* ** Grab the symbol table entry to see if the variable exists */ variable = httpdGetVariableByName(server, "query"); if (variable == NULL) { httpdPrintf(server,"Missing form data!"); return; } char *query =variable->value; queralyzer(query, &query_op); httpdPrintf(server, "%s\n", query_op); return; }
void http_nodogsplash_redirect(request *r, const char url[]) { char *header; httpdSetResponse(r, "302 Found"); safe_asprintf(&header, "Location: %s",url); httpdAddHeader(r, header); httpdPrintf(r, "<html><head></head><body><a href='%s'>Click here to continue to<br>%s</a></body></html>",url,url); free(header); }
void http_nodogsplash_redirect(request *r, const char url[]) { char *header; debug(LOG_DEBUG,"Redirect client %s to %s",r->clientAddr,url); httpdSetResponse(r, "302 Found\n"); safe_asprintf(&header, "Location: http://%s",url); httpdAddHeader(r, header); httpdPrintf(r, "<html><head></head><body><a href='%s'>Click here to continue to<br>%s</a></body></html>",url,url); free(header); }
/* response handler for HTTP 405 Method Not Allowed */ void http_nodogsplash_405(request *r) { httpdSetResponse(r, "405 Method Not Allowed"); httpdPrintf(r, "405 Method Not Allowed"); }