int Device::process_confirm_raw(char *buf) { int readings_removed = 0; int uid_test = (buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24)); if(uid == -1) update_uid(uid_test); int flags = buf[4]; if(flags & SHUTDOWN_FLAG) { state = SHUTDOWN; } if(flags & UPDATE_TIME_FLAG) { time_t temp = 0; for(int n = 0; n < 4; n++) { temp |= ((buf[6+n] & 0x000000FF) << n*8); } std::cout << "Time update, now " << temp << std::endl; } int n_readings = buf[5]; for(int i = 0; i < n_readings; i++) { time_t time = 0; for(int n = 0; n < 4; n++) { time |= ((buf[6+(i*(4))+n] & 0x000000FF) << n*8); } if(rm_reading(time)) readings_removed++; } return readings_removed; }
int Device::process_readings_raw(char *buf) { int uid_test = (buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24)); if(uid_test == -1) update_uid(uid_counter++); int flags = buf[4]; int n_readings = buf[5]; if(flags & LOW_BATTERY_FLAG) set_battery(LOW_BATTERY_LEVEL); if(flags & SHUTDOWN_FLAG) { set_battery(LOW_BATTERY_LEVEL); // std::cout << "Device shut down" << std::endl; } //std::cout << "n_readings = " << n_readings << std::endl; for(int i = 0; i < n_readings; i++) { time_t time = 0; int reading = 0; for(int n = 0; n < 4; n++) { time |= ((buf[6+(i*(4+4))+n] & 0x000000FF) << n*8); reading |= ((buf[6+(i*(4+4))+4+n] & 0x000000FF) << n*8); } add_reading(time, reading); } return n_readings; }
int Device::process_readings_xml(pugi::xml_document &doc) { std::stringstream ss; ss << "Device " << uid << ": Parsing client message" << std::endl; log(ss.str()); ss.str(std::string()); pugi::xml_node mother_node = doc.first_child(); std::string msg_v = mother_node.child("msg_version").child_value(); if((strcmp(mother_node.name(), "client") != 0) || \ (strcmp(msg_v.c_str(), " 1.0") != 0)) { ss << "Device " << uid << ": Invalid message, parsing failed" << std::endl; log(ss.str()); return 0; } int uid_test = atoi(mother_node.child("uid").child_value()); if(uid_test == -1) update_uid(uid_counter++); battery = atoi(mother_node.child("battery").child_value()); strncpy(fw_version, mother_node.child("fw").child_value(), 5); std::string shutdown = mother_node.child("shut_down").child_value(); if(strcmp(shutdown.c_str(), "true") == 0) { std::cout << "Device shut down" << std::endl; state = SHUTDOWN; } int num_readings = atoi(mother_node.child("n_readings").child_value()); pugi::xml_node readings = mother_node.child("readings"); for(int i = 0; i < num_readings; i++) { ss << "reading" << i; std::string time_c = readings.child(ss.str().c_str()).child("time").child_value(); int reading = atoi(readings.child(ss.str().c_str()).child("reading").child_value()); struct tm tm; strptime(time_c.c_str(), "%Y-%m-%d %H:%M:%S", &tm); tm.tm_isdst = -1; // dst not set by strptime time_t t = mktime(&tm); add_reading(t, reading); ss.str(std::string()); } return num_readings; }
int Device::process_confirm_xml(pugi::xml_document &doc) { std::stringstream ss; ss << "Device " << uid << ": Parsing server message" << std::endl; log(ss.str()); ss.str(std::string()); pugi::xml_node mother_node = doc.first_child(); std::string msg_v = mother_node.child("msg_version").child_value(); if((strcmp(mother_node.name(), "server") != 0) || \ (strcmp(msg_v.c_str(), " 1.0") != 0)) { ss << "Device " << uid << ": Invalid message, parsing failed" << std::endl; log(ss.str()); return 0; } int uid_test = atoi(mother_node.child("uid").child_value()); if(uid == -1) update_uid(uid_test); std::string shutdown = mother_node.child("shut_down").child_value(); if(strcmp(shutdown.c_str(), "true") == 0) { std::cout << "Shutdown command received, shutting down." << std::endl; state = SHUTDOWN; save_readings(); } int num_readings = atoi(mother_node.child("n_readings").child_value()); pugi::xml_node readings = mother_node.child("readings"); int readings_removed = 0; for(int i = 0; i < num_readings; i++) { ss << "reading" << i; std::string time_c = readings.child(ss.str().c_str()).child("time").child_value(); struct tm tm; strptime(time_c.c_str(), "%Y-%m-%d %H:%M:%S", &tm); tm.tm_isdst = -1; // dst not set by strptime time_t t = mktime(&tm); if(rm_reading(t)) readings_removed++; ss.str(std::string()); } return readings_removed; }
static int db_chown(backend_store_interface* i, const char* rel_path, uid_t uid, gid_t gid) { logger_logf(LOG(i), "rel_path = %s, uid = %ld, gid = %ld", rel_path, uid, gid); ERR_IF_DOESNT_EXIST(i, rel_path); long owner = get_uid(rel_path); long you = fuse_get_context()->uid; if (owner != you) { logger_logf(LOG(i), "can't chown since you're not the owner. You are %ld, owner is %ld", you, owner); return -EACCES; } if (uid != -1) { update_uid(rel_path, uid); } if (gid != -1) { update_gid(rel_path, gid); } return 0; }