int
add_station ( Arr * networks, char * net, char * sta, Arr * sinfo )
{
    Arr * stations;
    Arr * sold;
    char * latency;

    if ( networks == NULL )
        networks = newarr( strcmp );

    if ( sold = get_station( networks, net, sta ) )
    {
        sinfo_update( sold, sinfo );
        clrarr( sinfo, pffree );
    }
    else
    {
        if ( get_stations( networks, net ) == NULL ) 
            add_network( networks, net );

        if ( !(stations = get_stations( networks, net ) ) ) return 0;
        setarr( stations, sta, create_pf( sinfo, PFARR ) );
    }

    return 1;
}
Esempio n. 2
0
int main(void) {
  char *ifname = getenv("QUERY_STRING");

  if (ifname == NULL)
    badrequest();

  if (!interface_is_valid(ifname))
    badrequest();

  const struct iwinfo_ops *iw = iwinfo_backend(ifname);

  if (iw == NULL)
    badrequest();

  printf("Access-Control-Allow-Origin: *\n");
  printf("Content-type: text/event-stream\n\n");

  while (true) {
    struct json_object *obj;
    obj = get_stations(iw, ifname);
    printf("data: %s\n\n", json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PLAIN));
    fflush(stdout);
    json_object_put(obj);
    usleep(150000);
  }

  return 0;
}
int
add_network ( Arr * networks, char * net )
{
    Arr * network;
    Arr * oldnet;

    if ( get_stations( networks, net ) ) return 0;

    network = newarr( strcmp );

    setarr( networks, net, create_pf( network, PFARR ) );
    setarr( network, STALIST, create_pf( newarr( strcmp ), PFARR) );
    
    return 1;
}
Arr *
get_station ( Arr * networks, char * net, char * sta )
{
    return ( getpf( get_stations( networks, net ), sta ) );
}