Esempio n. 1
0
void ListSort(ListNode *List, void *Data, int (*LessThanFunc)(void *, void *, void *))
{
    ListNode *Curr=NULL, *Prev=NULL;
    int sorted=0;

    while (! sorted)
    {
        sorted=1;
        Prev=NULL;
        Curr=ListGetNext(List);
        while (Curr)
        {
            if (Prev !=NULL)
            {
                if ( (*LessThanFunc)(Data,Curr->Item,Prev->Item) )
                {
                    sorted=0;
                    ListSwapItems(Prev,Curr);
                }
            }
            Prev=Curr;
            Curr=ListGetNext(Curr);
        }
    }

}
Esempio n. 2
0
int HTTPServerActivateSSL(HTTPSession *Session,ListNode *Keys)
{
ListNode *Curr;
int Flags=0;

Curr=ListGetNext(Keys);
while (Curr)
{
STREAMSetValue(Session->S,Curr->Tag,(char *) Curr->Item);
Curr=ListGetNext(Curr);
}

Flags |= LU_SSL_PFS;
if (Settings.AuthFlags & (FLAG_AUTH_CERT_REQUIRED | FLAG_AUTH_CERT_SUFFICIENT | FLAG_AUTH_CERT_ASK)) Flags |= LU_SSL_VERIFY_PEER;

if (DoSSLServerNegotiation(Session->S,Flags))
{
	Session->Flags |= HTTP_SSL;
	return(TRUE);
}


LogToFile(Settings.LogPath,"ERROR: SSL negotiation failed with %s %s. Error was %s",Session->ClientHost,Session->ClientIP,STREAMGetValue(Session->S,"SSL-Error"));
return(FALSE);
}
Esempio n. 3
0
int OAuthParseReply(OAUTH *Ctx, const char *ContentType, const char *Reply)
{
    ListNode *P=NULL, *Curr=NULL;
    const char *ptr;

    if (! StrValid(ContentType)) return(FALSE);
    if (! StrValid(Reply)) return(FALSE);


    P=ParserParseDocument(ContentType, Reply);
    Curr=ListGetNext(P);
    while (Curr)
    {
        SetVar(Ctx->Vars, Curr->Tag, (char *) Curr->Item);
        Curr=ListGetNext(Curr);
    }

    ptr=ParserGetValue(P, "access_token");
    if (StrValid(ptr)) Ctx->AccessToken=CopyStr(Ctx->AccessToken, ptr);

    ptr=ParserGetValue(P, "refresh_token");
    if (StrValid(ptr)) Ctx->RefreshToken=CopyStr(Ctx->RefreshToken, ptr);

    Ctx->VerifyCode=CopyStr(Ctx->VerifyCode, ParserGetValue(P, "user_code"));
    Ctx->VerifyURL=CopyStr(Ctx->VerifyURL, ParserGetValue(P, "verification_url"));

    ParserItemsDestroy(P);

    return(TRUE);
}
Esempio n. 4
0
char *FindScriptHandlerForScript(char *RetStr, const char *ScriptPath)
{
char *Handler=NULL, *ptr;
ListNode *Curr;

ptr=strrchr(ScriptPath,'.');

Handler=CopyStr(RetStr,"");
if (ptr)
{
  Curr=ListGetNext(Settings.ScriptHandlers);
  while (Curr)
  {
    if (
        (strcmp(Curr->Tag,ptr)==0) ||
        (strcmp(Curr->Tag,ptr+1)==0)
      )
    {
      Handler=CopyStr(Handler,(char *) Curr->Item);
      break;
    }
    Curr=ListGetNext(Curr);
  }
}

return(Handler);
}
Esempio n. 5
0
void *IndexArrayOnList(ListNode *ListHead)
{
ListNode *Curr;
int count, list_size;
void **PtrArray;

Curr=ListGetNext(ListHead);  /* Skip past empty list 'header' item */
list_size=0;
while (Curr !=NULL) 
{
Curr=ListGetNext(Curr);
list_size++;
}
PtrArray=calloc(list_size+1,sizeof(void *));

Curr=ListGetNext(ListHead);  /* All lists have a dummy header, remember? */
for (count=0;count < list_size; count++)
{
PtrArray[count]=Curr->Item;
Curr=ListGetNext(Curr);

}
PtrArray[count]=NULL;
return(PtrArray);

}
Esempio n. 6
0
int STREAMAddDataProcessor(STREAM *S, TProcessingModule *Mod, const char *Args)
{
ListNode *Curr;
char *Tempstr=NULL;
int len;

STREAMFlush(S);

if (! S->ProcessingModules) S->ProcessingModules=ListCreate();
Tempstr=MCopyStr(Tempstr,Mod->Name,NULL);
ListAddNamedItem(S->ProcessingModules,Tempstr,Mod);

len=S->InEnd - S->InStart;
Tempstr=SetStrLen(Tempstr,len);
memcpy(Tempstr,S->InputBuff + S->InStart,len);
STREAMResetInputBuffers(S);

Curr=ListGetNext(Mod->Values);
while (Curr)
{
	STREAMSetValue(S,Curr->Tag,(char *) Curr->Item);
	Curr=ListGetNext(Curr);
}

STREAMReadThroughProcessors(S, Tempstr, len);

DestroyString(Tempstr);
return(TRUE);
}
Esempio n. 7
0
TPathItem *VPathFind(int Type, char *Match)
{
TPathItem *VPath=NULL, *Default=NULL;
ListNode *Curr;

Curr=ListGetNext(Settings.VPaths);
while (Curr)
{
	VPath=(TPathItem *) Curr->Item;

	switch (VPath->Type)
	{
	case PATHTYPE_MIMEICONS: if (Type==VPath->Type) return(VPath); break;
	case PATHTYPE_FILETYPE:  if ((Type==VPath->Type) && (fnmatch(Curr->Tag, Match, 0)==0)) return(VPath); break;
	default:
	if (StrLen(Curr->Tag) < 2) Default=VPath;
	if (
			StrLen(Match) && (strncmp(Match, Curr->Tag, StrLen(Curr->Tag))==0)
		) return(VPath);
	break;
	}
	Curr=ListGetNext(Curr);
}

return(Default);
}
Esempio n. 8
0
void LogFileFlushAll(int Force)
{
	time_t Now;
	ListNode *Curr;
	TLogFile *Log;

	time(&Now);

	Curr=ListGetNext(LogFiles);
	while (Curr)
	{
	        Log=(TLogFile *) Curr->Item;

	        if (Force)
	        {
                STREAMFlush(Log->S);
                Log->LastFlushTime=Now;
	        }
	        else if ((Now - Log->LastFlushTime) > Log->FlushInterval)
	        {
                STREAMFlush(Log->S);
                Log->LastFlushTime=Now;
	        }
		Curr=ListGetNext(Curr);
	}
}
Esempio n. 9
0
void ListSortNamedItems(ListNode *List)
{
    ListNode *Curr=NULL, *Prev=NULL;
    int sorted=0;

    while (! sorted)
    {
        sorted=1;
        Prev=NULL;
        Curr=ListGetNext(List);
        while (Curr)
        {
            if (Prev !=NULL)
            {
                if (strcmp(Prev->Tag,Curr->Tag) < 0)
                {
                    sorted=0;
                    ListSwapItems(Prev,Curr);
                }
            }

            Prev=Curr;
            Curr=ListGetNext(Curr);
        }
    }

}
Esempio n. 10
0
void DumpVars(ListNode *Vars)
{
ListNode *Curr;

Curr=ListGetNext(Vars);
while (Curr)
{
printf("%s = %s\n",Curr->Tag,Curr->Item);
Curr=ListGetNext(Curr);
}
}
Esempio n. 11
0
int ProcessGetFileInfo(TFileStore *FS, char *Pattern, char *Arg, int CmdFlags, ListNode *Vars)
{
ListNode *Items=NULL, *Curr;
char *Tempstr=NULL, *IncludePattern=NULL, *ExcludePattern=NULL, *ptr;
TFileInfo *FI;
int result=FALSE, Flags, i;
char *DisplayVars[]={"Category","Author","Subtitle","Duration","Dimensions",NULL};
//"Summary","Description",NULL};

IncludePattern=CopyStr(IncludePattern,GetVar(Vars,"IncludePattern"));
ExcludePattern=CopyStr(ExcludePattern,GetVar(Vars,"ExcludePattern"));

Items=ListCreate();

Flags=LIST_REFRESH;
//if (CmdFlags & FLAG_CMD_RECURSE) Flags |= LIST_INCLUDE_DIRS;
FileStoreLoadDir(FS,Pattern,Items, Flags);
Curr=ListGetNext(Items);

while (Curr)
{
	FI=(TFileInfo *) Curr->Item;

  if (FileIncluded(FI,IncludePattern,ExcludePattern,CmdFlags, Vars))
	{
		if (FI->Type==FTYPE_DIR) 
		{
			if (CmdFlags & FLAG_CMD_RECURSE) InternalRecurseInfoCommand(FS, FI->Name, Arg,  CmdFlags, Vars, ProcessGetFileInfo);
		}
		else 
		{
			printf("\nInfo For %s\n",FI->Path);
			printf("Size: %s (%d bytes)\n",GetHumanReadableDataQty(FI->Size,0),FI->Size);
			printf("ContentType: %s\n",FI->MediaType);

			printf("Timestamp: %s\n",GetDateStrFromSecs("%Y/%m/%d %H:%M:%S",FI->Mtime,NULL));
			for (i=0; DisplayVars[i]; i++)
			{
				ptr=GetVar(FI->Vars,DisplayVars[i]);
				if (StrLen(ptr)) printf("%s: %s\n",DisplayVars[i],ptr);
			}
		}
	}

Curr=ListGetNext(Curr);
}

ListDestroy(Items,FileInfoDestroy);

DestroyString(IncludePattern);
DestroyString(ExcludePattern);
DestroyString(Tempstr);
}
Esempio n. 12
0
void ListDump(ListNode *List)
{
    ListNode *Curr;

    Curr=ListGetNext(List);
    while (Curr)
    {
        printf("  %s\n",Curr->Tag);
        Curr=ListGetNext(Curr);
    }

}
Esempio n. 13
0
int ProcessGetDigest(TFileStore *FS, char *Pattern, char *Type, int CmdFlags, ListNode *Vars)
{
ListNode *Items=NULL, *Curr;
char *Tempstr=NULL, *IncludePattern=NULL, *ExcludePattern=NULL;
TFileInfo *FI;
int result=FALSE, Flags;

if (! FS->GetDigest) return(FALSE);

IncludePattern=CopyStr(IncludePattern,GetVar(Vars,"IncludePattern"));
ExcludePattern=CopyStr(ExcludePattern,GetVar(Vars,"ExcludePattern"));

Items=ListCreate();

Flags=LIST_REFRESH;
//if (CmdFlags & FLAG_CMD_RECURSE) Flags |= LIST_INCLUDE_DIRS;
FileStoreLoadDir(FS,Pattern,Items, Flags);
Curr=ListGetNext(Items);

while (Curr)
{
	FI=(TFileInfo *) Curr->Item;

  if (FileIncluded(FI,IncludePattern,ExcludePattern,CmdFlags, Vars))
	{
		if (FI->Type==FTYPE_DIR) 
		{
			if (CmdFlags & FLAG_CMD_RECURSE) InternalRecurseInfoCommand(FS, FI->Name, Type, CmdFlags, Vars, ProcessGetDigest);
		}
		else 
		{
			result=FS->GetDigest(FS,FI->Name,Type,&Tempstr);
			if (result)
			{
				if (CmdFlags & FLAG_CMD_RECURSE) printf("OKAY: %s %s%s\n",Tempstr,FS->CurrDir,FI->Name);
				else printf("OKAY: %s %s\n",Tempstr,FI->Name);
			}
			else printf("ERROR: %s\n",Tempstr);
		}
	}

Curr=ListGetNext(Curr);
}

ListDestroy(Items,FileInfoDestroy);

DestroyString(IncludePattern);
DestroyString(ExcludePattern);
DestroyString(Tempstr);

return(result);
}
Esempio n. 14
0
void SendResponse(ConnectStruct *Con,DNSMessageStruct *Response)
{
struct sockaddr_in Send_sa;
short int sendlen;
int len, salen;
char *Buffer=NULL;
ListNode *Curr;
ResourceRecord *RR;

Buffer=SetStrLen(Buffer,1024);
len=CreateResponsePacket(Buffer,Buffer+1024,Response,&Settings);

if (len==0)
{
  LogToFile(Settings.LogFilePath,"ERROR: Zero length response packet");
	DestroyString(Buffer);
  return;
}

if (Con->Type==TCP_CONNECT)
{
   sendlen=htons(len);
   write(Con->fd, &sendlen, sizeof(short int));
   write(Con->fd, Buffer, len);
}
else if (Con->Type==UDP_CONNECT)
{
   Send_sa.sin_family=AF_INET;
   Send_sa.sin_addr.s_addr=Response->ClientIP;
   Send_sa.sin_port=Response->ClientPort;
   salen=sizeof(struct sockaddr_in);

   sendto(Con->fd,Buffer,len,0,(struct sockaddr *) &Send_sa,salen);
}
else LogToFile(Settings.LogFilePath,"ERROR: Unknown Comms Type %d on send",Con->Type);

if (Settings.LogLevel >= LOG_RESPONSES) 
{
	LogToFile(Settings.LogFilePath,"Sent %d answers to %s for %s query",ListSize(Response->Answers), IPtoStr(Response->ClientIP),Response->Question);

	Curr=ListGetNext(Response->Answers);
	while (Curr)
	{
		RR=(ResourceRecord *) Curr->Item;
		LogToFile(Settings.LogFilePath,"	ANS: %s->%s type=%d ttl=%d",RR->Question,RR->Answer,RR->Type,RR->TTL);
		Curr=ListGetNext(Curr);
	}
}

DestroyString(Buffer);
}
Esempio n. 15
0
ListNode *InsertItemIntoSortedList(ListNode *List, void *Item, int (*LessThanFunc)(void *, void *, void *))
{
ListNode *Curr, *Prev;

Prev=List;
Curr=ListGetNext(Prev);
while (Curr && (LessThanFunc(NULL, Curr->Item,Item)) )
{
Prev=Curr;
Curr=ListGetNext(Prev);
}

return(ListInsertItem(Prev,Item));
}
Esempio n. 16
0
int M3UStreamDownload(STREAM *ManifestCon, const char *URL, const char *Title)
{
STREAM *Con=NULL;
char *Tempstr=NULL, *BasePath=NULL, *Line=NULL;
const char *ptr;
ListNode *Segments, *Curr;
int result;
double BytesRead=0;

Segments=ListCreate();
ptr=strrchr(URL, '/');
if (ptr)
{
BasePath=CopyStrLen(BasePath, URL, ptr - URL);
	Line=STREAMReadLine(Line,ManifestCon);
	while (Line)
	{
		StripLeadingWhitespace(Line);
		StripTrailingWhitespace(Line);
		
		if (*Line != '#')
		{
			Tempstr=MCopyStr(Tempstr, BasePath, "/", Line, NULL);
			ListAddItem(Segments, CopyStr(NULL, Tempstr));
		}
	Line=STREAMReadLine(Line,ManifestCon);
	}

	OpenOutputFiles(Title, URL, &BytesRead);
	Tempstr=SetStrLen(Tempstr,BUFSIZ);
	Curr=ListGetNext(Segments);
	while (Curr)
	{
		Con=ConnectAndRetryUntilDownload(Curr->Item, 0, 0);
		if (Con)
		{
		TransferItem(Con, Title, URL, "m3u8-stream", 0, 0, &BytesRead, FALSE);
		STREAMClose(Con);
		}

	Curr=ListGetNext(Curr);
	}
	CloseOutputFiles();
}

ListDestroy(Segments, DestroyString);
DestroyString(Tempstr);
DestroyString(BasePath);
DestroyString(Line);
}
Esempio n. 17
0
void ParserItemsDestroy(ListNode *Items)
{
    ListNode *Curr;

    Curr=ListGetNext(Items);
    while (Curr)
    {
        if (Curr->ItemType==ITEM_ARRAY) ParserItemsDestroy((ListNode *) Curr->Item);
        else if (Curr->ItemType==ITEM_ENTITY) ParserItemsDestroy((ListNode *) Curr->Item);
        else DestroyString(Curr->Item);
        Curr=ListGetNext(Curr);
    }
    ListDestroy(Items, NULL);
}
Esempio n. 18
0
void CopyVars(ListNode *Dest, ListNode *Source)
{
ListNode *Curr;
char *Str;

if (! Dest) return;
if (! Source) return;
Curr=ListGetNext(Source);
while (Curr)
{
SetVar(Dest,Curr->Tag,Curr->Item);
Curr=ListGetNext(Curr);
}

}
Esempio n. 19
0
STREAM *ConnectManagerGetStreamByName(char *Name)
{
TConnectManagerItem *Item;
ListNode *Curr;

	Curr=ListGetNext(ConnectManClients);
	while (Curr)
	{
		Item=(TConnectManagerItem *) Curr->Item;
		if (strcmp(Item->Name,Name)==0) return((STREAM *) Item->Data);
		Curr=ListGetNext(Curr);
	}

return(NULL);
}
Esempio n. 20
0
static void CGIPrintSelect(const char *Name, const char *CurrType, ListNode *Items)
{
ListNode *Curr;

printf("<select name=%s>\r\n", Name);

Curr=ListGetNext(Items);
while(Curr)
{
	if (StrValid(CurrType) && (strcmp(Curr->Tag,CurrType)==0)) printf("<option selected value=%s> %s\r\n",Curr->Tag, Curr->Item);
	else printf("<option value=%s> %s\r\n",Curr->Tag, Curr->Item);
	Curr=ListGetNext(Curr);
}
printf("</select>\r\n");
}
Esempio n. 21
0
int DownloadStream(char *URL, char *Title, ListNode *Items, int Flags)
{
STREAM *Con=NULL, *S=NULL;
ListNode *Curr;
char *Tempstr=NULL, *ptr;
char *Token=NULL;
int Port;
double len=0, ApproxDocSize=0, BytesRead=0;

	Curr=ListGetNext(Items);

	if (Flags & (FLAG_TEST | FLAG_TEST_SITES) )
	{
		if (Flags & FLAG_TEST) fprintf(stderr,"TEST MODE: would have downloaded '%s' url=%s\n",Title,Curr->Item);
		if (Curr) return(TRUE);
		return(FALSE);
	}

	OpenOutputFiles(Title,URL,&BytesRead);
	while (Curr)
	{
		if (strncmp((char *) Curr->Item,"http:",5)==0) Tempstr=CopyStr(Tempstr,(char *) Curr->Item);
		else
		{
			Tempstr=CopyStr(Tempstr,URL);
			ptr=strrchr(Tempstr,'/');
			if (ptr) *ptr='\0';
			Tempstr=MCatStr(Tempstr,"/",(char *) Curr->Item,NULL);
		}

		Con=ConnectAndRetryUntilDownload(Tempstr, 0, 0);
		if (Con)
		{
			ptr=STREAMGetValue(Con,"HTTP:content-length");
			if (ptr) len=atof(ptr);
			if (ApproxDocSize==0) ApproxDocSize=ListSize(Items) * len;
			TransferItem(Con, Title, Curr->Item, "", len, ApproxDocSize,  &BytesRead, BytesRead==0);
			STREAMClose(Con);
		}
		Curr=ListGetNext(Curr);
	}
	CloseOutputFiles();

DestroyString(Tempstr);
DestroyString(Token);

return(TRUE);
}
Esempio n. 22
0
ListNode *ParserFindItem(ListNode *Items, const char *Name)
{
    ListNode *Node, *Curr;
    char *Token=NULL;
    const char *ptr;


    ptr=Name;
    if (*ptr=='/')
    {
        Node=Items;
        ptr++;
        if (*ptr=='\0') return(Node);
    }
    else if (! Items->Side) Node=Items;
    else if (Items->Side->ItemType != ITEM_VALUE) Node=(ListNode *) Items->Side;


    if (Node && StrValid(ptr))
    {
        ptr=GetToken(ptr,"/",&Token,0);
        while (ptr)
        {
            if (Node->ItemType== ITEM_ROOT) Node=(ListNode *) ListFindNamedItem(Node,Token);
            else if (Node->ItemType != ITEM_VALUE) Node=(ListNode *) ListFindNamedItem((ListNode *) Node->Item,Token);

            if (! Node) break;
            ptr=GetToken(ptr,"/",&Token,0);
        }
    }
    else Node=ListGetNext(Items);

    DestroyString(Token);
    return(Node);
}
Esempio n. 23
0
void ClearVars(ListNode *Vars)
{
ListNode *Curr;
char *Str;

if (! Vars) return;
Curr=ListGetNext(Vars);
while (Curr)
{
    Str=ListDeleteNode(Curr);
    DestroyString(Str);
Curr=ListGetNext(Curr);
}


}
Esempio n. 24
0
int ConnectManagerCountNamedConnections(char *Name)
{
TConnectManagerItem *Item;
ListNode *Curr;
int count=0;

	Curr=ListGetNext(ConnectManClients);
	while (Curr)
	{
		Item=(TConnectManagerItem *) Curr->Item;
		if (strcmp(Item->Name,Name)==0) count++;
		Curr=ListGetNext(Curr);
	}

return(count);
}
Esempio n. 25
0
BOOL ConvertLowResLoad(LPLIST lpPktList)
/***********************************************************************/
{
LPCMDPKT lpCmdPkt;

lpCmdPkt = (LPCMDPKT)ListGetHead(lpPktList);
while (lpCmdPkt)
	{
	if (lpCmdPkt->idCommand == IDS_CMD_LOWRESLOAD)
		{
		LPLOADFILE_PARMS lpLoadFileParms;
		LPLOWRESLOAD_PARMS lpLowResParms;

		lpLoadFileParms = (LPLOADFILE_PARMS)Alloc(sizeof(LOADFILE_PARMS));
		if (!lpLoadFileParms)
			{
			Message(IDS_EMEMALLOC);
			return(FALSE);
			}
		lpLowResParms = (LPLOWRESLOAD_PARMS)lpCmdPkt->lpParms;
		lstrcpy(lpLoadFileParms->szFileName, lpLowResParms->szFileName);
		lpLoadFileParms->idFileType = lpLowResParms->idFileType;
		lpLoadFileParms->cmsInfo = lpLowResParms->cmsInfo;

		FreeUpParms(lpCmdPkt->idCommand, lpCmdPkt->lpParms);
		lpCmdPkt->idCommand = IDS_CMD_LOADFILE;
		lpCmdPkt->lpParms = lpLoadFileParms;
		}
	lpCmdPkt = (LPCMDPKT)ListGetNext(lpCmdPkt);
	}
return(TRUE);
}
Esempio n. 26
0
char *GetLogoutPath()
{
TPathItem *File;
ListNode *Curr;

Curr=ListGetNext(Settings.VPaths);
while (Curr)
{
	File=(TPathItem *) Curr->Item;
	if (File->Type==PATHTYPE_LOGOUT) return(File->URL);

Curr=ListGetNext(Curr);
}

return("");
}
Esempio n. 27
0
ListNode *ListGetNth(ListNode *Head, int n)
{
    ListNode *Curr;
    int count=0;

    if (! Head) return(NULL);

    Curr=ListGetNext(Head);
    while (Curr && (count < n))
    {
        count++;
        Curr=ListGetNext(Curr);
    }
    if (count < n) return(NULL);
    return(Curr);
}
Esempio n. 28
0
void ListAppendItems(ListNode *Dest, ListNode *Src, LIST_ITEM_CLONE_FUNC ItemCloner)
{
    ListNode *Curr;
    void *Item;

    Curr=ListGetNext(Src);
    while (Curr !=NULL)
    {
        if (ItemCloner)
        {
            Item=ItemCloner(Curr->Item);
            ListAddNamedItem(Dest, Curr->Tag, Item);
        }
        else ListAddNamedItem(Dest, Curr->Tag, Curr->Item);
        Curr=ListGetNext(Curr);
    }
}
Esempio n. 29
0
ListNode *ListFindItem(ListNode *Head, void *Item)
{
    ListNode *Curr;

    if (! Item) return(NULL);
    Curr=ListGetNext(Head);
    while (Curr)
    {
        if (Curr->Item==Item)
        {
            if (Head->Flags & LIST_FLAG_SELFORG) ListSwapItems(Curr->Prev, Curr);
            return(Curr);
        }
        Curr=ListGetNext(Curr);
    }
    return(Curr);
}
Esempio n. 30
0
char *GetAlias(char *Name)
{
ListNode *Curr;
ResourceRecord *AliasItem;

Curr=ListGetNext(AliasListHead);
while (Curr)
{
AliasItem=(ResourceRecord *)Curr->Item;
if (strcasecmp(AliasItem->Question,Name)==0) return(AliasItem->Answer);

Curr=ListGetNext(Curr);
}

return(Name);


}