97 lines
1.8 KiB
C
97 lines
1.8 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);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|