bool BaseSetupDlg::Run(String& vars) { upp <<= GetVar("UPP"); output <<= GetVar("OUTPUT"); base <<= vars; new_base = IsNull(vars); while(TopWindow::Run() == IDOK) { String varname = ~base; String varfile = VarFilePath(varname); if(varname != vars) { if(FileExists(varfile) && !PromptOKCancel(NFormat("Overwrite existing assembly [* \1%s\1]?", varfile))) continue; if(!SaveVars(varname)) { Exclamation(NFormat("Error writing assmbly [* \1%s\1].", VarFilePath(varname))); continue; } } SetVar("UPP", ~upp); SetVar("OUTPUT", ~output); Vector<String> paths = SplitDirs(upp.GetText().ToString()); for(int i = 0; i < paths.GetCount(); i++) RealizeDirectory(paths[i]); RealizeDirectory(output); vars = varname; return true; } return false; }
int main(void) { struct Hook hook; char userdata[] = "Some user data..."; LONG ret; memset(&hook, 0, sizeof(struct Hook)); hook.h_Entry = print_var; printf("Scanning local variables:\n"); ret = ScanVars(&hook, GVF_LOCAL_ONLY, userdata); printf("ScanVars returned %d\n", ret); printf("Adding some new local variables:\n"); SetVar("var1","Value of variable 1", -1, GVF_LOCAL_ONLY); SetVar("var2","Value of variable 2", -1, GVF_LOCAL_ONLY); SetVar("var3","Value of variable 3", -1, GVF_LOCAL_ONLY); printf("Scanning local variables again:\n"); ret = ScanVars(&hook, GVF_LOCAL_ONLY, userdata); printf("ScanVars returned %d\n", ret); printf("Trying to print all variables up to var2:\n"); hook.h_Entry = print_var_break; ret = ScanVars(&hook, GVF_LOCAL_ONLY, userdata); printf("ScanVars returned %d\n", ret); }
void OAuthParseForm(char *HTML, char *SubmitType, char **SubmitURL, ListNode *HiddenVals, ListNode *QueryVals) { char *TagName=NULL, *TagData=NULL, *Type=NULL, *Name=NULL, *Value=NULL, *ptr; ptr=XMLGetTag(HTML,NULL,&TagName,&TagData); while (ptr) { if (strcmp(TagName,"input")==0) { ParseTagData(TagName,TagData,&Type,&Name,&Value); if (strcasecmp(Type,"hidden")==0) SetVar(HiddenVals,Name,Value); if (strcasecmp(Type,"submit")==0) SetVar(HiddenVals,Name,Value); if (strcasecmp(Type,"text")==0) SetVar(QueryVals,Name,Value); if (strcasecmp(Type,"password")==0) SetVar(QueryVals,Name,Value); } if (strcmp(TagName,"form")==0) { ParseTagData(TagName,TagData,&Type,&Name,SubmitURL); } ptr=XMLGetTag(ptr,NULL,&TagName,&TagData); } DestroyString(TagName); DestroyString(TagData); DestroyString(Type); DestroyString(Name); DestroyString(Value); }
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); }
RichEditHdrFtr::RichEditHdrFtr() { InsertFrame(0, toolbar); WhenRefreshBar = callback(this, &RichEditHdrFtr::RefreshBar); SetVar("PAGECOUNT", "###"); SetVar("PAGENUMBER", "#"); SetVar("__DISPLAY_VALUE_FIELDS", 1); }
void SetupOAuthTypes() { OAuthTypes=ListCreate(); SetVar(OAuthTypes, "implicit", "response_type=token&client_id=$(client_id)&redirect_uri=$(redirect_uri)&scope=basic&state=$(session)"); SetVar(OAuthTypes, "device", "client_id=$(client_id)&scope=$(scope),client_id=$(client_id)&client_secret=$(client_secret)&code=$(device_code)&grant_type=http://oauth.net/grant_type/device/1.0"); SetVar(OAuthTypes, "password", "client_name=$(client_id)&scope=$(scope)&redirect_uris=$(redirect_uri)&grant_type=password,client_id=$(client_id)&client_secret=$(client_secret)&grant_type=password&username=$(username)&password=$(password)"); SetVar(OAuthTypes, "getpocket.com", "consumer_key=$(client_id)&scope=$(scope)&redirect_uri=$(redirect_uri),consumer_key=$(client_id)&code=$(code),https://getpocket.com/auth/authorize?request_token=$(code)&redirect_uri=$(redirect_uri)"); SetVar(OAuthTypes, "auth", ",client_id=$(client_id)&client_secret=$(client_secret)&code=$(code)&grant_type=authorization_code&redirect_uri=$(redirect_uri),$(url)?response_type=code&client_id=$(client_id)&redirect_uri=$(redirect_uri)&scope=$(scope)&state=$(session)"); }
void LibUsefulInitSettings() { char *Tempstr=NULL; LibUsefulSettings=ListCreate(); SetVar(LibUsefulSettings,"LibUsefulVersion",__LIBUSEFUL_VERSION__); Tempstr=MCopyStr(Tempstr,__LIBUSEFUL_BUILD_DATE__," ",__LIBUSEFUL_BUILD_TIME__,NULL); SetVar(LibUsefulSettings,"LibUsefulBuildTime",Tempstr); DestroyString(Tempstr); }
void OAuthSetUserCreds(OAUTH *Ctx, const char *UserName, const char *Password) { char *Tempstr=NULL; Tempstr=HTTPQuote(Tempstr, UserName); SetVar(Ctx->Vars, "username", Tempstr); Tempstr=HTTPQuote(Tempstr, Password); SetVar(Ctx->Vars, "password", Tempstr); DestroyString(Tempstr); }
static void CGIDisplayOptions(const char *HashType, const char *Encoding, const char *LineEnding, int OutputLength) { char *Token=NULL, *Tempstr=NULL; const char *ptr; ListNode *Items=NULL; int i; Items=ListCreate(); printf("<tr>\r\n"); Tempstr=HashAvailableTypes(Tempstr); ptr=GetToken(Tempstr, ",",&Token,0); while (ptr) { ListAddNamedItem(Items, Token, CopyStr(NULL, Token)); ptr=GetToken(ptr, ",",&Token,0); } printf("<td align=left>Type: "); CGIPrintSelect("HashType", HashType, Items); ListClear(Items, Destroy); printf("</td>\r\n"); printf("<td align=right>Encoding: "); for (i=0; EncodingNames[i] !=NULL; i++) SetVar(Items, EncodingNames[i], EncodingDescriptions[i]); CGIPrintSelect("Encoding", Encoding, Items); ListClear(Items, Destroy); printf("</td>\r\n"); printf("<tr>\r\n"); printf("<td align=left>Line Ending: </td>"); printf("<td align=right>"); for (i=0; LineEndingNames[i] !=NULL; i++) SetVar(Items, LineEndingNames[i], LineEndingDescriptions[i]); CGIPrintSelect("LineEnding", LineEnding, Items); ListClear(Items, Destroy); printf("</td>\r\n"); printf("</tr>\r\n"); printf("<tr>\r\n"); printf("<td align=left>Hash Length: </td>"); printf("<td align=right>"); if (OutputLength > 0) printf("<input type=text width=90%% name=\"OutputLength\" style=\"font-weight: bold; font-size:16px\" value=\"%d\">\r\n",OutputLength); else printf("<input type=text width=90%% name=\"OutputLength\" style=\"font-weight: bold; font-size:16px\">\r\n"); printf("</td>\r\n"); printf("</tr>\r\n"); ListDestroy(Items, Destroy); Destroy(Tempstr); Destroy(Token); }
int main(void) { char* var="abc"; char* val="cde"; char buffer[10]; LONG len; printf("test setvar '%s'\n", val); if (SetVar(var, val, strlen(val), 0) == DOSFALSE) printf("error setvar\n"); if ((len = GetVar(var, buffer, sizeof(buffer), 0)) < 0) printf("error getvar %d\n", len); printf("test getvar '%s'\n", buffer); val=""; printf("test1 setvar '%s'\n", val); if (SetVar(var, val, strlen(val), 0) == DOSFALSE) printf("error setvar\n"); if ((len = GetVar(var, buffer, sizeof(buffer), 0)) < 0) printf("error getvar %d\n", len); printf("test1 getvar '%s'\n", buffer); val="abc"; printf("test2 setvar '%s'\n", val); if (SetVar(var, val, strlen(val), 0) == DOSFALSE) printf("error setvar\n"); if ((len = GetVar(var, buffer, sizeof(buffer), 0)) < 0) printf("error getvar %d\n", len); printf("test2 getvar '%s'\n", buffer); val=""; printf("test3 setvar '%s'\n", val); if (SetVar(var, val, strlen(val), 0) == DOSFALSE) printf("error setvar\n"); if ((len = GetVar(var, buffer, sizeof(buffer), 0)) < 0) printf("error getvar %d\n", len); printf("test3 getvar '%s'\n", buffer); val=""; printf("test4 setvar '%s'\n", val); if (SetVar(var, val, strlen(val), 0) == DOSFALSE) printf("error setvar\n"); if ((len = GetVar(var, buffer, sizeof(buffer), 0)) < 0) printf("error getvar %d\n", len); printf("test4 getvar '%s'\n", buffer); return 0; }
pid_t HandleChildRegisterRequest(STREAM *S, char *Data) { char *Tempstr=NULL, *Host=NULL, *ptr; int Flags=0; time_t LastTime; ptr=GetToken(Data,":",&Host,0); if (*ptr=='A') Flags |= LOGIN_CHECK_ALLOWED; if (*ptr=='I') Flags |= LOGGED_IN; if (*ptr=='F') Flags |= LOGIN_FAIL; if (*ptr=='C') Flags |= LOGIN_CHANGE; ptr=GetVar(Settings.HostConnections,Host); LastTime=time(NULL); if (Flags & LOGIN_CHECK_ALLOWED) { if (ptr && (strcmp(ptr,"logout")==0)) { SetVar(Settings.HostConnections,Host,""); STREAMWriteLine("logout\n",S); } else { STREAMWriteLine("okay\n",S); } } else if (Flags & LOGIN_CHANGE) { Tempstr=CopyStr(Tempstr,"logout"); SetVar(Settings.HostConnections,Host,Tempstr); STREAMWriteLine("okay\n",S); } else { if (Flags & LOGGED_IN) LastTime=0; Tempstr=FormatStr(Tempstr,"%ld",LastTime); SetVar(Settings.HostConnections,Host,Tempstr); STREAMWriteLine("okay\n",S); } STREAMFlush(S); DestroyString(Tempstr); DestroyString(Host); return(0); }
// SaveIfNeeded void SavedVariableBank::SaveIfNeeded() { // Basically, force save if the player collected a star if(GM_STAR_COUNT > GetVar(SPECIAL_SAVE_STR)) { SetVar(SPECIAL_SAVE_STR, GM_STAR_COUNT); WriteBank(); } }
char* test_serect() { loadtable(); SetVar(test,100); GetVar(outputpool,100); return outputpool; }
/// Parses GET or POST-style variable data. /// Saves to internal variable structure using HTTP::Parser::SetVar. void HTTP::Parser::parseVars(std::string data) { std::string varname; std::string varval; // position where a part start (e.g. after &) size_t pos = 0; while (pos < data.length()) { size_t nextpos = data.find('&', pos); if (nextpos == std::string::npos) { nextpos = data.length(); } size_t eq_pos = data.find('=', pos); if (eq_pos < nextpos) { // there is a key and value varname = data.substr(pos, eq_pos - pos); varval = data.substr(eq_pos + 1, nextpos - eq_pos - 1); } else { // no value, only a key varname = data.substr(pos, nextpos - pos); varval.clear(); } SetVar(urlunescape(varname), urlunescape(varval)); if (nextpos == std::string::npos) { // in case the string is gigantic break; } // erase & pos = nextpos + 1; } }
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); }
void OAuthParseJSON(char *JSON, ListNode *Vars) { char *ptr, *ptr2, *Token=NULL, *Name=NULL, *Value=NULL; StripLeadingWhitespace(JSON); StripTrailingWhitespace(JSON); ptr=JSON+StrLen(JSON)-1; if (*ptr=='}') *ptr='\0'; ptr=JSON; if (*ptr=='{') ptr++; ptr=GetToken(ptr,",",&Token,0); while (ptr) { printf("TOK: %s\n",Token); ptr2=GetToken(Token,":",&Name,0); StripTrailingWhitespace(Name); StripQuotes(Name); ptr2=GetToken(ptr2,":",&Value,GETTOKEN_QUOTES); StripLeadingWhitespace(Value); StripTrailingWhitespace(Value); StripQuotes(Value); printf("JSON: %s=%s\n",Name,Value); SetVar(Vars,Name,Value); ptr=GetToken(ptr,",",&Token,0); } DestroyString(Name); DestroyString(Value); DestroyString(Token); }
/*! * * @brief start DIA macro request for "interface-datafield" reporting value * - $r_value is set with fmt ... parameters * - load and parse diatemplates/dat_inst_%04x_%04x_%d.xml * @param dev device/sensor number * @param serial serial number of the device * @param app application number * @param cluster cluster number * @param attribut attribut number * @param member member number * @param fmt ... printf(3) like * @return void * */ void DiaReportValue(int dev,int serial,int app,int cluster,int attr,int member,char *fmt,...) { t_dia_req req; char value[1024]; va_list listArg; if (DiaDisconnected()) return; va_start(listArg,fmt); vsprintf (value, fmt, listArg); va_end(listArg); SetVar("r_value",value); memset (&req,0,sizeof(t_dia_req)); req.rq_cli = NULL; req.rq_dev = dev; req.rq_serial = serial; req.rq_app = app; req.rq_cluster = cluster; req.rq_attribut = attr; req.rq_member = member; req.rq_name = (char *)__func__; req.rq_plcDup = 1; req.rq_flags = DiaRequestMode; DiaRequestMode = 0; DiaRepInstCreate(&req,NULL); }
int DoSet (Parser *p) { Value v; int r; DynamicBuffer buf; DBufInit(&buf); r = ParseIdentifier(p, &buf); if (r) return r; /* Allow optional equals-sign: SET var = value */ if (ParseNonSpaceChar(p, &r, 1) == '=') { ParseNonSpaceChar(p, &r, 0); } r = EvaluateExpr(p, &v); if (r) { DBufFree(&buf); return r; } if (*DBufValue(&buf) == '$') r = SetSysVar(DBufValue(&buf)+1, &v); else r = SetVar(DBufValue(&buf), &v); DBufFree(&buf); return r; }
void HMACSetup(HashratCtx *Ctx) { char *Tempstr=NULL, *ptr; STREAM *S; ptr=GetVar(Ctx->Vars,"EncryptionKey"); if (StrLen(ptr)==0) { if (isatty(0)) { write(1, "Enter HMAC Key: ",16); S=STREAMFromFD(0); Tempstr=STREAMReadLine(Tempstr,S); StripTrailingWhitespace(Tempstr); SetVar(Ctx->Vars,"EncryptionKey",Tempstr); ptr=Tempstr; STREAMDisassociateFromFD(S); } //By now we must have an encryption key! if (! StrLen(ptr)) { write(1,"ERROR: No HMAC Key given!\n",27); exit(2); } } DestroyString(Tempstr); }
STREAM *InternalCopyOpenSource(TTransferContext *Ctx, TFileInfo *SrcFI) { STREAM *S; char *ptr; int val=0; //Specify the DESTINATION size in the source, for use in 'resume' transfers if (Ctx->DestFS->GetFileSize) SrcFI->ResumePoint=Ctx->DestFS->GetFileSize(Ctx->DestFS, SrcFI->Name); //Set version info if getting a particular version of file ptr=GetVar(Ctx->Vars,"Version"); SetVar(SrcFI->Vars,"Version,",ptr); if ( (Ctx->CmdFlags & FLAG_CMD_RESUME) && (Ctx->SrcFS->Features & FS_RESUME_TRANSFERS) && (Ctx->DestFS->Features & FS_RESUME_TRANSFERS) ) val |= OPEN_RESUME; S=Ctx->SrcFS->OpenFile(Ctx->SrcFS,SrcFI, val); //OPEN SOURCE DONE //Construct 'write' args. THESE ARE ARGS TO OPEN THE DEST FILE if (S) { ptr=STREAMGetValue(S,"filesize"); if (StrLen(ptr)) SrcFI->Size=atoi(ptr); else if (Ctx->SrcFS->GetFileSize) SrcFI->Size=Ctx->SrcFS->GetFileSize(Ctx->SrcFS, SrcFI->Path); } return(S); }
HTTPSession *FileSendCreateSession(char *Path, HTTPSession *Request, ListNode *Vars, int ICYInterval) { HTTPSession *Session; char *Tempstr=NULL; Session=HTTPSessionResponse(Request); Session->ResponseCode=CopyStr(Session->ResponseCode,"200 OK"); Session->ContentType=CopyStr(Session->ContentType,GetVar(Vars,"ContentType")); Session->LastModified=atoi(GetVar(Vars,"MTime-secs")); Session->ContentSize=atoi(GetVar(Vars,"FileSize")); if (Session->Flags & SESSION_ICECAST) { Session->Flags |= SESSION_ICECAST; Session->Protocol=CopyStr(Session->Protocol,"ICY"); Tempstr=FormatStr(Tempstr,"%d",ICYInterval); SetVar(Session->Headers,"icy-metaint",Tempstr); } else if (HTTPServerDecideToCompress(Request,Path)) { Session->ContentSize=0; Session->Flags |= SESSION_ENCODE_GZIP; } DestroyString(Tempstr); return(Session); }
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); }
void HashAvailableTypes(ListNode *Vars) { int i; for (i=0; HashTypes[i] !=NULL; i++) SetVar(Vars,HashTypes[i], HashTypes[i]); }
void HTTPServerSendResponse(STREAM *S, HTTPSession *Session, char *ResponseLine, char *ContentType, char *Body) { HTTPSession *Response; char *Tempstr=NULL; long ResponseCode=0; LogToFile(Settings.LogPath,"RESPONSE: '%s' to %s@%s for '%s %s'",ResponseLine,Session->UserName,Session->ClientIP,Session->Method,Session->Path); ResponseCode=strtol(ResponseLine,NULL,10); //Create 'Response' rather than using session, because things set by the client in 'Session' might //get copied into the response and interfere with the response otherwise Response=HTTPSessionCreate(); /*Copy Values from Session object into Response */ if (Session) { Response->MethodID=Session->MethodID; Response->LastModified=Session->LastModified; Response->Flags |= Session->Flags & (SESSION_KEEPALIVE | SESSION_AUTHENTICATED); //Response->Flags |= SESSION_KEEPALIVE; Response->ClientIP=CopyStr(Response->ClientIP,Session->ClientIP); Response->Path=CopyStr(Response->Path,Session->Path); Response->Method=CopyStr(Response->Method,Session->Method); Response->URL=CopyStr(Response->URL,Session->URL); Response->UserName=CopyStr(Response->UserName,Session->UserName); } Response->ResponseCode=CopyStr(Response->ResponseCode,ResponseLine); if (ResponseCode==302) SetVar(Response->Headers,"Location",Body); else Response->ContentSize=StrLen(Body); Response->ContentType=CopyStr(Response->ContentType,ContentType); if (HTTPServerDecideToCompress(Session,NULL)) { Response->Flags |= SESSION_ENCODE_GZIP; Tempstr=SetStrLen(Tempstr,Response->ContentSize *2); Response->ContentSize=CompressBytes(&Tempstr, "gzip",Body, StrLen(Body), 5); } else Tempstr=CopyStr(Tempstr,Body); if ((ResponseCode==401) || (ResponseCode==407)) HTTPServerSendHeaders(S, Response,HEADERS_AUTH); else HTTPServerSendHeaders(S, Response, HEADERS_KEEPALIVE); STREAMWriteBytes(S,Tempstr,Response->ContentSize); STREAMFlush(S); /* If HTTPServerSendHeaders set SESSION_REUSE then set that in the Session object */ //if (Response->Flags & SESSION_REUSE) Session->Flags |= SESSION_REUSE; //else Session->Flags &= ~SESSION_REUSE; ProcessSessionEventTriggers(Response); HTTPSessionDestroy(Response); DestroyString(Tempstr); }
void HTTPServerSendM3U(STREAM *S, HTTPSession *Session, char *Path, int NoOfFiles, TPathItem **Files) { char *Tempstr=NULL, *M3U=NULL, *URL=NULL, *Salt=NULL, *AccessToken=NULL, *ptr; ListNode *Vars; STREAM *F; int i; M3U=CopyStr(M3U,"#EXTM3U\n"); for (i=0; i < NoOfFiles; i++) { if (InFileTypeList(Files[i]->Path,Settings.M3UFileTypes)) { //Examine file for Artist/title information Vars=ListCreate(); F=STREAMOpenFile(Files[i]->Path, SF_RDONLY); if (F) { MediaReadDetails(F, Vars); STREAMClose(F); } ptr=GetVar(Vars, "Media-title"); if (StrLen(ptr)) { //#EXTINF - extra info - length (seconds), title Tempstr=CopyStr(Tempstr, GetVar(Vars, "Media-artist")); if (! StrLen(Tempstr)) Tempstr=CopyStr(Tempstr,"unknown-artist"); M3U=MCatStr(M3U,"#EXTINF: -1, ", Tempstr, "-", GetVar(Vars,"Media-title"),"\n",NULL); } //Actually supply the URL M3U=CatStr(M3U,Files[i]->URL); //if we are supporting access token authentication, supply that if (AuthenticateExamineMethods(Settings.AuthMethods, FALSE) & AUTH_ACCESSTOKEN) { GenerateRandomBytes(&Salt,24,ENCODE_HEX); AccessToken=MakeAccessToken(AccessToken, Session->UserName, Salt, Session->ClientIP, Files[i]->URL); M3U=MCatStr(M3U,"?AccessToken=",AccessToken,NULL); } ListDestroy(Vars,DestroyString); M3U=CatStr(M3U,"\n"); } } Tempstr=MCopyStr(Tempstr,Path,".m3u",NULL); SetVar(Session->Headers,"Content-disposition",Tempstr); HTTPServerSendResponse(S, Session, "200 OK","audio/x-mpegurl",M3U); DestroyString(AccessToken); DestroyString(Tempstr); DestroyString(Salt); DestroyString(URL); DestroyString(M3U); }
int M3UStreamInfo(STREAM *S, char *Title, char *URL, char *FirstLine, int Flags) { char *Tempstr=NULL, *Doc=NULL, *Resolution=NULL, *Bandwidth=NULL, *ptr; ListNode *Vars=NULL; int RetVal=FALSE; Vars=ListCreate(); Tempstr=CopyStr(Tempstr,FirstLine); while (Tempstr) { StripTrailingWhitespace(Tempstr); if (Flags & (FLAG_DEBUG2 | FLAG_DEBUG3)) fprintf(stderr,"%s\n",Tempstr); if (strncmp("#EXT-X-STREAM-INF",Tempstr,StrLen("#EXT-X-STREAM-INF"))==0) M3UParseStreamInfo(Tempstr, &Resolution, &Bandwidth); 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); ptr=FileTypeFromURL(Doc); if (strcmp(ptr,"m3u8")==0) ptr="stream"; if (StrLen(Resolution)) { if (StrLen(ptr)) Tempstr=MCopyStr(Tempstr,"item:",ptr,":",Resolution,NULL); else Tempstr=MCopyStr(Tempstr,"item:stream:",Resolution,NULL); } else if (StrLen(Bandwidth)) { if (StrLen(ptr)) Tempstr=MCopyStr(Tempstr,"item:",ptr,":",Bandwidth,NULL); else Tempstr=MCopyStr(Tempstr,"item:stream:",Bandwidth,NULL); } else Tempstr=CopyStr(Tempstr,"ID"); SetVar(Vars,Tempstr,Doc); } Tempstr=STREAMReadLine(Tempstr,S); } ptr=GetVar(Vars,"ID"); if (! StrLen(ptr)) Type=SelectDownloadFormat(Vars, TYPE_REFERENCE, FALSE); ptr=GetVar(Vars,"ID"); if (StrLen(ptr)) RetVal=DownloadM3U(ptr, Title, Flags); ListDestroy(Vars,DestroyString); DestroyString(Tempstr); DestroyString(Resolution); DestroyString(Bandwidth); DestroyString(Doc); return(RetVal); }
static void cmd_set(const char *cmd, const char *args) { char vn[MAX_CMDLEN]; if (get_token(&args, vn, sizeof(vn), 1)) { ScriptError("Expected <varname>"); return; } SetVar(vn, args); }
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); }
void DispatchCmd() { switch(curcmd) { case READFRAME: SwapBuffers(); break; case SETCONTROL: SetVar(arg_buffer[0], *((int *) (arg_buffer + 1))); break; default: break; } }
// READ FILE // The format of the save file is simply keys and values separated by newlines void SavedVariableBank::ReadFile(std::wfstream* pFilestream) { if(pFilestream != NULL && pFilestream->is_open()) { std::wstring line; double val = 0; while(getline(*pFilestream, line)) { std::wstring key = line; std::wstring val_str; getline(*pFilestream, val_str); val = _wtof(val_str.c_str()); SetVar(key, val); } } }