aqhome: more work on http endpoint.
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
#include "aqhome/mqtt/msg_mqtt_pubresponse.h"
|
||||
#include "aqhome/mqtt/msg_mqtt_subscribe.h"
|
||||
#include "aqhome/mqtt/msg_mqtt_suback.h"
|
||||
#include "aqhome/http/endpoint_http.h"
|
||||
#include "aqhome/hexfile/hexfile.h"
|
||||
#include "aqhome/hexfile/flashrecord.h"
|
||||
|
||||
@@ -23,6 +24,8 @@
|
||||
#include <gwenhywfar/text.h>
|
||||
#include <gwenhywfar/gwentime.h>
|
||||
#include <gwenhywfar/buffer.h>
|
||||
#include <gwenhywfar/endpoint_tcpd.h>
|
||||
#include <gwenhywfar/endpoint_msgio.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
@@ -244,6 +247,73 @@ GWEN_MSG *_awaitPacket2(GWEN_MSG_ENDPOINT *epClient, uint8_t expectedPacketType)
|
||||
|
||||
|
||||
|
||||
GWEN_MSG_ENDPOINT *_acceptHttpConnection(GWEN_UNUSED GWEN_MSG_ENDPOINT *ep,
|
||||
GWEN_SOCKET *sk,
|
||||
GWEN_UNUSED const GWEN_INETADDRESS *addr,
|
||||
GWEN_UNUSED void *data)
|
||||
{
|
||||
GWEN_MSG_ENDPOINT *epIncoming;
|
||||
|
||||
DBG_INFO(GWEN_LOGDOMAIN, "Incoming connection");
|
||||
//epIncoming=GWEN_IpcEndpoint_CreateIpcTcpServiceForSocket(sk, NULL, 1);
|
||||
epIncoming=GWEN_MsgEndpoint_new("HTTP-Service", 0);
|
||||
GWEN_MsgEndpoint_SetSocket(epIncoming, sk);
|
||||
GWEN_MsgIoEndpoint_Extend(epIncoming);
|
||||
AQH_HttpEndpoint_Extend(epIncoming, AQH_ENDPOINT_HTTP_FLAGS_PASSIVE);
|
||||
return epIncoming;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int testHttpDaemon()
|
||||
{
|
||||
GWEN_MSG_ENDPOINT *epServer;
|
||||
int loop;
|
||||
|
||||
AQH_Init();
|
||||
epServer=GWEN_TcpdEndpoint_new("127.0.0.1", 55556, NULL, 1);
|
||||
GWEN_TcpdEndpoint_SetAcceptFn(epServer, _acceptHttpConnection, NULL);
|
||||
|
||||
for (loop=0;; loop++) {
|
||||
GWEN_MSG_ENDPOINT *ep;
|
||||
|
||||
DBG_INFO(GWEN_LOGDOMAIN, "Loop %d:", loop);
|
||||
GWEN_MsgEndpoint_IoLoop(epServer, 2000); /* 2000 ms */
|
||||
ep=GWEN_MsgEndpoint_Tree2_GetFirstChild(epServer);
|
||||
while(ep) {
|
||||
GWEN_MSG *msg;
|
||||
|
||||
DBG_INFO(GWEN_LOGDOMAIN, "- Checking endpoint");
|
||||
while( (msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(ep)) ) {
|
||||
GWEN_DB_NODE *db;
|
||||
GWEN_BUFFER *buf;
|
||||
GWEN_MSG *msgOut;
|
||||
|
||||
DBG_INFO(GWEN_LOGDOMAIN, " - received msg");
|
||||
db=GWEN_Msg_GetDbParsedInfo(msg);
|
||||
if (db)
|
||||
GWEN_DB_Dump(db, 2);
|
||||
|
||||
buf=GWEN_Buffer_new(0, 256, 0, 1);
|
||||
GWEN_Buffer_AppendString(buf, "HTTP/1.1 200 Okay\r\n");
|
||||
GWEN_Buffer_AppendString(buf, "Connection: close\r\n");
|
||||
GWEN_Buffer_AppendString(buf, "Content-length: 23\r\n");
|
||||
GWEN_Buffer_AppendString(buf, "\r\n");
|
||||
GWEN_Buffer_AppendString(buf, "This is a test string\r\n");
|
||||
msgOut=GWEN_Msg_fromBytes((const uint8_t*)GWEN_Buffer_GetStart(buf), GWEN_Buffer_GetUsedBytes(buf));
|
||||
GWEN_Buffer_free(buf);
|
||||
GWEN_MsgEndpoint_AddSendMessage(ep, msgOut);
|
||||
GWEN_Msg_free(msg);
|
||||
} /* while */
|
||||
ep=GWEN_MsgEndpoint_Tree2_GetNext(ep);
|
||||
}
|
||||
GWEN_MsgEndpoint_RemoveUnconnectedAndEmptyChildren(epServer);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int testHexfile(int argc, char **argv)
|
||||
{
|
||||
const char *inFilename;
|
||||
@@ -350,7 +420,8 @@ int main(int argc, char **argv)
|
||||
//return testHexfile(argc, argv);
|
||||
//return testFlashRecords(argc, argv);
|
||||
//return testMqttConnection2();
|
||||
return testMqttSubscribe2(argc, argv);
|
||||
//return testMqttSubscribe2(argc, argv);
|
||||
return testHttpDaemon();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user