Ejemplo n.º 1
0
void *ListDeleteItem(ListNode *Head, void *Item)
{
ListNode *Node;

Node=ListFindItem(Head, Item);
if (Node) ListDeleteNode(Node);
}
Ejemplo n.º 2
0
int STREAMDeleteDataProcessor(STREAM *S, char *Class, char *Name)
{
ListNode *Curr;
char *Tempstr=NULL;
int len;

STREAMFlush(S);

Tempstr=MCopyStr(Tempstr,Class,":",Name,NULL);
Curr=ListFindNamedItem(S->ProcessingModules,Tempstr);
ListDeleteNode(Curr);

DestroyString(Tempstr);
return(TRUE);
}
Ejemplo n.º 3
0
void LogFileClose(const char *Path)
{
ListNode *Node;
TLogFile *LogFile;

Node=ListFindNamedItem(LogFiles,Path);
if (Node)
{
LogFile=(TLogFile *) Node->Item;
ListDeleteNode(Node);
DestroyString(LogFile->Path);
STREAMClose(LogFile->S);
free(LogFile);
}
}
Ejemplo n.º 4
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);
}


}
Ejemplo n.º 5
0
void UnsetVar(ListNode *Vars,const char *Name)
{
ListNode *Curr;
char *Str=NULL;
char *Tempstr=NULL;

if (Vars) return;
Tempstr=CopyStr(Tempstr,Name);
strlwr(Tempstr);
Curr=ListFindNamedItem(Vars,Tempstr);
if (Curr)
{
    Str=ListDeleteNode(Curr);
    DestroyString(Str);
}
DestroyString(Tempstr);
}
Ejemplo n.º 6
0
int main()
{

    List *l = ListCreate();
    int code;
    int index;
    double item;
    instructions();
    while ((code =  getchar()) != EOF) {
        switch (code) {
            case 'p':
                ListPrint(l);
                break;
            case 'a':
                //printf("add: ");
                if (scanf("%d %lf", &index, &item) == 2) {
                    ListInsert(l, index, item);
                } else {
                    printf("Input error\n");
                }
                break;
            case 'd':
                if (scanf("%lf", &item) == 1) {
                    Node *item_ptr = ListFind(l, item);
                    if (item_ptr) {
                        ListDeleteNode(l, item_ptr);
                    } else {
                        printf("Incorrect index\n");
                    }
                } else {
                    printf("Input error\n");
                }
                break;
                
            case 'q':
                ListDestroy(&l);
                return 0;
                
            case 'e':
                ListExchange(l);
                break;
        }
    }
    ListDestroy(&l);
    return 0;
}
Ejemplo n.º 7
0
// deletes an item at the specified index. ( 0 based )
int ListDeleteAt( list *l, int pos ) {
	if ( l == NULL || pos < 0 || pos > l->itemCount )
		return 0;
	
	listNode *node = l->head;

	for( int i = 0; i < l->itemCount; i++ ) {
		if ( i == pos ) {
			ListDeleteNode( node );
			l->itemCount--;
			return 1;
		}

		node = node->next;
	}

	return 0;
}
Ejemplo n.º 8
0
void ResetTTY(int tty)
{
struct termios *tty_data;
char *Tempstr=NULL;
ListNode *Curr;

Tempstr=FormatStr(Tempstr,"%d",tty);
Curr=ListFindNamedItem(TTYAttribs,Tempstr);
if (Curr)
{
	tty_data=(struct termios *) Curr->Item;
	tcsetattr(tty,TCSANOW,tty_data);
	ListDeleteNode(Curr);
	free(tty_data);
}

DestroyString(Tempstr);
}
Ejemplo n.º 9
0
// deletes the specified item ( linear search )
int ListDeleteItem( list *l, void *data ) {
	
	if ( l == NULL || data == NULL )
		return 0;

	listNode *node = l->head;

	for( int i = 0; i < l->itemCount; i++ ) {
		// compare pointers. obvs wont work for strings.
		if ( data == node->data ) {
			ListDeleteNode( node );
			l->itemCount--;
			return 1;
		}

		node = node->next;
	}

	return 0;
}
Ejemplo n.º 10
0
void OAuthDestroy(void *p_OAuth)
{
    OAUTH *Ctx;
    ListNode *Curr;

    Ctx=(OAUTH *) p_OAuth;
    Curr=ListFindNamedItem(OAuthKeyChain, Ctx->Name);
    if (Curr) ListDeleteNode(Curr);

    DestroyString(Ctx->Name);
    DestroyString(Ctx->Stage1);
    DestroyString(Ctx->Stage2);
    DestroyString(Ctx->VerifyTemplate);
    DestroyString(Ctx->AccessToken);
    DestroyString(Ctx->RefreshToken);
    DestroyString(Ctx->RefreshURL);
    DestroyString(Ctx->VerifyURL);
    DestroyString(Ctx->VerifyCode);
    DestroyString(Ctx->Creds);
    DestroyString(Ctx->SavePath);
    ListDestroy(Ctx->Vars, Destroy);
    free(Ctx);
}
Ejemplo n.º 11
0
main(int argc, char *argv[])
{
ListNode *Curr, *Next;
int OverrideType=TYPE_NONE;
char *Tempstr=NULL;
int result;

//HTTPSetFlags(HTTP_NOCOMPRESS);
StdIn=STREAMFromFD(0);
STREAMSetTimeout(StdIn,0);
ParseEnvironmentVariables();

DownloadQueue=ListCreate();
Tempstr=MCopyStr(Tempstr,"Movgrab ",Version,NULL);
HTTPSetUserAgent(Tempstr);
FormatPreference=CopyStr(FormatPreference,"mp4,flv,webm,m4v,mov,mpg,mpeg,wmv,avi,3gp,reference,mp3,m4a,wma,m3u8,m3u8-stream");
AddOutputFile("", TRUE);

ParseCommandLine(argc, argv, DownloadQueue, &OverrideType);
CheckSettings();
if (StrLen(Proxy)) 
{
	if (! SetGlobalConnectionChain(Proxy))
	{
		printf("ERROR: Failed to set proxy settings to '%s'\n",Proxy);
		exit(1);
	}
}



if (Flags & FLAG_PRINT_USAGE) PrintUsage();
else if (Flags & FLAG_PRINT_VERSION) PrintVersion();
else if (! (Flags & FLAG_STDIN))
{
	if (ListSize(DownloadQueue)==0) PrintUsage();
}


while (1)
{
	if ((Flags & FLAG_STDIN) && (ListSize(DownloadQueue)==0) )
	{
		Tempstr=STREAMReadLine(Tempstr,StdIn);
		StripTrailingWhitespace(Tempstr);
		ListAddItem(DownloadQueue,CopyStr(NULL,Tempstr));
	}

	Curr=ListGetNext(DownloadQueue);
	while (Curr)
	{
		if (Flags & FLAG_TEST_SITES)
		{
			fprintf(stderr,"Checking %-20s ",Curr->Tag);
			fflush(NULL);
		}


		result=GrabMovie((char *) Curr->Item,OverrideType);
		Next=ListGetNext(Curr); //must do this after grab movie
																//incase more items added while grabbing

			if (Flags & FLAG_TEST_SITES) 
			{
				if (result) fprintf(stderr," okay\n");
				else fprintf(stderr," BROKEN\n");
			}
			
		ListDeleteNode(Curr);

		Curr=Next;
	}

	if (Flags & FLAG_TEST_SITES) break;
	if (! (Flags & FLAG_STDIN)) break;
}

}
Ejemplo n.º 12
0
ListNode *ListFindNamedItemInsert(ListNode *Root, const char *Name)
{
    ListNode *Prev, *Curr, *Next, *Head;
    int result=0, count=0;
    int hops=0, jumps=0, miss=0;
    unsigned long long val;

    if (! Root) return(Root);
    if (! StrValid(Name)) return(Root);

    if (Root->Flags & LIST_FLAG_MAP_HEAD) Head=MapGetChain(Root, Name);
    else Head=Root;


    //Dont use 'ListGetNext' internally
    Curr=Head->Next;
    if (! Curr) return(Head);

    //if LIST_FLAG_CACHE is set, then the general purpose 'Side' pointer of the head node points to a cached item
    if ((Root->Flags & LIST_FLAG_CACHE) && Head->Side && Head->Side->Tag)
    {
        //use next to hold Head->Side for less typing!
        Next=Head->Side;

        if (Root->Flags & LIST_FLAG_CASE) result=strcmp(Next->Tag,Name);
        else result=strcasecmp(Next->Tag,Name);

        if (result==0) return(Next);
        //if result < 0 AND ITS AN ORDERED LIST then it means the cached item is ahead of our insert point, so we might as well jump to it
        else if ((Root->Flags & LIST_FLAG_ORDERED) && (result < 0)) Curr=Next;
    }

    //Check last item in list
    Prev=Head->Prev;
    if (Prev && (Prev != Head) && Prev->Tag)
    {
        if (Head->Flags & LIST_FLAG_CASE) result=strcmp(Prev->Tag,Name);
        else result=strcasecmp(Prev->Tag,Name);

        if (result == 0) return(Prev);
        if ((Head->Flags & LIST_FLAG_ORDERED) && (result < 1)) return(Prev);
    }

    Prev=Head;

    while (Curr)
    {
        Next=Curr->Next;
        if (Curr->Tag)
        {
            if (Root->Flags & LIST_FLAG_CASE) result=strcmp(Curr->Tag,Name);
            else result=strcasecmp(Curr->Tag,Name);

            if (result==0)
            {
                if (Root->Flags & LIST_FLAG_SELFORG) ListSwapItems(Curr->Prev, Curr);
                return(Curr);
            }

            if ((result > 0) && (Root->Flags & LIST_FLAG_ORDERED)) return(Prev);

            //Can only get here if it's not a match
            if (Root->Flags & LIST_FLAG_TIMEOUT)
            {
                val=ListNodeGetTime(Curr);
                if ((val > 0) && (val < GetTime(TIME_CACHED)))
                {
                    Destroy(Curr->Item);
                    ListDeleteNode(Curr);
                }
            }
        }

        hops++;
        count++;


        Prev=Curr;
        Curr=Next;
    }

    return(Prev);
}
Ejemplo n.º 13
0
void ConnectManagerMainLoop()
{
TConnectManagerItem *Item, *NewItem;
ListNode *Curr, *Prev;
int highfd=0;
fd_set ReadSet, WriteSet;
int sock, result, SelectResult, NextTimerFire;
STREAM *S;
time_t Now;
struct timeval tv;
int MoreData=FALSE;

while (1)
{
	MoreData=FALSE;
  time(&Now);
 	NextTimerFire=60;
	Curr=ListGetNext(Timers);
	while (Curr)
	{
		Item=(TConnectManagerItem *) Curr->Item;
		if (Item->LastTimerFire==0) Item->LastTimerFire=Now;
		result=(Item->LastTimerFire + Item->TimerVal) - Now;
	    if (result < NextTimerFire) NextTimerFire=result;
		Curr=ListGetNext(Curr);
	}



		FD_ZERO(&ReadSet);
		FD_ZERO(&WriteSet);
		Curr=ListGetNext(ConnectManServers);
		while (Curr)
		{
			Item=(TConnectManagerItem *) Curr->Item;
		 	 S=(STREAM *) Item->Data;
			FD_SET(S->in_fd,&ReadSet);
			if (S->in_fd > highfd) highfd=S->in_fd;
			Curr=ListGetNext(Curr);
		}


		Curr=ListGetNext(ConnectManClients);
		while (Curr)
		{
			Item=(TConnectManagerItem *) Curr->Item;
		  S=(STREAM *) Item->Data;
			if (! S) 
			{
				ListDeleteNode(Curr);
				continue;
			}
 
			if (S->State & SS_CONNECTING)
			{
				FD_SET(S->in_fd,&WriteSet);
			}
			if (S->InEnd > S->InStart) MoreData=TRUE;
			else
			{
			//always add to read set
			FD_SET(S->in_fd,&ReadSet);
			if (S->in_fd > highfd) highfd=S->in_fd;
			}

			Curr=ListGetNext(Curr);
		}

	if (MoreData)
	{
	tv.tv_usec = 10;
  tv.tv_sec = 0;
	SelectResult=0;
	}
	else
	{
		//SELECT!!!
 	 tv.tv_usec = 20000;
 	 tv.tv_sec = NextTimerFire;
	}
	SelectResult=select(highfd+1,&ReadSet,&WriteSet,NULL,&tv);


	if (SelectResult > 0)
	{
		Curr=ListGetNext(ConnectManServers);
		while (Curr)
		{
			Item=(TConnectManagerItem *) Curr->Item;

   		S=(STREAM *) Item->Data;
			if (! S) 
			{
				ListDeleteNode(Curr);
				continue;
			}


			if (FD_ISSET(S->in_fd,&ReadSet))
			{
				sock=TCPServerSockAccept(S->in_fd,&S->Path);
				if (sock > -1)
				{
				S=STREAMFromFD(sock);
				STREAMSetFlushType(S,FLUSH_LINE,0,0);
				NewItem=ConnectManagerAddIncoming(S,Item->Name, Item->OnData);
				if (Item->OnConnect) Item->OnConnect(NewItem);	
				}
			}

			Curr=ListGetNext(Curr);
		}
	}


		Curr=ListGetNext(ConnectManClients);
		while (Curr)
		{
			Item=(TConnectManagerItem *) Curr->Item;
	 		S=(STREAM *) Item->Data;
			if (! S) 
			{
				ListDeleteNode(Curr);
				continue;
			}

			if ((SelectResult > 0) && FD_ISSET(S->in_fd,&WriteSet))
			{
				if (S->State & SS_CONNECTING)
				{
					if (STREAMIsConnected(S)) 
					{
						STREAMSetFlags(S, 0, SF_NONBLOCK);
						if (Item->OnConnect) Item->OnConnect(Item);
					}

				}
			}

			if (
					 (S->InEnd > S->InStart) ||
					 ((SelectResult > 0) && (FD_ISSET(S->in_fd,&ReadSet)))
				)
			{
                if (! (S->State & SS_CONNECTING))
                {
				if (Item->OnData)
				{
					  result=Item->OnData(S, Item->Name);
					  if (! result)
						{	
					    STREAMClose(S);
							Prev=ListGetPrev(Curr);
							ListDeleteNode(Curr);
							free(Item);
						  Curr=Prev;	
					  }
						else if (result==RECONNECT)
						{
							STREAMClose(S);
							S=STREAMCreate();
							STREAMConnectToHost(S,Item->Host,Item->Port,CONNECT_NONBLOCK);
							Item->Data=(void *) S;
						}

				}
				}
			}
			Curr=ListGetNext(Curr);
		}


  time(&Now);
	Curr=ListGetNext(Timers);
	while (Curr)
	{
	   Item=(TConnectManagerItem *) Curr->Item;
	   if ( (Now - Item->LastTimerFire) >= Item->TimerVal ) 
       {
			if (Item->OnData) ((ONTIMER_FUNC)Item->OnData)(Item->Data,Item->Name);
			Item->LastTimerFire=Now;
       }
	  Curr=ListGetNext(Curr);
	}

	
}

}