int client_loop(int sock) { int s; char buf[1024]; int r; char **args; ft_putstr("[client]-> "); s = read(0, buf, 1023); buf[s - 1] = '\0'; args = ft_strsplit(buf, ' '); if (!ft_strcmp(args[0], "quit")) return (1); write(sock, buf, s); if (!ft_strcmp(args[0], "get")) return (action_get(sock, args)); while ((r = recv(sock, buf, sizeof(buf), 0)) > 0) { buf[r] = '\0'; if (ft_strcmp(buf, END) == 0 || (ft_strcmp(buf, "") == 0)) break ; write(1, buf, r); } write(1, "\n", 1); return (0); }
int handle_request(char *recv_ip, char *in, int in_len, char *out, int *out_len, int http) { char *action, *msgid, *body; int action_len, msgid_len; action = get_tag_value(in, wsd_discovery, sizeof(wsd_discovery)-1, &action_len); if (!action) action = get_tag_value(in, wsd_transfer, sizeof(wsd_transfer)-1, &action_len); if (!action) { if (http) return action_get(0, out, out_len, http); return -1; } msgid = get_tag_value(in, wsd_msgid, sizeof(wsd_msgid)-1, &msgid_len); if (!msgid) return -1; body = strstr(in, wsd_body); if (!msgid) return -1; action[action_len] = 0; msgid[msgid_len] = 0; wsdd_log(LOG_INFO, "Action %s", action); if (strcmp(action, wsd_act_probe) == 0) return action_probe(recv_ip, msgid, body, out, out_len, http); if (strcmp(action, wsd_act_resolve) == 0) return action_resolve(recv_ip, msgid, body, out, out_len, http); if (strcmp(action, wsd_act_get) == 0) return action_get(msgid, out, out_len, http); return -1; }