started working on storage service.
This commit is contained in:
@@ -46,11 +46,13 @@
|
||||
|
||||
<headers dist="true" install="$(pkgincludedir)/http" >
|
||||
endpoint_http.h
|
||||
urlhandler.h
|
||||
</headers>
|
||||
|
||||
|
||||
<headers dist="true" >
|
||||
endpoint_http_p.h
|
||||
urlhandler_p.h
|
||||
</headers>
|
||||
|
||||
|
||||
@@ -58,6 +60,7 @@
|
||||
$(local/typefiles)
|
||||
|
||||
endpoint_http.c
|
||||
urlhandler.c
|
||||
</sources>
|
||||
|
||||
|
||||
|
||||
96
aqhome/http/urlhandler.c
Normal file
96
aqhome/http/urlhandler.c
Normal file
@@ -0,0 +1,96 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2023 Martin Preuss, all rights reserved.
|
||||
*
|
||||
* The license for this file can be found in the file COPYING which you
|
||||
* should have received along with this file.
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include "./urlhandler_p.h"
|
||||
|
||||
#include <gwenhywfar/debug.h>
|
||||
#include <gwenhywfar/misc.h>
|
||||
#include <gwenhywfar/text.h>
|
||||
|
||||
|
||||
|
||||
|
||||
GWEN_INHERIT_FUNCTIONS(AQH_URLHANDLER)
|
||||
GWEN_LIST_FUNCTIONS(AQH_URLHANDLER, AQH_UrlHandler)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
AQH_URLHANDLER *AQH_UrlHandler_new(void)
|
||||
{
|
||||
AQH_URLHANDLER *uh;
|
||||
|
||||
GWEN_NEW_OBJECT(AQH_URLHANDLER, uh);
|
||||
GWEN_INHERIT_INIT(AQH_URLHANDLER, uh);
|
||||
uh->urlPatternList=GWEN_StringList_new();
|
||||
|
||||
return uh;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_UrlHandler_free(AQH_URLHANDLER *uh)
|
||||
{
|
||||
if (uh) {
|
||||
GWEN_INHERIT_FINI(AQH_URLHANDLER, uh);
|
||||
GWEN_StringList_free(uh->urlPatternList);
|
||||
GWEN_FREE_OBJECT(uh);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_UrlHandler_AddUrlPattern(AQH_URLHANDLER *uh, const char *s)
|
||||
{
|
||||
if (uh && s && *s)
|
||||
GWEN_StringList_AppendString(uh->urlPatternList, s, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int AQH_UrlHandler_UrlMatches(const AQH_URLHANDLER *uh, const char *s)
|
||||
{
|
||||
if (uh && s && *s) {
|
||||
GWEN_STRINGLISTENTRY *se;
|
||||
|
||||
se=GWEN_StringList_FirstEntry(uh->urlPatternList);
|
||||
while(se) {
|
||||
const char *pattern;
|
||||
|
||||
pattern=GWEN_StringListEntry_Data(se);
|
||||
if (GWEN_Text_ComparePattern(s, pattern, 0)!=-1)
|
||||
return 1;
|
||||
se=GWEN_StringListEntry_Next(se);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
GWEN_MSG *AQH_UrlHandler_HandleMessage(AQH_URLHANDLER *uh, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msgReceived)
|
||||
{
|
||||
if (uh && uh->handleFn)
|
||||
return uh->handleFn(uh, ep, msgReceived);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
43
aqhome/http/urlhandler.h
Normal file
43
aqhome/http/urlhandler.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2023 Martin Preuss, all rights reserved.
|
||||
*
|
||||
* The license for this file can be found in the file COPYING which you
|
||||
* should have received along with this file.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef AQHOME_URLHANDLER_H
|
||||
#define AQHOME_URLHANDLER_H
|
||||
|
||||
#include <aqhome/api.h>
|
||||
|
||||
#include <gwenhywfar/inherit.h>
|
||||
#include <gwenhywfar/stringlist.h>
|
||||
#include <gwenhywfar/endpoint.h>
|
||||
#include <gwenhywfar/msg.h>
|
||||
|
||||
|
||||
|
||||
typedef struct AQH_URLHANDLER AQH_URLHANDLER;
|
||||
GWEN_INHERIT_FUNCTION_LIB_DEFS(AQH_URLHANDLER, AQHOME_API)
|
||||
GWEN_LIST_FUNCTION_LIB_DEFS(AQH_URLHANDLER, AQH_UrlHandler, AQHOME_API)
|
||||
|
||||
|
||||
|
||||
typedef GWEN_MSG*(*AQH_URLHANDLER_HANDLE_FN)(AQH_URLHANDLER *uh, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msgReceived);
|
||||
|
||||
|
||||
AQHOME_API AQH_URLHANDLER *AQH_UrlHandler_new(void);
|
||||
AQHOME_API void AQH_UrlHandler_free(AQH_URLHANDLER *uh);
|
||||
|
||||
AQHOME_API void AQH_UrlHandler_AddUrlPattern(AQH_URLHANDLER *uh, const char *s);
|
||||
AQHOME_API int AQH_UrlHandler_UrlMatches(const AQH_URLHANDLER *uh, const char *s);
|
||||
|
||||
AQHOME_API GWEN_MSG *AQH_UrlHandler_HandleMessage(AQH_URLHANDLER *uh, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msgReceived);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
27
aqhome/http/urlhandler_p.h
Normal file
27
aqhome/http/urlhandler_p.h
Normal file
@@ -0,0 +1,27 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2023 Martin Preuss, all rights reserved.
|
||||
*
|
||||
* The license for this file can be found in the file COPYING which you
|
||||
* should have received along with this file.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef AQHOME_URLHANDLER_P_H
|
||||
#define AQHOME_URLHANDLER_P_H
|
||||
|
||||
|
||||
#include "aqhome/http/urlhandler.h"
|
||||
|
||||
|
||||
struct AQH_URLHANDLER {
|
||||
GWEN_INHERIT_ELEMENT(AQH_URLHANDLER);
|
||||
GWEN_LIST_ELEMENT(AQH_URLHANDLER);
|
||||
|
||||
GWEN_STRINGLIST *urlPatternList;
|
||||
AQH_URLHANDLER_HANDLE_FN handleFn;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user