Files
aqhomecontrol/aqhome/http/urlhandler.c

112 lines
2.0 KiB
C

/****************************************************************************
* 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);
}
}
AQH_HTTP_CONTENT *AQH_UrlHandler_GetContentProvider(const AQH_URLHANDLER *uh)
{
return uh?uh->httpContentProvider:NULL;
}
void AQH_UrlHandler_SetContentProvider(AQH_URLHANDLER *uh, AQH_HTTP_CONTENT *cp)
{
if (uh)
uh->httpContentProvider=cp;
}
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;
}