示例#1
0
void ParseFunction(STREAM *S, const char *Config)
{
char *Token=NULL, *Tempstr=NULL;
const char *ptr;
ListNode *Select;
TCrayon *Crayon;

if (! Functions) Functions=ListCreate();

ptr=GetToken(Config, "\\S", &Token, GETTOKEN_QUOTES);
Select=ListCreate();

ListAddNamedItem(Functions, Token, Select);

Tempstr=STREAMReadLine(Tempstr, S);
while (Tempstr)
{
	StripTrailingWhitespace(Tempstr);
	StripLeadingWhitespace(Tempstr);
	ptr=GetToken(Tempstr, "\\S", &Token, GETTOKEN_QUOTES);
	if (strcmp(Token,"}")==0) break;
	
	if (MatchActionType(Token) > -1)
	{
		 ParseCrayonization("action", Tempstr, Select);
	}
	else ParseCrayonization(Token, ptr, Select);
	Tempstr=STREAMReadLine(Tempstr, S);
}

Destroy(Tempstr);
Destroy(Token);
}
示例#2
0
文件: test.c 项目: ColumPaget/daytime
main()
{
char *Tempstr=NULL;
ListNode *Vars, *Streams;
STREAM *S;
int i;
char *IP[]={"217.33.140.70","8.8.8.8","4.2.2.1","88.198.48.36",NULL};

Vars=ListCreate();
Streams=ListCreate();
MessageBusRegister("proc:tester.test.func", 4, 10, Tester);
MessageBusRegister("http://freegeoip.net/xml/", 4, 10, NULL);

printf("PARENT: %d\n",getpid());
for (i=0; i < 4; i++)
{
Tempstr=FormatStr(Tempstr,"string=hello&integer=%d",i);
MessageBusWrite("proc:tester.test.func", Tempstr);
MessageBusWrite("http://freegeoip.net/xml/", IP[i]);

MessageQueueAddToSelect(Streams);
S=STREAMSelect(Streams, NULL);
if (S) 
{
	MessageBusRecv(S, &Tempstr, Vars);
	DumpVars(Vars);
}
else printf("NO ACTIVITY!\n");
sleep(1);
}


}
示例#3
0
HTTPInfoStruct *HTTPInfoCreate(char *Host, int Port, char *Logon, char *Password, char *Method, char *Doc, char *ContentType, int ContentLength)
{
HTTPInfoStruct *Info;
char *ptr;

Info=(HTTPInfoStruct *) calloc(1,sizeof(HTTPInfoStruct));
HTTPInfoSetValues(Info, Host, Port, Logon, Password, Method, Doc, ContentType, ContentLength);

Info->ServerHeaders=ListCreate();
Info->CustomSendHeaders=ListCreate();
//SetVar(Info->CustomSendHeaders,"Accept","*/*");

if (g_Flags) Info->Flags=g_Flags;

ptr=LibUsefulGetValue("HTTP:Proxy");
if (StrLen(ptr)) 
{
	Info->Proxy=CopyStr(Info->Proxy,ptr);
	strlwr(Info->Proxy);
	if (strncmp(Info->Proxy,"http:",5)==0) Info->Flags |= HTTP_PROXY;
	else if (strncmp(Info->Proxy,"https:",6)==0) Info->Flags |= HTTP_PROXY;
	else Info->Flags=HTTP_TUNNEL;
}

return(Info);
}
//Encrypted settings for M8
//ES when M8 is from an AP
CTlvEsM8Ap::CTlvEsM8Ap()
{
    if(!(nwKeyIndex = ListCreate()))
        throw WSC_ERR_OUTOFMEMORY;

    if(!(nwKey = ListCreate()))
        throw WSC_ERR_OUTOFMEMORY;

}
//ES when M7 is from an AP
CTlvEsM7Ap::CTlvEsM7Ap()
{
    nwKeyIndex = ListCreate();
    if(!nwKeyIndex)
        throw WSC_ERR_OUTOFMEMORY;

    nwKey = ListCreate();
    if(!nwKey)
        throw WSC_ERR_OUTOFMEMORY;
}
示例#6
0
/* Initilize the Monitor
 * we create an index, then the enterSem and urgentSem with
 * values 1, 0 respectivly.  Then the condition variable semaphore
 * and List are created as array sizes K which are givent to the
 * initilizing function.  The semaphore for condition variable
 * is given 0 for every spot in the array.
 * Then the enterQueue and urgentQueue are created */
