void login_handler(request_args &r){ int code=200; std::vector<m2pp::header> redir_headers = {{"Content-Type","text/html"}}; mustache::Context* dict = base_template_variables(new mustache::Context(), scripts); mustache::PlustacheTypes::ObjectType login_form_section, message_section; soci::session sql(r.db_pool); User *user = new User(); if(header_value(r.req.headers,"METHOD") == "POST"){ std::unordered_map<std::string,std::string> login_form = getFormFields(r.req.body); for(auto fields:login_form){ std::cout << fields.first << " = " << fields.second << std::endl; } std::string username = login_form["userid"]; log_DEBUG(username); sql << "select * from users where username = '******'",soci::into(*user); if(!sql.got_data()){ message_section["STATUS"] = "Username is not registered."; }else{ redir_headers.push_back({"Location","/nutrition/" }); code = 303; } } dict->add("LOGIN_FORM", login_form_section); dict->add("MESSAGE", message_section); r.conn.reply_http(r.req,render_template("login",dict),code,"OK",redir_headers); }
void print_device(EnDevice variable){ log_DEBUG("[EnDevice] dc_id = %d",variable.dc_id); log_DEBUG("[EnDevice] rorg = %02hhX",variable.rorg); log_DEBUG("[EnDevice] func = %02hhX",variable.func); log_DEBUG("[EnDevice] type = %02hhX",variable.type); log_DEBUG("[EnDevice] id1 = %02hhX",variable.id1); log_DEBUG("[EnDevice] id2 = %02hhX",variable.id2); log_DEBUG("[EnDevice] id3 = %02hhX",variable.id3); log_DEBUG("[EnDevice] id4 = %02hhX",variable.id4); log_DEBUG("[EnDevice] enable = %d",variable.enable); }
bool addEnoceanDevice(char* data) { unsigned char rorg = data[0]; unsigned char id1 = ""; unsigned char id2 = ""; unsigned char id3 = ""; unsigned char id4 = ""; switch (rorg) { case 0xD5: id1 = data[2]; id2 = data[3]; id3 = data[4]; id4 = data[5]; break; case 0xF6: id1 = data[2]; id2 = data[3]; id3 = data[4]; id4 = data[5]; break; case 0xA5: id1 = data[5]; id2 = data[6]; id3 = data[7]; id4 = data[8]; break; case 0xD2: id1 = data[7]; id2 = data[8]; id3 = data[9]; id4 = data[10]; break; default: log_DEBUG("[EnOcean] TYPE: Not Supported"); break; } log_DEBUG("[EnOcean] Record Mode : %d", RECORD); if (RECORD == 1) { log_INFO("[EnOcean] Recording new device type : %02hhX",rorg); mysql_insert("INSERT IGNORE INTO devices (dc_id,last_update,packettype,int_id,id1,id2,id3,id4,com) \ SELECT IFNULL(MAX(dc_id),0)+1,NOW(),'%02hhX',4,'%02hhX','%02hhX','%02hhX','%02hhX','tx' FROM devices ON DUPLICATE KEY UPDATE last_update=NOW();",\ rorg,id1,id2,id3,id4); }
int main() { log_DEBUG(PSTR("debug")); log_INFORMATIONAL(PSTR("informational")); log_NOTICE(PSTR("notice")); log_WARNING(PSTR("warning")); log_ERROR(PSTR("error")); log_CRITICAL(PSTR("critical")); log_ALERT(PSTR("alert")); log_EMERGENCY(PSTR("emergency")); return EXIT_SUCCESS; }
void Logs::DEBUG_LOG(const char* file, int line, const char* function, const char* format, ...) { //#ifdef DEBUG if (!Settings::getInstance()->IsLogEnabled) return; char buffer[2048]; memset(buffer, 0x00, sizeof(buffer)); va_list args; va_start (args, format); #if defined(__unix__) vsnprintf(buffer, sizeof(buffer) - 1, format, args); #else _vsnprintf_s(buffer, sizeof(buffer) - 1, format, args); #endif log_DEBUG(processLog(file, line, function, buffer)); va_end(args); //#endif }
int read_config_file(char CONFIGFILE[1024]) { FILE *fic = NULL; int nb_lignes; char line[512]={'\0'}; fic=fopen (CONFIGFILE,"r"); if(fic==NULL) { //printf("Probleme a l'ouverture du fichier de configuration\n"); return 1; } // compter et afficher les lignes du fichier nb_lignes = 0; while(fgets(line, 512, fic) != NULL) { if( (line[0] != '#') && (line[0] != '\n')) { variable_detection(line); } nb_lignes++; } log_INFO("\n--------- Loading Mydombox Server configuration ---------"); log_DEBUG("LOG_FILE_PATH = %s", LOG_FILE_PATH); log_DEBUG("LOG_LEVEL = %s", LOG_LEVEL); log_DEBUG("MYSQL = %d", MYSQL); log_DEBUG("HOSTNAME = %s", HOSTNAME); log_DEBUG("PORT = %d", PORT); log_DEBUG("LOGIN = %s", LOGIN); log_DEBUG("PASSWORD = %s", PASSWORD); log_DEBUG("DATABASE = %s", DATABASE); log_DEBUG("PORT_RFXTRX433 = %s",PORT_RFXTRX433); log_DEBUG("PORT_ENOUSB300 = %s",PORT_ENOUSB300); log_DEBUG("MODULE_SOAP = %d", MODULE_SOAP); log_DEBUG("PORT_SOAP = %d", PORT_SOAP); log_DEBUG("MODULE_RPIDOM = %d", MODULE_RPIDOM); log_DEBUG("PORT_RPIDOM = %s", PORT_RPIDOM); log_DEBUG("RPIDOM_TELE1_TYPE = %d", RPIDOM_TELE1_TYPE); log_DEBUG("RPIDOM_TELE2_TYPE = %d", RPIDOM_TELE2_TYPE); log_DEBUG("RPIDOM_1WIRE = %d", RPIDOM_1WIRE); log_DEBUG("MDB_CLOUD = %d", MDB_CLOUD); log_DEBUG("MDB_KEY = %s", MDB_KEY); log_DEBUG("MDB_ID = %s", MDB_ID); log_DEBUG("MDB_X_ISS_Key = %s", MDB_X_ISS_Key); log_DEBUG("MDB_X_OAPI_Key = %s", MDB_X_OAPI_Key); log_DEBUG("MDB_DATASOURCE = %s", MDB_DATASOURCE); log_DEBUG("--------------------------------------------------------\n"); fclose(fic); return 0; }
EnDevice GetEnDevice(char* data){ EnDevice device; device.dc_id = 0; unsigned char packettype = data[0]; unsigned char id1 = ""; unsigned char id2 = ""; unsigned char id3 = ""; unsigned char id4 = ""; switch (packettype) { case 0xD5: id1 = data[2]; id2 = data[3]; id3 = data[4]; id4 = data[5]; break; case 0xF6: id1 = data[2]; id2 = data[3]; id3 = data[4]; id4 = data[5]; break; case 0xA5: id1 = data[5]; id2 = data[6]; id3 = data[7]; id4 = data[8]; break; case 0xD2: id1 = data[7]; id2 = data[8]; id3 = data[9]; id4 = data[10]; break; default: log_DEBUG("[EnOcean] TYPE: Not Supported"); break; } MYSQL *conn; MYSQL_RES *result; MYSQL_ROW row; conn = mysql_connection(); result = mysql_select(conn,"SELECT dc_id,packettype,subtype,type,id1,id2,id3,id4,enable FROM devices \ WHERE int_id=%d AND id1='%02hhX'AND id2='%02hhX'AND id3='%02hhX'AND id4='%02hhX';",4,id1,id2,id3,id4); int num_fields = mysql_num_fields(result); if (num_fields != 0) { while ((row = mysql_fetch_row(result))){ device.dc_id = atoi(row[0]); device.rorg = stringtohex(row[1]); device.func = stringtohex(row[2]); device.type = stringtohex(row[3]); device.id1 = stringtohex(row[4]); device.id2 = stringtohex(row[5]); device.id3 = stringtohex(row[6]); device.id4 = stringtohex(row[7]); device.enable=(bool)row[8]; } } return device; }