Added verify to http api
This commit is contained in:
@@ -78,7 +78,7 @@ stbbr_last_received(char *stanza)
|
|||||||
int
|
int
|
||||||
stbbr_received(char *stanza)
|
stbbr_received(char *stanza)
|
||||||
{
|
{
|
||||||
return verify_any(stanza);
|
return verify_any(stanza, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -34,6 +34,7 @@
|
|||||||
#include "server/log.h"
|
#include "server/log.h"
|
||||||
#include "server/server.h"
|
#include "server/server.h"
|
||||||
#include "server/prime.h"
|
#include "server/prime.h"
|
||||||
|
#include "server/verify.h"
|
||||||
|
|
||||||
struct MHD_Daemon *httpdaemmon = NULL;
|
struct MHD_Daemon *httpdaemmon = NULL;
|
||||||
|
|
||||||
@@ -42,7 +43,8 @@ struct MHD_Daemon *httpdaemmon = NULL;
|
|||||||
typedef enum {
|
typedef enum {
|
||||||
STBBR_OP_UNKNOWN,
|
STBBR_OP_UNKNOWN,
|
||||||
STBBR_OP_SEND,
|
STBBR_OP_SEND,
|
||||||
STBBR_OP_FOR
|
STBBR_OP_FOR,
|
||||||
|
STBBR_OP_VERIFY
|
||||||
} stbbr_op_t;
|
} stbbr_op_t;
|
||||||
|
|
||||||
typedef struct conn_info_t {
|
typedef struct conn_info_t {
|
||||||
@@ -99,6 +101,8 @@ int connection_cb(void* cls, struct MHD_Connection* conn, const char* url, const
|
|||||||
con_info->stbbr_op = STBBR_OP_SEND;
|
con_info->stbbr_op = STBBR_OP_SEND;
|
||||||
} else if (g_strcmp0(method, "POST") == 0 && g_strcmp0(url, "/for") == 0) {
|
} else if (g_strcmp0(method, "POST") == 0 && g_strcmp0(url, "/for") == 0) {
|
||||||
con_info->stbbr_op = STBBR_OP_FOR;
|
con_info->stbbr_op = STBBR_OP_FOR;
|
||||||
|
} else if (g_strcmp0(method, "POST") == 0 && g_strcmp0(url, "/verify") == 0) {
|
||||||
|
con_info->stbbr_op = STBBR_OP_VERIFY;
|
||||||
} else {
|
} else {
|
||||||
con_info->stbbr_op = STBBR_OP_UNKNOWN;
|
con_info->stbbr_op = STBBR_OP_UNKNOWN;
|
||||||
return send_response(conn, NULL, MHD_HTTP_BAD_REQUEST);
|
return send_response(conn, NULL, MHD_HTTP_BAD_REQUEST);
|
||||||
@@ -121,32 +125,44 @@ int connection_cb(void* cls, struct MHD_Connection* conn, const char* url, const
|
|||||||
const char *query = NULL;
|
const char *query = NULL;
|
||||||
|
|
||||||
switch (con_info->stbbr_op) {
|
switch (con_info->stbbr_op) {
|
||||||
|
case STBBR_OP_SEND:
|
||||||
|
{
|
||||||
|
server_send(con_info->body->str);
|
||||||
|
return send_response(conn, NULL, MHD_HTTP_OK);
|
||||||
|
}
|
||||||
|
case STBBR_OP_FOR:
|
||||||
|
{
|
||||||
|
id = MHD_lookup_connection_value(conn, MHD_GET_ARGUMENT_KIND, "id");
|
||||||
|
query = MHD_lookup_connection_value(conn, MHD_GET_ARGUMENT_KIND, "query");
|
||||||
|
if (id && query) {
|
||||||
|
return send_response(conn, NULL, MHD_HTTP_BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
case STBBR_OP_SEND:
|
if (id) {
|
||||||
server_send(con_info->body->str);
|
prime_for_id(id, con_info->body->str);
|
||||||
return send_response(conn, NULL, MHD_HTTP_OK);
|
return send_response(conn, NULL, MHD_HTTP_CREATED);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (query) {
|
||||||
|
prime_for_query(query, con_info->body->str);
|
||||||
|
return send_response(conn, NULL, MHD_HTTP_CREATED);
|
||||||
|
}
|
||||||
|
|
||||||
case STBBR_OP_FOR:
|
|
||||||
id = MHD_lookup_connection_value(conn, MHD_GET_ARGUMENT_KIND, "id");
|
|
||||||
query = MHD_lookup_connection_value(conn, MHD_GET_ARGUMENT_KIND, "query");
|
|
||||||
if (id && query) {
|
|
||||||
return send_response(conn, NULL, MHD_HTTP_BAD_REQUEST);
|
return send_response(conn, NULL, MHD_HTTP_BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
case STBBR_OP_VERIFY:
|
||||||
if (id) {
|
{
|
||||||
prime_for_id(id, con_info->body->str);
|
int res = verify_any(con_info->body->str, TRUE);
|
||||||
return send_response(conn, NULL, MHD_HTTP_CREATED);
|
if (res) {
|
||||||
|
return send_response(conn, "true", MHD_HTTP_OK);
|
||||||
|
} else {
|
||||||
|
return send_response(conn, "false", MHD_HTTP_OK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
if (query) {
|
{
|
||||||
prime_for_query(query, con_info->body->str);
|
return send_response(conn, NULL, MHD_HTTP_BAD_REQUEST);
|
||||||
return send_response(conn, NULL, MHD_HTTP_CREATED);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return send_response(conn, NULL, MHD_HTTP_BAD_REQUEST);
|
|
||||||
|
|
||||||
default:
|
|
||||||
return send_response(conn, NULL, MHD_HTTP_BAD_REQUEST);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,12 +44,12 @@ verify_set_timeout(int seconds)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
verify_any(char *stanza_text)
|
verify_any(char *stanza_text, gboolean ign_timeout)
|
||||||
{
|
{
|
||||||
XMPPStanza *stanza = stanza_parse(stanza_text);
|
XMPPStanza *stanza = stanza_parse(stanza_text);
|
||||||
|
|
||||||
int result = 0;
|
int result = 0;
|
||||||
if (timeoutsecs <= 0) {
|
if (timeoutsecs <= 0 || ign_timeout) {
|
||||||
result = stanzas_verify_any(stanza);
|
result = stanzas_verify_any(stanza);
|
||||||
} else {
|
} else {
|
||||||
double elapsed = 0.0;
|
double elapsed = 0.0;
|
||||||
|
|||||||
@@ -25,6 +25,6 @@
|
|||||||
|
|
||||||
void verify_set_timeout(int seconds);
|
void verify_set_timeout(int seconds);
|
||||||
int verify_last(char *stanza);
|
int verify_last(char *stanza);
|
||||||
int verify_any(char *stanza);
|
int verify_any(char *stanza, gboolean ign_timeout);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user