/* * Deals with the GET_SENSORS_REQ message */ static inline void handle_get_sensors_req(int fd) { int sensors_len; int sensors_count; char *sensors_list; thermal_get_sensors_resp_msg_t *msg; int len; len = sizeof(thermal_get_sensors_resp_msg_t); sensors_len = sensor_getlist(&sensors_list, &sensors_count); len += sensors_len; msg = (thermal_get_sensors_resp_msg_t *) malloc(len); if (msg == NULL) { ERR("unable to allocate memory\n"); free(sensors_list); return; } msg->msg.len = len; msg->msg.id = GET_SENSORS_RESP; msg->number_of_sensors = sensors_count; msg->sensors = ((char *) msg) + sizeof(thermal_get_sensors_resp_msg_t); memcpy(msg->sensors, sensors_list, sensors_len); INF("--> GET_SENSORS_RESP\n"); socket_send_msg(fd, (thermal_socket_msg_t *) msg); free(msg); free(sensors_list); }
/* * Deals with the GET_ACTIONS_REQ message */ static inline void handle_get_actions_req(int fd) { int actions_len; int actions_count; char *actions_list; thermal_get_actions_resp_msg_t *msg; int len; len = sizeof(thermal_get_actions_resp_msg_t); actions_len = actions_getlist(&actions_list, &actions_count); len += actions_len; msg = (thermal_get_actions_resp_msg_t *) malloc(len); if (msg == NULL) { ERR("unable to allocate memory\n"); free(actions_list); return; } msg->msg.len = len; msg->msg.id = GET_ACTIONS_RESP; msg->number_of_actions = actions_count; msg->actions = ((char *) msg) + sizeof(thermal_get_actions_resp_msg_t); memcpy(msg->actions, actions_list, actions_len); INF("--> GET_ACTIONS_RESP\n"); socket_send_msg(fd, (thermal_socket_msg_t *) msg); free(msg); free(actions_list); }
bool bot_hand_shake(struct bot *bot) { char buff[128]; int len; bool ret; ret = socket_send_msg(bot->socket, HELLO_MSG, strlen(HELLO_MSG)); if (ret == false) { DEBUG(LOG_DEFAULT, "send_msg handshake fail\n"); return false; } ret = socket_recv_line(bot->socket, buff, &len, sizeof(buff)); if (ret == false) { DEBUG(LOG_DEFAULT, "send_msg handshake fail\n"); return false; } if (bot_validate_server(bot, buff, len) == false) { DEBUG(LOG_DEFAULT, "Host validation fail\n"); return false; } DEBUG(LOG_DEFAULT, "hand shake success\n"); return true; }
int def_read(t_socket *soc, int cs) { int r; char buff[SOC_BUFF_SIZE]; if (soc->fds[cs].type != SOC_LOCAL) socket_on_read(soc, cs); else { r = socket_read(cs, &buff, SOC_BUFF_SIZE, soc); socket_send_msg(soc, cs, buff, r); } return (cs); }
void socket_event(thermal_notification_event_msg_t *msg) { socket_client_t *c; pthread_mutex_lock(&socket_clients_lock); DBG("--> THERMAL_NOTIFICATION_EVENT\n"); c = socket_clients; while (c != NULL) { socket_send_msg(c->fd, (thermal_socket_msg_t *) msg); c = c->next; } pthread_mutex_unlock(&socket_clients_lock); }
/* * Deals with the GET_SENSOR_CONFIG_REQ message */ static inline void handle_get_sensor_config_req(int fd, thermal_get_sensor_config_req_msg_t *inmsg) { thermal_get_sensor_config_resp_msg_t *msg; int len; inmsg->sensor = ((char *) inmsg) + sizeof(thermal_get_sensor_config_req_msg_t); INF("requesting configuration for sensor \"%s\"\n", inmsg->sensor); len = sensor_getsensorresp(inmsg->sensor, &msg); if (len == 0) { ERR("failed to find sensor config\n"); return; } INF("--> GET_SENSOR_CONFIG_RESP\n"); socket_send_msg(fd, (thermal_socket_msg_t *) msg); free(msg); }