Changes between Version 2 and Version 3 of doc/developer/WiFiDog_V2

Show
Ignore:
Timestamp:
03/25/08 22:00:26 (14 years ago)
Author:
papril
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • doc/developer/WiFiDog_V2

    v2 v3  
    1313 * QoS support 
    1414 * Versioned and more standard protocol 
     15 * Better URLs (RESTful philosophy?) 
    1516 
    1617= Proposed architecture and ideas = 
     
    3940 * If it failed contacting the auth server twice, apply the "what to do when the internet is down" policy (either "allow" or "reject but explain what's going on") 
    4041 * When it receives the status from the auth server, it will also receive a list of "who's supposed to be connected". It will do a DIFF of this with what it has to remove/add who should be there 
     42 
     43== Things tested == 
     44 
     45=== JSON for protocol === 
     46XML or YAML would have been great, but I tried to use Syck (http://whytheluckystiff.net/syck/) and it didn't seem trivial to use, it looks like it supports a stream parser, we need something more like a DOM to find values returned. 
     47 
     48JSON (with json-c-0.7) gives us that in C and is quite elegant. 
     49 
     50Here's how we can generate JSON: 
     51{{{ 
     52struct json_object *status_object = json_object_new_object(); 
     53json_object_object_add(status_object, "wifidog_version", json_object_new_string(VERSION)); 
     54json_object_object_add(status_object, "protocol_version", json_object_new_double(2.0)); 
     55json_object_object_add(status_object, "node_id", json_object_new_string(node_id)); 
     56json_object_object_add(status_object, "fetch_config", json_object_new_boolean(1)); 
     57 
     58struct json_object *node_status_object = json_object_new_object(); 
     59json_object_object_add(node_status_object, "wifidog_uptime", json_object_new_int(25)); 
     60json_object_object_add(node_status_object, "sys_uptime", json_object_new_int(get_sys_uptime())); 
     61json_object_object_add(node_status_object, "sys_loadavg", json_object_new_double(get_sys_loadavg())); 
     62json_object_object_add(node_status_object, "sys_memfree", json_object_new_int(get_sys_memfree())); 
     63 
     64char * json = json_object_to_json_string(status_object); 
     65}}} 
     66 
     67It returns the JSON string. 
     68 
     69To parse: 
     70 
     71{{{ 
     72struct json_object * json_object = json_tokener_parse(the_string); 
     73struct json_object * value_json_object = json_object_object_get(json_object, "node_id"); 
     74printf("%s\n", json_object_get_string(value_json_object)); 
     75}}} 
     76 
     77This will retrieve the string value of "node_id" at the first level in the tree.