void MonInit(int k){
  int i;
  enterSem = NewSem(1);
  urgentSem = NewSem(0);
  condSems = (int*)malloc(sizeof(int)*k);
  condLists = (LIST**)malloc(sizeof(LIST *)*k);
  for(i=0; i<k; i++){
    condSems[i] = NewSem(0);
    condLists[i] = ListCreate();
  }
  enterQueue = ListCreate();
  urgentQueue = ListCreate();
}
示例#7
0
ListNode *MapCreate(int Buckets, int Flags)
{
    ListNode *Node, *SubNode;
    int i;

//clear map flags out
    Flags &= ~LIST_FLAG_MAP;

    Node=ListCreate();
    Node->Flags |= LIST_FLAG_MAP_HEAD | Flags;
    Node->ItemType=Buckets;

		//we allocate one more than we will use, so the last one acts as a terminator
    Node->Item=calloc(Buckets+1, sizeof(ListNode));
    SubNode=(ListNode *) Node->Item;
    for (i=0; i < Buckets; i++)
    {
        SubNode->Head=Node;
        SubNode->Prev=SubNode;
        SubNode->Flags |= LIST_FLAG_MAP_CHAIN | Flags;
        SubNode->Stats=(ListStats *) calloc(1,sizeof(ListStats));
        SubNode++;
    }

    return(Node);
}
示例#8
0
void OpenSkins( void )
{
    DmOpenRef           dbRef;
    DmSearchStateType   stateInfo;
    UInt16              cardNo;
    LocalID             dbID;
    Err                 err;

    resourceDBList = ListCreate();

    if ( resourceDBList == NULL )
        return;

    err = DmGetNextDatabaseByTypeCreator( true, &stateInfo,
            (UInt32) SkinResourceType, (UInt32) ViewerAppID,
            false, &cardNo, &dbID );

    while ( err == errNone ) {
        dbRef = DmOpenDatabase( cardNo, dbID, dmModeReadOnly );
        if ( dbRef != NULL )
            ListAppend( resourceDBList, dbRef );

        err = DmGetNextDatabaseByTypeCreator( false, &stateInfo,
                (UInt32) SkinResourceType, (UInt32) ViewerAppID, false,
                &cardNo, &dbID );
    }
}
示例#9
0
ListNode *ConfigFileLoadFileStores(char *Path)
{
STREAM *S;
TFileStore *FS=NULL;
char *Tempstr=NULL, *Token=NULL, *ptr;

if (! FileStores) FileStores=ListCreate();
S=STREAMOpenFile(Path,O_RDONLY);
if (S)
{
	Tempstr=STREAMReadLine(Tempstr,S);
	while (Tempstr)
	{
		StripTrailingWhitespace(Tempstr);
		ptr=GetToken(Tempstr," ",&Token,0);

		if (strcmp(Token,"FileStore")==0)
		{
			FS=ConfigFileReadFileStore(S, ptr);
			ListAddNamedItem(FileStores,FS->Name,FS);
		}

		Tempstr=STREAMReadLine(Tempstr,S);
	}

STREAMClose(S);
}

DestroyString(Tempstr);
DestroyString(Token);

return(FileStores);
}
示例#10
0
void SettingsInit()
{
//Default users that the system could run as
char *DefaultUsers[]={"nobody","daemon","guest","wwwrun",NULL};
int i;

memset(&Settings,0,sizeof(TSettings));
Settings.Interface=CopyStr(Settings.Interface,"");
Settings.Port=23;
Settings.AuthDelay=3;
Settings.AuthTries=3;
Settings.IdleTimeout=3600;
Settings.AuthMethods=CopyStr(Settings.AuthMethods,"native");
Settings.AuthFile=CopyStr(Settings.AuthFile,"/etc/ptelnetd.auth");
Settings.DefaultShell=CopyStr(Settings.DefaultShell,"/bin/sh");
Settings.LogPath=CopyStr(Settings.LogPath,"/var/log/telnetd.log");
Settings.BindMounts=CopyStr(Settings.BindMounts,"");
Settings.PidFile=CopyStr(Settings.PidFile,"/var/run/ptelnetd-$(Interface)-$(ServerPort).pid");
Settings.BlockHosts=ListCreate();
Settings.TermType=CopyStr(Settings.TermType,"vt100");
for (i=0; DefaultUsers[i] !=NULL; i++)
{
			if (getpwnam(DefaultUsers[i]))
			{
				Settings.RealUser=CopyStr(Settings.RealUser,DefaultUsers[i]);
				break;
			}
}

Settings.ChDir=CopyStr(Settings.ChDir,"/var/empty/");
}
示例#11
0
STREAM *ConnectManagerAddClient(char *Host, int Port, int Flags, char *Name, CONNECT_FUNC OnConnect, ONDATA_FUNC OnData)
{
STREAM *S;
TConnectManagerItem *Item;

if (! ConnectManClients) ConnectManClients=ListCreate();

S=STREAMCreate();
if (! STREAMConnectToHost(S,Host,Port,Flags))
{
STREAMClose(S);
return(NULL);
}

Item=(TConnectManagerItem *) calloc(1,sizeof(TConnectManagerItem));
Item->OnConnect=OnConnect;
Item->OnData=OnData;
Item->Data=(void *) S;
Item->Name=CopyStr(Item->Name,Name);
Item->Host=CopyStr(Item->Host,Host);
Item->Port=Port;

if (Item->OnConnect && STREAMIsConnected(S)) Item->OnConnect(Item);

ListAddItem(ConnectManClients,Item);
return(S);
}
示例#12
0
文件: common.c 项目: ColumPaget/Alaya
HTTPSession *HTTPSessionCreate()
{
HTTPSession *Session;

Session=(HTTPSession *) calloc(1,sizeof(HTTPSession));

//Must set all these to "" otherwise nulls can cause trouble later
Session->Protocol=CopyStr(Session->Protocol,"HTTP/1.1");
Session->ServerName=CopyStr(Session->ServerName,"");
Session->UserAgent=CopyStr(Session->UserAgent,"");
Session->UserName=CopyStr(Session->UserName,"");
Session->RealUser=CopyStr(Session->RealUser,"");
Session->ContentType=CopyStr(Session->ContentType,"");
Session->Host=CopyStr(Session->Host,"");
Session->Path=CopyStr(Session->Path,"");
Session->Arguments=CopyStr(Session->Arguments,"");
Session->ClientHost=CopyStr(Session->ClientHost,"");
Session->ClientIP=CopyStr(Session->ClientIP,"");
Session->ClientMAC=CopyStr(Session->ClientMAC,"");
Session->ClientReferrer=CopyStr(Session->ClientReferrer,"");
Session->StartDir=CopyStr(Session->StartDir,"");
Session->Depth=1;
Session->CacheTime=Settings.DocumentCacheTime;
Session->Headers=ListCreate();
Session->Flags |= SESSION_UPLOAD;

return(Session);
}
示例#13
0
文件: help.c 项目: mjames-upc/garp
void
HelpCB ( Widget parent )
{
	char	*file, *dpath;
	int	verbose;
/*
 *  Callback to popup HTML dialog.
 */
	verbose = GetVerboseLevel();
	if( verbose > VERBOSE_0 )
	    printf ("HelpCB\n");

        dpath = GetConfigValue ("GarpHTML");
        file = builddirpath ( dpath, home_html );

/*
 *	Initialize hypertext file list.
 */
	historyList = ListCreate();
	if ( file ) ListAddEntry ( historyList, strdup(file) );

/*
 *	Popup HTML dialog.
 */
	XtManageChild ( help.dialog );
	XtPopup ( XtParent ( help.dialog ), XtGrabNone);

	Free ( dpath );
	Free ( file );
}
示例#14
0
文件: server.c 项目: ColumPaget/Alaya
void HTTPServerSendDocument(STREAM *S, HTTPSession *Session, char *Path, int Flags)
{
int result;
ListNode *Vars;

	Vars=ListCreate();

	if (StrLen(Path)==0) result=FILE_NOSUCH;
	else result=LoadFileRealProperties(Path, TRUE, Vars);

	if (result==FILE_NOSUCH) HTTPServerSendHTML(S, Session, "404 Not Found","Couldn't find that document.");
	else
	{
		//Set 'LastModified' so we can use it if the server sends 'If-Modified-Since'
	  Session->LastModified=atoi(GetVar(Vars,"MTime-secs"));

		//If we are asking for details of a file then we treat that as a directory function
		if ((result==FILE_DIR) || (strstr(Session->Arguments,"format=")))
		{
			HTTPServerSendDirectory(S,Session,Path,Vars);
		}
		else HTTPServerSendFile(S, Session, Path, Vars, Flags);
	}

ListDestroy(Vars,DestroyString);
}
示例#15
0
文件: server.c 项目: ColumPaget/Alaya
void HTTPServerHandleStream(STREAM *Output, HTTPSession *Session, char *SearchPath, int SendData)
{
char *Tempstr=NULL;
HTTPSession *Response;
ListNode *Vars;
STREAM *S;
glob_t Glob;
int i;


Vars=ListCreate();
SetVar(Vars,"ContentType","audio/mpeg");
Response=FileSendCreateSession("", Session, Vars, 0);
HTTPServerSendHeaders(Output, Response, FALSE);
STREAMFlush(Output);

Tempstr=MCopyStr(Tempstr,SearchPath,"/*",NULL);
glob(Tempstr,0,0,&Glob);

LogToFile(Settings.LogPath,"Stream from Dir: %s, %d files",SearchPath,Glob.gl_pathc);

for (i=0; i < Glob.gl_pathc; i++)
{
	S=STREAMOpenFile(Glob.gl_pathv[i],SF_RDONLY);
	if (S)
	{
		IcecastSendData(S, Output, 4096000);
		STREAMClose(S);
	}
}

globfree(&Glob);
DestroyString(Tempstr);
ListDestroy(Vars,DestroyString);
}
示例#16
0
int DownloadM3U(char *URL, char *Title, int Flags)
{
char *Tempstr=NULL, *ID=NULL, *Doc=NULL, *ptr;
int Port=0, BytesRead=0, len=0, count=0;
int RetVal=FALSE;
ListNode *Items, *Curr;
int M3UType=M3U_PLAYLIST;
STREAM *Con;

if (Flags & FLAG_DEBUG) fprintf(stderr,"M3U STREAM: %s\n",URL);


Items=ListCreate();
Con=ConnectAndRetryUntilDownload(URL, 0, 0);
if (Con)
{
Tempstr=STREAMReadLine(Tempstr,Con);
while (Tempstr)
{
StripTrailingWhitespace(Tempstr);
StripLeadingWhitespace(Tempstr);

if (Flags & (FLAG_DEBUG2 | FLAG_DEBUG3)) fprintf(stderr,"%s\n",Tempstr);
if (StrLen(Tempstr))
{
	if (strncmp("#EXT-X-STREAM-INF",Tempstr,StrLen("#EXT-X-STREAM-INF"))==0)
	{
			RetVal=M3UStreamInfo(Con,Title,URL,Tempstr,Flags);
			M3UType=M3U_STREAMINFO;
	}
	else if (strncmp("#EXT-X-MEDIA-SEQUENCE",Tempstr,StrLen("#EXT-X-MEDIA-SEQUENCE"))==0) M3UType=M3U_PLAYLIST;
	else if (*Tempstr != '#') 
	{
		if (strncasecmp(Tempstr,"http",4) !=0) 
		{
			Doc=CopyStr(Doc,URL);
			ptr=strrchr(Doc,'/');
			if (ptr) *ptr='\0';
			Doc=MCatStr(Doc,"/",Tempstr,NULL);
		}
		else Doc=CopyStr(Doc,Tempstr);
		ListAddItem(Items,CopyStr(NULL,Doc));
	}
}

Tempstr=STREAMReadLine(Tempstr,Con);
}

STREAMClose(Con);
if (M3UType == M3U_PLAYLIST) RetVal=DownloadStream(URL, Title, Items, Flags);
}

ListDestroy(Items,DestroyString);
DestroyString(Tempstr);
DestroyString(Doc);
DestroyString(ID);


return(RetVal);
}
示例#17
0
InitData()
{
	if (!(dataList = ListCreate()))
		return(0);

	return(1);
}
示例#18
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);
}
示例#19
0
void OAuthInstalledAppGetAccessToken(char *TokenURL, char *ClientID, char *ClientSecret, char *AuthCode, char *RedirectURL, char **AccessToken, char **RefreshToken)
{
char *Tempstr=NULL, *Encode=NULL;
ListNode *Vars=NULL;
STREAM *S;

Vars=ListCreate();

Tempstr=MCopyStr(Tempstr,TokenURL,"?client_id=",ClientID,NULL);
Tempstr=MCatStr(Tempstr,"&client_secret=",ClientSecret,NULL);
Tempstr=MCatStr(Tempstr,"&code=",AuthCode,NULL);
Tempstr=MCatStr(Tempstr,"&redirect_uri=",RedirectURL,NULL);
Tempstr=MCatStr(Tempstr,"&grant_type=","authorization_code",NULL);

S=HTTPMethod("POST",Tempstr,"","","","",0);
if (S)
{
Tempstr=STREAMReadLine(Tempstr,S);
while (Tempstr)
{
StripTrailingWhitespace(Tempstr);
fprintf(stderr,"OA: %s\n",Tempstr);
OAuthParseJSON(Tempstr, Vars);
Tempstr=STREAMReadLine(Tempstr,S);
}
}

*AccessToken=CopyStr(*AccessToken,GetVar(Vars,"access_token"));
*RefreshToken=CopyStr(*RefreshToken,GetVar(Vars,"refresh_token"));

ListDestroy(Vars,DestroyString);
DestroyString(Tempstr);
DestroyString(Encode);
}
示例#20
0
TFileStore *IDriveFileStoreCreate(char *Name, char *ConnectSetup)
{
TFileStore *FS;

FS=(TFileStore *) calloc(1,sizeof(TFileStore));
FS->Flags=FS_SSL | FS_WRITEABLE | FS_CHDIR_FULLPATH;
FS->Features=FS_FILE_SIZE;
FS->Vars=ListCreate();
FS->CurrDir=CopyStr(FS->CurrDir,"");
FS->InitArg=CopyStr(FS->InitArg,ConnectSetup);
FS->Name=CopyStr(FS->Name,Name);

SetVar(FS->Vars,"LSFormat:Details","%s %m %v %n ");
SetVar(FS->Vars,"LSFormat:Long","%S %m %v %n ");


FS->Create=IDriveFileStoreCreate;
FS->Open=IDriveOpen;
FS->Close=IDriveClose;
FS->ChDir=DefaultChDir;
FS->MkDir=IDriveMkDir;
FS->LoadDir=IDriveLoadDir;
FS->OpenFile=IDriveOpenFile;
FS->CloseFile=IDriveCloseFile;
FS->ReadBytes=DefaultReadBytes;
FS->WriteBytes=DefaultWriteBytes;
FS->RenameFile=IDriveRenameFile;
FS->DeleteFile=IDriveDeleteFile;
FS->GetFileSize=FileStoreGetFileSize;

return(FS);
}
示例#21
0
void OAuthDeviceGetAccessToken(char *TokenURL, char *ClientID, char *ClientSecret, char *DeviceCode, char **AccessToken, char **RefreshToken)
{
char *Tempstr=NULL, *Encode=NULL;
ListNode *Vars=NULL;
STREAM *S;

Vars=ListCreate();

Encode=HTTPQuote(Encode,ClientID);
Tempstr=MCopyStr(Tempstr,TokenURL,"?client_id=",Encode,NULL);
Encode=HTTPQuote(Encode,ClientSecret);
Tempstr=MCatStr(Tempstr,"&client_secret=",Encode,NULL);
Tempstr=MCatStr(Tempstr,"&code=",DeviceCode,NULL);
Tempstr=MCatStr(Tempstr,"&grant_type=","http://oauth.net/grant_type/device/1.0",NULL);

S=HTTPMethod("POST",Tempstr,"","","","",0);
if (S)
{
Tempstr=STREAMReadLine(Tempstr,S);
while (Tempstr)
{
StripTrailingWhitespace(Tempstr);
printf("OA: %s\n",Tempstr);
OAuthParseJSON(Tempstr, Vars);
Tempstr=STREAMReadLine(Tempstr,S);
}
}

*AccessToken=CopyStr(*AccessToken,GetVar(Vars,"access_token"));
*RefreshToken=CopyStr(*RefreshToken,GetVar(Vars,"refresh_token"));

ListDestroy(Vars,DestroyString);
DestroyString(Tempstr);
DestroyString(Encode);
}
示例#22
0
void OAuthDeviceRefreshToken(char *TokenURL, char *ClientID, char *ClientSecret, char *RequestRefreshToken, char **AccessToken, char **RefreshToken)
{
char *Tempstr=NULL, *Encode=NULL;
ListNode *Vars=NULL;
STREAM *S;

Vars=ListCreate();

Tempstr=MCopyStr(Tempstr,TokenURL,"?client_id=",ClientID,NULL);
Tempstr=MCatStr(Tempstr,"&client_secret=",ClientSecret,NULL);
Tempstr=MCatStr(Tempstr,"&refresh_token=",RequestRefreshToken,NULL);
Tempstr=MCatStr(Tempstr,"&grant_type=","refresh_token",NULL);

S=HTTPMethod("POST",Tempstr,"","","","",0);
if (S)
{
Tempstr=STREAMReadLine(Tempstr,S);
while (Tempstr)
{
StripTrailingWhitespace(Tempstr);
OAuthParseJSON(Tempstr, Vars);

Tempstr=STREAMReadLine(Tempstr,S);
}
} 

*AccessToken=CopyStr(*AccessToken,GetVar(Vars,"access_token"));
*RefreshToken=CopyStr(*RefreshToken,GetVar(Vars,"refresh_token"));

ListDestroy(Vars,DestroyString);
DestroyString(Tempstr);
DestroyString(Encode);
}
示例#23
0
static void SortAndMakeUserFontNameList( void )
{
    UInt16        i;
    DBEntryType*  dbListEntry;
    DBEntryType** userFontArray;

    currentUserFontNumber = NO_SUCH_USER_FONT;
    ClearUserFontNameList();
    if ( userFontDBList == NULL )
        return;

    numberOfUserFonts = ListSize( userFontDBList );
    if ( numberOfUserFonts == 0 )
        return;

    userFontArray   = SafeMemPtrNew( numberOfUserFonts * sizeof( DBEntryType* ) );
    userFontNames   = SafeMemPtrNew( numberOfUserFonts * sizeof( Char* ) );
    dbListEntry     = ListFirst( userFontDBList );
    for ( i = 0; i < numberOfUserFonts ; i++ ) {
        userFontArray[ i ] = dbListEntry;
        dbListEntry        = ListNext( userFontDBList, dbListEntry );
    }
    SysQSort( userFontArray, numberOfUserFonts, sizeof( DBEntryType* ),
        DBEntryCompare, 0 );
    ListDelete( userFontDBList );
    userFontDBList = ListCreate();
    for ( i = 0 ; i < numberOfUserFonts ; i++ ) {
        ListAppend( userFontDBList, userFontArray[ i ] );
        userFontNames[ i ] = userFontArray[ i ]->name;
    }
    SafeMemPtrFree( userFontArray );
}
示例#24
0
ListNode *ParserParseDocument(const char *TypeStr, const char *Doc)
{
    ListNode *Node, *Items;
    const char *Types[]= {"json","rss","yaml","config","ini","url",NULL};
    const char *ptr;
    char *Token=NULL;
    int Type;

    if (! StrValid(TypeStr)) return(NULL);
    if (! StrValid(Doc)) return(NULL);


    GetToken(TypeStr,";",&Token,0);
    StripTrailingWhitespace(Token);
    StripLeadingWhitespace(Token);

    ptr=Token;
    if (strncmp(ptr,"application/",12)==0) ptr+=12;
    if (strncmp(ptr,"x-www-form-urlencoded",21)==0) ptr="url";

    Type=MatchTokenFromList(ptr,Types,0);

    Items=ListCreate();
    ptr=Doc;
    while (isspace(*ptr)) ptr++;
    if (*ptr=='{') ptr++;
    if (*ptr=='[') ptr++;
    ParserParseItems(Type, ptr, Items, 0);

    fflush(NULL);

    return(ParserOpenItem(Items,"/"));
}
示例#25
0
文件: lists.c 项目: 8devices/Caraboot
/*
 * copy is only as large as necessary
 */
