void Peers::add_stations() { char reply[2048]; size_t reply_len; char cmd[30]; int res; reply_len = sizeof(reply) - 1; if (wpagui->ctrlRequest("STA-FIRST", reply, &reply_len) < 0) return; do { reply[reply_len] = '\0'; QString info(reply); char *txt = reply; while (*txt != '\0' && *txt != '\n') txt++; *txt++ = '\0'; if (strncmp(reply, "FAIL", 4) == 0 || strncmp(reply, "UNKNOWN", 7) == 0) break; add_station(info); reply_len = sizeof(reply) - 1; snprintf(cmd, sizeof(cmd), "STA-NEXT %s", reply); res = wpagui->ctrlRequest(cmd, reply, &reply_len); } while (res >= 0); }
static void read_gp(FILE *file) { char buf[100]; int x, y, d; int n; int this, last = -1; while (fgets(buf, sizeof(buf), stdin)) { n = sscanf(buf, "#STATION %d %d", &x, &y); if (n == 2) { add_station(x, y); continue; } if (!strcmp(buf, "\n")) { last = -1; continue; } n = sscanf(buf, "%d %d %d", &x, &y, &d); if (n != 3) continue; this = add_node(x, y, d); if (last == -1) { last = this; } else { add_edge(last, this); last = -1; } } }
void try_add_station(struct dect_station * station) { struct dect_station * p = cli.station_list; int found = 0; while (p) { if (!memcmp(p->RFPI, station->RFPI, 5)) { if (p->type == station->type) { if ( (p->channel != station->channel) && (cli.verbose) ) { int i; LOG("### station"); for (i=0; i<5; i++) LOG(" %.2x", station->RFPI[i]); LOG(" switched from channel %d to channel %d\n", p->channel, station->channel); } found = 1; p->channel = station->channel; p->count_seen++; p->last_seen = time(NULL); p->RSSI += station->RSSI; /* we avg on dump */ } } p = p->next; } if (!found) add_station(station); if (cli.autorec && (cli.mode != MODE_PPSCAN)) { if (rfpi_is_ignored(station->RFPI)) { if (cli.verbose) { LOG("### skipping ignored RFPI %.2x %.2x %.2x %.2x %.2x\n", station->RFPI[0], station->RFPI[1], station->RFPI[2], station->RFPI[3], station->RFPI[4]); } } else { do_ppscan(station->RFPI); } } }
void Peers::add_single_station(const char *addr) { char reply[2048]; size_t reply_len; char cmd[30]; reply_len = sizeof(reply) - 1; snprintf(cmd, sizeof(cmd), "STA %s", addr); if (wpagui->ctrlRequest(cmd, reply, &reply_len) < 0) return; reply[reply_len] = '\0'; QString info(reply); char *txt = reply; while (*txt != '\0' && *txt != '\n') txt++; *txt++ = '\0'; if (strncmp(reply, "FAIL", 4) == 0 || strncmp(reply, "UNKNOWN", 7) == 0) return; add_station(info); }
void handle_client(conn_t *conn) { conn->user = NULL; for(; ;) { request_t *rqst = parse_args(conn->input); if(rqst != NULL) { if(IS_PROTOCOL(rqst, P_LOGIN)) { if(login(rqst->argv[1], rqst->argv[2]) == 0) { conn->user = (t_user*) malloc(sizeof(t_user)); memcpy(conn->user, find_user_by_id(rqst->argv[1]), sizeof(t_user)); simple_response(0, conn); } else { simple_response(1, conn); } } else if(IS_PROTOCOL(rqst, P_SIGNUP)) { if(signup(rqst->argv[1], rqst->argv[2]) == 0 ) { simple_response(0, conn); } else { simple_response(1, conn); } } else if(IS_PROTOCOL(rqst, P_EXIT)) { simple_response(0, conn); return; } else if(conn->user != NULL) { //authorized user if(IS_PROTOCOL(rqst, P_BUY)) { if(buy(conn->user->id, rqst->argv[1]) == 0) { simple_response(0, conn); } else { simple_response(1, conn); } } else if(IS_PROTOCOL(rqst, P_QUERY)) { t_ticket_list *list = query(rqst->argv[1], rqst->argv[2]); write(conn->dfd, "*", 1); char *tmp = ltoa(list->num); int tmplen = strlen(tmp); write(conn->dfd, tmp, tmplen); write(conn->dfd, CRLF, CLLEN); free(tmp); tmp = ltoa(sizeof(t_ticket)); tmplen = strlen(tmp); int i; for (i = 0; i < list->num; ++i) { write(conn->dfd, "?", 1); write(conn->dfd, tmp, tmplen); write(conn->dfd, CRLF, CLLEN); write(conn->dfd, &list->data[i], sizeof(t_ticket)); } free(tmp); } else if(IS_PROTOCOL(rqst, P_USER_INFO)) { char *tmp = ltoa(sizeof(t_user)); int tmplen = strlen(tmp); write(conn->dfd, "?", 1); write(conn->dfd, tmp, tmplen); write(conn->dfd, CRLF, CLLEN); write(conn->dfd, conn->user, sizeof(t_user)); } else if(IS_PROTOCOL(rqst, P_USER_UPD)) { if(update_user_info(conn->user->id, rqst->argv[1], rqst->argv[2], rqst->argv[3]) == 0) { memcpy(conn->user, find_user_by_id(conn->user->id), sizeof(t_user)); simple_response(0, conn); } else { simple_response(1, conn); } } else if(IS_PROTOCOL(rqst, P_QUERY_BUY)) { t_ticket_list *list = query_buy(conn->user->id); write(conn->dfd, "*", 1); char *tmp = ltoa(list->num); int tmplen = strlen(tmp); write(conn->dfd, tmp, tmplen); write(conn->dfd, CRLF, CLLEN); free(tmp); tmp = ltoa(sizeof(t_ticket)); tmplen = strlen(tmp); int i; for (i = 0; i < list->num; ++i) { write(conn->dfd, "?", 1); write(conn->dfd, tmp, tmplen); write(conn->dfd, CRLF, CLLEN); write(conn->dfd, &list->data[i], sizeof(t_ticket)); } free(tmp); } else if(IS_PROTOCOL(rqst, P_REFUND)) { if(refund(conn->user->id, rqst->argv[1]) == 0) { simple_response(0, conn); } else { simple_response(1, conn); } } else if(IS_PROTOCOL(rqst, P_TICKET) && conn->user->type == 1) { t_ticket *tkt = load_ticket(rqst->argv[1]); if(tkt == NULL) { simple_response(1, conn); } else { char *tmp = ltoa(sizeof(t_ticket)); write(conn->dfd, "?", 1); write(conn->dfd, tmp, strlen(tmp));write(conn->dfd, CRLF, CLLEN); write(conn->dfd, tkt, sizeof(t_ticket)); free(tmp); } } else if(IS_PROTOCOL(rqst, P_TKT_UPDATE) && conn->user->type == 1) { if(add_update_ticket(rqst->argv[1], rqst->argv[2], rqst->argv[3], rqst->argv[4], rqst->argv[5], rqst->argv[6], rqst->argv[7], rqst->argv[8], rqst->argv[9] ) == 0) { simple_response(0, conn); } else { simple_response(1, conn); } } else if(IS_PROTOCOL(rqst, P_STN_ADD) && conn->user->type == 1) { if(add_station(rqst->argv[1]) == 0) { simple_response(0, conn); } else { simple_response(1, conn); } } else if(IS_PROTOCOL(rqst, P_STN_DEL) && conn->user->type == 1) { if(del_station(rqst->argv[1]) == 0) { simple_response(0, conn); } else { simple_response(1, conn); } } else if(IS_PROTOCOL(rqst, P_STN_ALL) && conn->user->type == 1) { t_station_list *list = all_station(); write(conn->dfd, "*", 1); char *tmp = ltoa(list->num); int tmplen = strlen(tmp); write(conn->dfd, tmp, tmplen); write(conn->dfd, CRLF, CLLEN); free(tmp); tmp = ltoa(sizeof(t_station)); tmplen = strlen(tmp); int i; for (i = 0; i < list->num; ++i) { write(conn->dfd, "?", 1); write(conn->dfd, tmp, tmplen); write(conn->dfd, CRLF, CLLEN); write(conn->dfd, &list->data[i], sizeof(t_station)); } free(tmp); } } else { simple_response(1, conn); } } } }