[UDP-HTTP] Handle new request "ReadResults"
This commit is contained in:
parent
73494defe6
commit
adc05b98c0
|
@ -14,7 +14,29 @@
|
|||
* Only the last result read from the positioning server, for each
|
||||
* mobile, is memorised and provided to the HTTP client.
|
||||
*
|
||||
* The only HTTP request currently implemented is "ReadSimpleResults".
|
||||
* The HTTP requests currently implemented are listed bellow.
|
||||
*
|
||||
* ** Request "ReadResults" **
|
||||
* Answer in case of error:
|
||||
* Results;NOK;Explanation
|
||||
* Normal answer:
|
||||
* Results;OK;Nb_results;Result_1;…;Result_n
|
||||
* Nb_results is the number of results in the answer (number of mobiles).
|
||||
* Result_i follows this format:
|
||||
* Mobile_MAC;Request_type;Request_timestamp;Nb_algo;Algo_1;…;Algo_n
|
||||
* Nb_algo is the number of algorithms in the result.
|
||||
* Algo_i follows this format:
|
||||
* Algorithm_name;X;Y;Z;Error;Area_name
|
||||
* Error is the distance from the true coordinates of the mobile, if
|
||||
* known; if unknown, Error is set to -1.
|
||||
* Area_name is the name of the area or room in which the mobile is (may
|
||||
* be empty).
|
||||
*
|
||||
* ** Unknown request **
|
||||
* If a unknown request is received, the answer format is:
|
||||
* UnknownRequest;NOK
|
||||
*
|
||||
* ** Request "ReadSimpleResults" **
|
||||
* Answer in case of error:
|
||||
* SimpleResults;NOK;Explanation
|
||||
* Normal answer:
|
||||
|
@ -24,9 +46,6 @@
|
|||
* Mobile_MAC;X;Y;Z;Area_name
|
||||
* Area_name is the name of the area or room in which the mobile is (may
|
||||
* be empty).
|
||||
*
|
||||
* If a unknown request is received, the answer format is:
|
||||
* UnknownRequest;NOK
|
||||
*/
|
||||
|
||||
#include "owlps-udp-to-http.h"
|
||||
|
@ -293,6 +312,14 @@ extract_request_from_message(char client_request[CLIENT_REQUEST_STRLEN],
|
|||
return SIMPLE_RESULTS_ID ;
|
||||
}
|
||||
|
||||
if (strncmp(RESULTS_REQUEST, token,
|
||||
strlen(RESULTS_REQUEST)) == 0)
|
||||
{
|
||||
strncpy(client_request, RESULTS_REQUEST,
|
||||
CLIENT_REQUEST_STRLEN) ;
|
||||
return RESULTS_ID ;
|
||||
}
|
||||
|
||||
return 0 ; // No known request found
|
||||
}
|
||||
|
||||
|
@ -307,6 +334,56 @@ void prepare_answer(int request_id)
|
|||
|
||||
switch (request_id)
|
||||
{
|
||||
case RESULTS_ID:
|
||||
strncpy(answer + answer_strlen, RESULTS_ANSWER,
|
||||
strlen(RESULTS_ANSWER)) ;
|
||||
answer_strlen += strlen(RESULTS_ANSWER) ;
|
||||
|
||||
sem_wait(&lock_results) ;
|
||||
|
||||
if (! results)
|
||||
{
|
||||
char answer_end[] = ";NOK;NoResult" ;
|
||||
strncpy(answer + answer_strlen, answer_end,
|
||||
strlen(answer_end)) ;
|
||||
answer_strlen += strlen(answer_end) ;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
results_list *result ;
|
||||
char answer_begin[10] ;
|
||||
size_t answer_begin_len ;
|
||||
|
||||
snprintf(answer_begin, 10, ";OK;%u", nb_results) ;
|
||||
answer_begin_len = strlen(answer_begin) ;
|
||||
strncpy(answer + answer_strlen, answer_begin,
|
||||
answer_begin_len) ;
|
||||
answer_strlen += answer_begin_len ;
|
||||
|
||||
realloc_answer(answer_strlen +
|
||||
nb_results * OWL_CSV_RESULT_STRLEN) ;
|
||||
|
||||
result = results ;
|
||||
while (result != NULL)
|
||||
{
|
||||
char result_str[OWL_CSV_RESULT_STRLEN] ;
|
||||
size_t result_len ;
|
||||
owl_result_to_csv(result_str, result->result) ;
|
||||
result_len = strlen(result_str) ;
|
||||
answer[answer_strlen++] = ';' ;
|
||||
assert(answer_strlen<answer_buflen) ;
|
||||
strncpy(answer + answer_strlen, result_str,
|
||||
result_len) ;
|
||||
answer_strlen += result_len ;
|
||||
result = result->next ;
|
||||
}
|
||||
}
|
||||
|
||||
sem_post(&lock_results) ;
|
||||
|
||||
break ;
|
||||
|
||||
case SIMPLE_RESULTS_ID:
|
||||
strncpy(answer + answer_strlen, SIMPLE_RESULTS_ANSWER,
|
||||
strlen(SIMPLE_RESULTS_ANSWER)) ;
|
||||
|
|
|
@ -7,10 +7,13 @@
|
|||
#define NB_CONNECTIONS 1
|
||||
#define CLIENT_MESSAGE_STRLEN 2500
|
||||
|
||||
#define CLIENT_REQUEST_STRLEN 21
|
||||
#define SIMPLE_RESULTS_ID 1
|
||||
#define SIMPLE_RESULTS_REQUEST "ReadSimpleResults"
|
||||
#define SIMPLE_RESULTS_ANSWER "SimpleResults"
|
||||
#define CLIENT_REQUEST_STRLEN 21
|
||||
#define RESULTS_ID 2
|
||||
#define RESULTS_REQUEST "ReadResults"
|
||||
#define RESULTS_ANSWER "Results"
|
||||
|
||||
#ifndef OWLPS_VERSION
|
||||
# define OWLPS_VERSION "unknown version"
|
||||
|
|
Loading…
Reference in New Issue