list_t ListCopy (list_t originalList)
{
	list_t tempList = NULL;
	int numItems;

	if (!originalList)
		return NULL;

	tempList = ListCreate ((*originalList)->itemSize);
	if (tempList) {
		numItems = ListNumItems (originalList);

		if (!SetHandleSize ((Handle) tempList,
				    sizeof (ListStruct) +
				    numItems * (*tempList)->itemSize)) {
			ListDispose (tempList);
			return NULL;
		}

		(*tempList)->numItems = (*originalList)->numItems;
		(*tempList)->listSize = (*originalList)->numItems;
		(*tempList)->itemSize = (*originalList)->itemSize;
		(*tempList)->percentIncrease = (*originalList)->percentIncrease;
		(*tempList)->minNumItemsIncrease =
				(*originalList)->minNumItemsIncrease;

		memcpy (ITEMPTR (tempList, 0), ITEMPTR (originalList, 0),
				numItems * (*tempList)->itemSize);
	}

	return tempList;
}
示例#26
0
/// HIFN Creates a Source VChan of a certain data type.
SourceVChan_type* init_SourceVChan_type (char 							name[], 
										 DLDataTypes 					dataType,
										 void* 							VChanOwner,
										 VChanStateChangeCBFptr_type	VChanStateChangeCBFptr)
{
	SourceVChan_type*	vchan 	= malloc(sizeof(SourceVChan_type));
	if (!vchan) return NULL;
	
	// init base VChan type
	if (init_VChan_type ((VChan_type*) vchan, name, VChan_Source, VChanOwner, (DiscardVChanFptr_type)discard_SourceVChan_type, 
						 (DisconnectVChanFptr_type)disconnectSourceVChan, VChanStateChangeCBFptr, (VChanIsConnectedFptr_type) SourceVChanIsConnected) < 0) goto Error;
	
	// init list with Sink VChans
	if (!(vchan -> sinkVChans 	= ListCreate(sizeof(SinkVChan_type*)))) goto Error;
	
	// init data packet type
	vchan->dataType = dataType;
	
	return vchan;
	
Error:
	
	discard_VChan_type ((VChan_type**)&vchan);  // do this last
	return NULL;
}
示例#27
0
void ProcessLSCmd(TFileStore *FS, TFileStore *DiskFS, int CmdFlags, char *Pattern, int LinesToList)
{
 TFileInfo *FI;
 ListNode *Items, *Curr;
 int val, count=0, total_bytes=0;
 char *Tempstr=NULL, *ptr;
 
	Items=ListCreate();
	val=LIST_INCLUDE_DIRS;
	if (CmdFlags & FLAG_LS_REFRESH) val |=LIST_REFRESH;
	if (StrLen(Pattern)==0) FileStoreLoadDir(FS,"*",Items,val);
	else FileStoreLoadDir(FS,Pattern,Items,val);

	total_bytes=DirectoryListingPrintOutput(FS, CmdFlags, LinesToList, Items);

	printf(".\n");
	if (FS->BytesAvailable > 0) Tempstr=GenerateQuotaString(Tempstr,FS);
	else Tempstr=CopyStr(Tempstr,"");
 
	if (CmdFlags & (FLAG_LS_LONGDETAILS | FLAG_LS_MEDIADETAILS)) printf("% 8d bytes total  %s\n",total_bytes,Tempstr);
	else if (CmdFlags & FLAG_LS_DETAILS) printf("% 8s total  %s\n",GetHumanReadableDataQty(total_bytes,0),Tempstr);
 
	fflush(NULL); 
	ListDestroy(Items,FileInfoDestroy);
 
	DestroyString(Tempstr);
}
示例#28
0
void InitSettings()
{
time_t Now;
struct utsname UnameData;

//Initialise timezone information, this is so that
//we don't get erratic times in log files from forked
//chrooted processes
time(&Now);
localtime(&Now);
srand(Now+getpid());
SetTimezoneEnv();


uname(&UnameData);
memset(&Settings,0,sizeof(TSettings));
Settings.MaxLogSize=999999;
Settings.MaxLogRotate=5;
Settings.LogPath=CopyStr(Settings.LogPath,"SYSLOG");
Settings.ConfigPath=CopyStr(Settings.ConfigPath,"/etc/alaya.conf");
Settings.DefaultDir=CopyStr(Settings.DefaultDir,"./");
Settings.BindAddress=CopyStr(Settings.BindAddress,"");
Settings.Flags |= FLAG_KEEPALIVES;
Settings.DirListFlags=DIR_SHOWFILES | DIR_FANCY;
Settings.AuthFlags=FLAG_AUTH_REQUIRED | FLAG_AUTH_COOKIE;
Settings.AuthPath=CopyStr(Settings.AuthPath,"/etc/alaya.auth");
Settings.AuthMethods=CopyStr(Settings.AuthMethods,"accesstoken,cookie,native");
Settings.AuthRealm=CopyStr(Settings.AuthRealm,UnameData.nodename);
Settings.IndexFiles=CopyStr(Settings.IndexFiles,"index.html,dir.html");
Settings.M3UFileTypes=CopyStr(Settings.M3UFileTypes,".mp3,.ogg,.mp4,.flv,.webm,.m4v,.m4a,.aac,.wma,.wmv");
Settings.ForbiddenURLStrings=CopyStr(Settings.ForbiddenURLStrings,"..,%00,%2e%2e");
Settings.VPaths=ListCreate();
Settings.HostConnections=ListCreate();
Settings.ScriptHandlers=ListCreate();
Settings.LoginEntries=ListCreate();
Settings.DocumentCacheTime=10;
Settings.AddressSpace=CopyStr(Settings.AddressSpace, "250M");
Settings.StackSize=CopyStr(Settings.StackSize, "1M");
Settings.ActivityTimeout=10000;
Settings.PackFormats=CopyStr(Settings.PackFormats,"tar:internal,zip:zip -");

GenerateRandomBytes(&Settings.AccessTokenKey,32,ENCODE_BASE64);
//this will be set to 80 or 443 in 'PostProcessSettings'
Settings.Port=0;

}
示例#29
0
OAUTH *OAuthCreate(const char *Type, const char *Name, const char *ClientID, const char *ClientSecret, const char *Scopes, const char *RefreshURL)
{
    OAUTH *Ctx;
    char *Tempstr=NULL, *Token=NULL;
    const char *ptr;

    if (OAuthTypes==NULL) SetupOAuthTypes();
    ptr=GetVar(OAuthTypes, Type);
    if (! StrValid(ptr)) return(NULL);

    Ctx=(OAUTH *) calloc(1,sizeof(OAUTH));

    ptr=GetToken(ptr,",",&(Ctx->Stage1), 0);
    ptr=GetToken(ptr,",",&(Ctx->Stage2), 0);
    ptr=GetToken(ptr,",",&(Ctx->VerifyTemplate), 0);
    Ctx->Name=CopyStr(Ctx->Name, Name);
    Ctx->Vars=ListCreate();
    SetVar(Ctx->Vars,"client_name",ClientID);
    SetVar(Ctx->Vars,"client_id",ClientID);
    SetVar(Ctx->Vars,"client_secret",ClientSecret);
    Tempstr=HTTPQuote(Tempstr, Scopes);
    SetVar(Ctx->Vars,"scope",Tempstr);
    SetVar(Ctx->Vars,"redirect_uri","urn:ietf:wg:oauth:2.0:oob");
    SetVar(Ctx->Vars,"connect_back_page","<html><body><h1>Code Accepted By Application</h1><body></html>");
    Ctx->AccessToken=CopyStr(Ctx->AccessToken, "");
    Ctx->RefreshToken=CopyStr(Ctx->RefreshToken, "");
    Ctx->RefreshURL=CopyStr(Ctx->RefreshURL, RefreshURL);
    Ctx->SavePath=MCopyStr(Ctx->SavePath, GetCurrUserHomeDir(), "/.oauth.creds",NULL);

    if (strcasecmp(Type, "getpocket.com")==0)
    {
        ptr=GetToken(ClientID,"-",&Token,0);
        Tempstr=MCopyStr(Tempstr, "pocketapp",Token,":authorizationFinished",NULL);
        SetVar(Ctx->Vars, "redirect_uri",Tempstr);

//Ctx->VerifyURL=MCopyStr(Ctx->VerifyURL,"https://getpocket.com/auth/authorize?request_token=",Ctx->AccessToken,"&redirect_uri=",Args,NULL);
    }
    else if (strcasecmp(Type, "implicit")==0) Ctx->Flags |= OAUTH_IMPLICIT;

    if (! OAuthKeyChain) OAuthKeyChain=ListCreate();
    ListAddNamedItem(OAuthKeyChain, Name, Ctx);

    DestroyString(Tempstr);
    DestroyString(Token);
    return(Ctx);
}
示例#30
0
eventData *Event_Create()
{
  eventData *event_data;

  event_data = (eventData*)malloc( sizeof(eventData) );
  if (!event_data) {
    fprintf( stderr, "Out of memory in Event_Create()\n" );
    return 0;
  }

  ListCreate( event_data->defs.list, eventDefInfo, 10 );
  ListCreate( event_data->list, eventInfo, 10 );
  event_data->idx = 0;
  event_data->idx_proc = 0;

  return event_data;
}