예제 #1
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);
}
예제 #2
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);
}
예제 #3
0
void ConfigFileSaveFileStores()
{
STREAM *S;
char *Tempstr=NULL, *PortStr=NULL, *ptr;
ListNode *Curr;
TFileStore *FS;


Tempstr=MCopyStr(Tempstr,GetCurrUserHomeDir(),"/.fileferry.conf",NULL);
S=STREAMOpenFile(Tempstr,O_CREAT | O_TRUNC | O_WRONLY);
if (S)
{
	Curr=ListGetNext(FileStores);
	while (Curr)
	{	
		FS=(TFileStore *) Curr->Item;	
		PortStr=FormatStr(PortStr,"%d",FS->Port);
		if (! StrLen(FS->Name)) Tempstr=MCopyStr(Tempstr,"FileStore ",FS->Type,":",FS->Logon,"@",FS->Host,"\n{\n",NULL);
		else Tempstr=MCopyStr(Tempstr,"FileStore ",FS->Name,"\n{\n",NULL);
		Tempstr=MCatStr(Tempstr, "Type: ",FS->Type,"\n","Host: ",FS->Host,"\n","Port: ",PortStr,"\n","Login: "******"\n","Password: "******"\n",NULL);
		if (FS->Settings & FS_OAUTH) 
		{
			ptr=GetVar(FS->Vars,"OAuthRefreshToken");
			if (StrLen(ptr)) Tempstr=MCatStr(Tempstr, "OAuth\nRefreshToken: ", ptr,"\n",NULL);
		}
		Tempstr=MCatStr(Tempstr, "}\n\n",NULL);
		STREAMWriteLine(Tempstr,S);
		Curr=ListGetNext(Curr);
	}
	STREAMClose(S);
}
else printf("ERROR: Failed to open config file\n");

DestroyString(Tempstr);
DestroyString(PortStr);
}
예제 #4
0
static void MMapSetup()
{
char *FName=NULL, *Tempstr=NULL;
struct stat Stat;
int MMapSize=4096, result;
STREAM *S;

if (! CrayonizerMMap)
{

FName=MCopyStr(FName, GetCurrUserHomeDir(), "/.crayonizer.mmap", NULL);

result=stat(FName, &Stat);
if ((result==-1) || (Stat.st_size < MMapSize))
{
S=STREAMOpen(FName, "w");
if (S)
{
Tempstr=SetStrLen(Tempstr, MMapSize);
memset(Tempstr, 0, MMapSize);
STREAMWriteBytes(S, Tempstr, MMapSize);
STREAMClose(S);
}

}


S=STREAMOpen(FName, "r+M");
if (S) CrayonizerMMap=STREAMGetItem(S, "MMap");
}

//Don't close!
//STREAMClose(S);
Destroy(Tempstr);
Destroy(FName);
}