Example #1
0
int OAuthFinalize(OAUTH *Ctx, const char *URL)
{
    char *Tempstr=NULL;
    int result;

    Tempstr=SubstituteVarsInString(Tempstr, Ctx->Stage2, Ctx->Vars,0);
    result=OAuthGrant(Ctx, URL, Tempstr);
    if (StrValid(Ctx->AccessToken)) OAuthSave(Ctx, "");

    DestroyString(Tempstr);
    return(result);
}
Example #2
0
int OAuthStage1(OAUTH *Ctx, const char *URL)
{
    char *Tempstr=NULL;
    int result;

    Tempstr=GetRandomAlphabetStr(Tempstr, 10);
    SetVar(Ctx->Vars, "session",Tempstr);
    SetVar(Ctx->Vars, "url",URL);
    Tempstr=SubstituteVarsInString(Tempstr, Ctx->Stage1, Ctx->Vars, 0);

    if (StrLen(Tempstr))
    {
        if (Ctx->Flags & OAUTH_IMPLICIT) result=OAuthImplicit(Ctx, URL, Tempstr);
        else result=OAuthGrant(Ctx, URL, Tempstr);
    }

    if (StrLen(Ctx->VerifyTemplate))
    {
        Ctx->VerifyURL=SubstituteVarsInString(Ctx->VerifyURL, Ctx->VerifyTemplate, Ctx->Vars,0);
    }

    DestroyString(Tempstr);
    return(result);
}
Example #3
0
char *LogFileInternalGetRotateDestinationPath(char *RetStr, TLogFile *LogFile)
{
char *Tempstr=NULL;

	Tempstr=CopyStr(Tempstr, STREAMGetValue(LogFile->S,"RotatePath"));
	if (StrLen(Tempstr) && strchr(Tempstr,'$'))
	{
		STREAMSetValue(LogFile->S, "Date",GetDateStr("%Y_%m_%d",NULL));
		STREAMSetValue(LogFile->S, "Time",GetDateStr("%H:%M:%S",NULL));
		RetStr=SubstituteVarsInString(RetStr,Tempstr,LogFile->S->Values,0);
	}
	else RetStr=CopyStr(RetStr,LogFile->Path);

	DestroyString(Tempstr);

return(RetStr);
}
Example #4
0
int ConfigLoad(const char *CmdLine, const char *ConfigPaths, char **CrayonizerDir, ListNode *CrayonList)
{
int RetVal=FALSE;
char *Tempstr=NULL, *UserDir=NULL, *Token=NULL;
ListNode *Vars;
const char *ptr;
int i;


Vars=ListCreate();
SetVar(Vars,"SystemConfigDir","/etc");
SetVar(Vars,"SystemCrayonizerDir","/etc/crayonizer.d");
GetToken(CmdLine," ",&Tempstr,0);
SetVar(Vars,"Command",Tempstr);
UserDir=CopyStr(UserDir,GetCurrUserHomeDir());
SetVar(Vars,"UserDir",UserDir);
Tempstr=MCopyStr(Tempstr,UserDir,"/.crayonizer.d",NULL);
SetVar(Vars,"UserCrayonizerDir",Tempstr);


ptr=GetToken(ConfigPaths, ",", &Token, GETTOKEN_QUOTES);
while (ptr)
{
	Tempstr=SubstituteVarsInString(Tempstr,Token,Vars,0);
	if (ConfigReadFile(Tempstr, CmdLine, CrayonizerDir, CrayonList))
	{
		RetVal=TRUE;
		break;
	}
ptr=GetToken(ptr, ",", &Token, GETTOKEN_QUOTES);
}


if (! RetVal) fprintf(stderr, "ERROR! Crayonizer can't find config file in '%s'.\n", ConfigPaths);

Destroy(Tempstr);
Destroy(UserDir);
Destroy(Token);

return(RetVal);
}
Example #5
0
char *HTTPServerSubstituteArgs(char *RetStr, const char *Template, HTTPSession *Session)
{
ListNode *Vars;
char *Name=NULL, *Value=NULL, *ptr;


Vars=ListCreate();
ptr=GetNameValuePair(Session->Arguments,"&","=",&Name,&Value);
while (ptr)
{
SetVar(Vars,Name,Value);
ptr=GetNameValuePair(ptr,"&","=",&Name,&Value);
}

RetStr=SubstituteVarsInString(RetStr, Template, Vars, 0);

ListDestroy(Vars, DestroyString);
DestroyString(Name);
DestroyString(Value);


return(RetStr);
}
Example #6
0
char *SessionSubstituteVars(char *RetStr, char *Format, TSession *Session)
{
ListNode *Vars;
char *Tempstr=NULL;

Tempstr=CopyStr(RetStr,"");
Vars=ListCreate();

Tempstr=SetStrLen(Tempstr,4096);
gethostname(Tempstr, 4096);
SetVar(Vars,"ServerHost",Tempstr);
Tempstr=FormatStr(Tempstr,"%d",Settings.Port);
SetVar(Vars,"ServerPort",Tempstr);
SetVar(Vars,"Interface",Settings.Interface);
SetVar(Vars,"Date",GetDateStr("%Y/%m/%d",NULL));
SetVar(Vars,"Date",GetDateStr("%H:%M:%S",NULL));
SetVar(Vars,"DateTime",GetDateStr("%Y/%m/%d %H:%M:%S",NULL));


//This function might be called before session setup, where all
//that we can substitute are 'interface' and 'serverhost/port' etc
if (Session)
{
	SetVar(Vars,"ClientHost",Session->ClientHost);
	SetVar(Vars,"ClientIP",Session->ClientIP);
	SetVar(Vars,"ClientMAC",Session->ClientMAC);
	SetVar(Vars,"ServerIP",Session->ServerIP);
	SetVar(Vars,"User",Session->User);
	SetVar(Vars,"RealUser",Session->RealUser);
}

Tempstr=SubstituteVarsInString(Tempstr,Format,Vars,0);

ListDestroy(Vars,DestroyString);

return(Tempstr);
}
Example #7
0
void IcecastSendData(STREAM *Input, STREAM *Output, int ICYInterval)
{
char *ICYMessage=NULL, *Tempstr=NULL;
int BuffSize=4096, BytesRead=0, len, result;
ListNode *Vars;

	Vars=ListCreate();
	SetVar(Vars, "Title",GetBasename(Input->Path));
	MediaReadDetails(Input,Vars);

	ICYMessage=SubstituteVarsInString(ICYMessage,"StreamTitle='$(Title)'; StreamArtist='$(Artist)';",Vars,0);
	LogToFile(Settings.LogPath,"Open: %s, message: %s",Input->Path,ICYMessage);
	Tempstr=SetStrLen(Tempstr,BuffSize);
	while (TRUE) 
	{
		len=ICYInterval-BytesRead;
		if (len > BuffSize) len=BuffSize;
		result=STREAMReadBytes(Input,Tempstr,len);
		if (result==EOF) break;

		BytesRead+=result;
		STREAMWriteBytes(Output,Tempstr,result);

		if (BytesRead==ICYInterval)
		{
			LogToFile(Settings.LogPath,"SEND ICY: %s",ICYMessage);
			BytesRead=0;
			SendICYMessage(Output, ICYMessage);
			//Don't send it again.
			ICYMessage=CopyStr(ICYMessage,"");
		}	
	}

ListDestroy(Vars,DestroyString);
DestroyString(ICYMessage);
DestroyString(Tempstr);
}
Example #8
0
pid_t HandleIconRequest(STREAM *ClientCon, char *Data)
{
HTTPSession *Response;
char *Name=NULL, *Value=NULL, *ptr, *tptr;
char *Tempstr=NULL;
ListNode *Vars;
pid_t pid;


pid=fork();
if (pid==0)
{
Response=ParseSessionInfo(Data);
Vars=ListCreate();
ptr=GetNameValuePair(Response->Arguments,"&","=",&Name,&Tempstr);
while (ptr)
{
	Value=HTTPUnQuote(Value,Tempstr);
	SetVar(Vars,Name,Value);
	if (strcasecmp(Name,"MimeType")==0)
	{
		tptr=GetToken(Value,"/",&Tempstr,0);
		SetVar(Vars,"MimeClass",Tempstr);
		SetVar(Vars,"MimeSub",tptr);
	}
	ptr=GetNameValuePair(ptr,"&","=",&Name,&Tempstr);
}

	if (! SwitchGroup(Response->Group))
	{
		LogToFile(Settings.LogPath,"WARN: Failed to switch to group '%s' for mimeicons '%s'", Response->RealUser, Tempstr);
	}

	if (! SwitchUser(Response->RealUser))
	{
		LogToFile(Settings.LogPath,"ERROR: Failed to switch to user '%s' when getting icons from '%s'", Response->SearchPath);
		LogFileFlushAll(TRUE);
		_exit(0);
	}


	STREAMWriteLine("READY\n",ClientCon); STREAMFlush(ClientCon);
	ptr=GetToken(Response->SearchPath,":",&Value,0);
	while (ptr)
	{
		Tempstr=SubstituteVarsInString(Tempstr,Value,Vars,0);
		if (access(Tempstr,R_OK)==0) break;
		ptr=GetToken(ptr,":",&Value,0);
	}
		
	//HTTPServerSendDocument(ClientCon, Response, Tempstr, HEADERS_SENDFILE|HEADERS_USECACHE|HEADERS_KEEPALIVE);
	HTTPServerSendDocument(ClientCon, Response, Tempstr, HEADERS_SENDFILE|HEADERS_USECACHE);
	//exit 1 means we can keep connection alive for reuse
	LogFileFlushAll(TRUE);
	_exit(1);
}

DestroyString(Name);
DestroyString(Value);
DestroyString(Tempstr);

return(pid);
}