Exemplo n.º 1
0
void DisplayTransferStatus(char *Line, unsigned int transferred, unsigned int total, unsigned int *percent, unsigned int secs,int CmdFlags, int Throttle)
{
int result=0, cols=80, bps=0;
char *Tempstr=NULL, *TimeStr=NULL, *ptr=NULL;
static int ThrotCount=0;
struct winsize w;


	if (Settings.Flags & FLAG_QUIET) return;
	if (CmdFlags & FLAG_QUIET) return;
	if (! isatty(1)) return;

	ptr=getenv("COLUMNS");
	if (ptr) cols=atoi(ptr);
	printf("\r");
	if (total==0) Tempstr=FormatStr(Tempstr,"%s bytes sent ",GetHumanReadableDataQty(transferred,0));
	else
	{
	result=(transferred * 100) / total;
//	if (result != *percent)
	{
		Tempstr=FormatStr(Tempstr,"%d%% %s of ",result,GetHumanReadableDataQty(transferred,0));
		Tempstr=CatStr(Tempstr,GetHumanReadableDataQty(total,0));
	}
	*percent=result;
	}

bps=transferred / secs;
TimeStr=FormatStr(TimeStr," in %d secs %s Bps ",secs,GetHumanReadableDataQty(bps,0) );

if ((Throttle > 0) && (bps > Throttle)) 
{
	ThrotCount++;
	usleep(ThrotCount * 250000);
}
else if (ThrotCount > 0) ThrotCount--;

if (ThrotCount > 0) Tempstr=MCatStr(Tempstr,TimeStr, Line, " (throttling)      ",NULL);
else Tempstr=MCatStr(Tempstr,TimeStr, Line, "           ",NULL);


ioctl(0, TIOCGWINSZ, &w);
if (StrLen(Tempstr) > w.ws_col) Tempstr[w.ws_col]='\0';

printf("%s",Tempstr);
fflush(NULL);

DestroyString(TimeStr);
DestroyString(Tempstr);
}
Exemplo n.º 2
0
char *GenerateQuotaString(char *RetStr, TFileStore *FS)
{
double Percent;
char *Tempstr=NULL;

Percent= (FS->BytesUsed * 100.0) / FS->BytesAvailable;

Tempstr=CopyStr(Tempstr, GetHumanReadableDataQty(FS->BytesUsed,0));
RetStr=FormatStr(RetStr,"%0.2f%% of quota used (%s / %s)",Percent,Tempstr, GetHumanReadableDataQty(FS->BytesAvailable,0));

DestroyString(Tempstr);

return(RetStr);
}
Exemplo n.º 3
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);
}
Exemplo n.º 4
0
int DisplayAvailableFormats(ListNode *Vars, char *Formats, int ShowSize)
{
char *URL=NULL, *Token=NULL, *TokenID=NULL, *Tempstr=NULL, *ptr;
STREAM *S;
int result=TRUE;

fprintf(stderr, "\nFormats available for this Movie: ");

ptr=GetToken(Formats," ",&Token,0);
while (ptr)
{
if (StrLen(Token)) TokenID=MCopyStr(TokenID,"item:",Token,NULL);

URL=CopyStr(URL,GetVar(Vars,TokenID));

if (strcmp(Token,"reference") !=0)
{
	fprintf(stderr,"%s",Token);

	if (ShowSize)
	{
	S=HTTPMethod("HEAD",URL,NULL,NULL);
	if (S)
	{
		Tempstr=CopyStr(Tempstr,STREAMGetValue(S,"HTTP:ResponseCode"));
		if (strcmp(Tempstr,"403") ==0) 
		{
			printf("\nERROR: %s response for %s\n",Tempstr,URL);
			result=FALSE;
			break;
		}
		else if (strcmp(Tempstr,"200")==0)
		{
			Tempstr=CopyStr(Tempstr,STREAMGetValue(S,"HTTP:Content-length"));
			fprintf(stderr, " (%s)",GetHumanReadableDataQty(strtod(Tempstr,NULL),FALSE));
			STREAMClose(S);
		}
	}
	}
}
fprintf(stderr,", ");

ptr=GetToken(ptr," ",&Token,0);
}

fprintf(stderr,"\n\n",Tempstr);

DestroyString(Token);
DestroyString(TokenID);
DestroyString(Tempstr);
DestroyString(URL);

return(result);
}
Exemplo n.º 5
0
int ProcessGetFileInfo(TFileStore *FS, char *Pattern, char *Arg, int CmdFlags, ListNode *Vars)
{
ListNode *Items=NULL, *Curr;
char *Tempstr=NULL, *IncludePattern=NULL, *ExcludePattern=NULL, *ptr;
TFileInfo *FI;
int result=FALSE, Flags, i;
char *DisplayVars[]={"Category","Author","Subtitle","Duration","Dimensions",NULL};
//"Summary","Description",NULL};

IncludePattern=CopyStr(IncludePattern,GetVar(Vars,"IncludePattern"));
ExcludePattern=CopyStr(ExcludePattern,GetVar(Vars,"ExcludePattern"));

Items=ListCreate();

Flags=LIST_REFRESH;
//if (CmdFlags & FLAG_CMD_RECURSE) Flags |= LIST_INCLUDE_DIRS;
FileStoreLoadDir(FS,Pattern,Items, Flags);
Curr=ListGetNext(Items);

while (Curr)
{
	FI=(TFileInfo *) Curr->Item;

  if (FileIncluded(FI,IncludePattern,ExcludePattern,CmdFlags, Vars))
	{
		if (FI->Type==FTYPE_DIR) 
		{
			if (CmdFlags & FLAG_CMD_RECURSE) InternalRecurseInfoCommand(FS, FI->Name, Arg,  CmdFlags, Vars, ProcessGetFileInfo);
		}
		else 
		{
			printf("\nInfo For %s\n",FI->Path);
			printf("Size: %s (%d bytes)\n",GetHumanReadableDataQty(FI->Size,0),FI->Size);
			printf("ContentType: %s\n",FI->MediaType);

			printf("Timestamp: %s\n",GetDateStrFromSecs("%Y/%m/%d %H:%M:%S",FI->Mtime,NULL));
			for (i=0; DisplayVars[i]; i++)
			{
				ptr=GetVar(FI->Vars,DisplayVars[i]);
				if (StrLen(ptr)) printf("%s: %s\n",DisplayVars[i],ptr);
			}
		}
	}

Curr=ListGetNext(Curr);
}

ListDestroy(Items,FileInfoDestroy);

DestroyString(IncludePattern);
DestroyString(ExcludePattern);
DestroyString(Tempstr);
}
Exemplo n.º 6
0
void HTTPServerSendDirList(STREAM *S, HTTPSession *Session, char *Path, int Flags, int NoOfFiles, TPathItem **Files)
{
char *HTML=NULL, *Tempstr=NULL;
int i, HasMedia=FALSE;
int FileCount=0, DirCount=0, ByteCount=0;
TPathItem *PI;
const char *p_MimeIconsURL=NULL;

//The title headers for the directory are added in 'FinalizeDirListHTML' believe it or not

PI=VPathFind(PATHTYPE_MIMEICONS, NULL);
if (PI) p_MimeIconsURL=PI->URL;

if (Settings.DirListFlags & DIR_FANCY) 
{
HTML=CatStr(HTML,"<table align=center width=90%% border=0>\r\n");

Tempstr=CopyStr(Tempstr,Session->URL);
HTML=CatStr(HTML,"<tr bgcolor=\"#AAAAFF\">");

//This one is for checkbox
if (Settings.DirListFlags & DIR_INTERACTIVE) HTML=MCatStr(HTML,"<th align=center><a href=\"",Session->URL,"?format=html&all-selected=true\" onclick=\"setCheckboxes(1); return(false);\">all</a> - <a href=\"",Session->URL,"\" onclick=\"setCheckboxes(0); return(false);\">none</a></th>",NULL);
HTML=FancyHeading(HTML,"Type",SORT_TYPE,Tempstr,Flags);
HTML=FancyHeading(HTML,"Name",SORT_NAME,Tempstr,Flags);
HTML=FancyHeading(HTML,"Last Modified",SORT_TIME,Tempstr,Flags);
HTML=FancyHeading(HTML,"Size",SORT_SIZE,Tempstr,Flags);

//this one is for action buttons
if (Settings.DirListFlags & DIR_INTERACTIVE) HTML=CatStr(HTML,"<td> &nbsp; </td>");
HTML=CatStr(HTML,"</tr>\r\n");
}

for (i=0; i < NoOfFiles; i++)
{
	if (Settings.DirListFlags & DIR_FANCY) 
	{
		HTML=FormatFancyDirItem(HTML,i,Files[i],p_MimeIconsURL, Flags);
		if (InFileTypeList(Files[i]->Path,Settings.M3UFileTypes)) HasMedia=DIR_HASMEDIA;
		if (Files[i]->Type==PATHTYPE_DIR) DirCount++;
		else
		{
			FileCount++;
			ByteCount+=Files[i]->Size;
		}
	}
	else 
	{
		HTML=MCatStr(HTML,"<a href=\"",Files[i]->URL,"\">",Files[i]->Name,"</a><br>\r\n",NULL);
	}
}


if (Settings.DirListFlags & DIR_FANCY) 
{
	if (Settings.DirListFlags & DIR_INTERACTIVE) i=6;
	else i=4;

	//DirCount-1 here because we will have counted '..'
	if (DirCount > 0) DirCount--;

	Tempstr=FormatStr(Tempstr,"<tr bgcolor=\"#AAAAFF\"><td align=center colspan=%d>%d Files and %d Subdirectories, %s bytes total</td></tr>",i,FileCount,DirCount,GetHumanReadableDataQty((double) ByteCount,0));
	HTML=MCatStr(HTML,Tempstr,"</table>\r\n",NULL);
}


Tempstr=FinalizeDirListHTML(Tempstr, Session, Path, HTML, p_MimeIconsURL, HasMedia | Settings.DirListFlags);
HTTPServerSendResponse(S, Session, "200 OK","text/html",Tempstr);

DestroyString(Tempstr);
DestroyString(HTML);
}
Exemplo n.º 7
0
char *FormatFancyDirItem(char *RetStr, int count, TPathItem *File, const char *MimeIconsURL, int Flags)
{
char *Tempstr=NULL, *FileType=NULL, *DateStr=NULL, *DisplayName=NULL, *Interact=NULL;
char *Comment=NULL, *CheckBox=NULL, *ptr;
char *bgcolor;
ListNode *Vars;

	
	Vars=ListCreate();
	LoadFileProperties(File->Path, Vars);

/*
	ptr=GetVar(Vars,"comment");
	if (StrLen(ptr)) 
	{
		Comment=MCopyStr(Comment," title=\"",ptr,"\" ",NULL);
	}
	else Comment=CopyStr(Comment,"");
*/

	Comment=FormatFancyDirComment(Comment, Vars);

		if ((count % 2)==0) bgcolor="#FFFFFF";
		else bgcolor="#CCCCCC";

		if ((Now - File->Mtime) < 60)
		{
			DateStr=FormatStr(DateStr,"<font color=red>%d seconds ago</font>",Now - File->Mtime);
		}
		else DateStr=CopyStr(DateStr,GetDateStrFromSecs("%Y/%m/%d %H:%M:%S",File->Mtime,NULL));

		FileType=FormatFileType(FileType, File, Vars, MimeIconsURL);
		//Okay, start building the actual table row
		RetStr=MCatStr(RetStr, "<tr bgcolor=\"",bgcolor,"\">",NULL);
		Interact=CopyStr(Interact,"");
		CheckBox=CopyStr(CheckBox,"");

		if (strcmp(File->Name,"..")==0) 
		{
			DisplayName=CopyStr(DisplayName,".. (Parent Directory)");
			if (Settings.DirListFlags & DIR_INTERACTIVE) CheckBox=CopyStr(CheckBox,"<td align=\"center\">&nbsp;</td>");
		}
		else 
		{
			if (Settings.DisplayNameLen && (StrLen(File->Name) > Settings.DisplayNameLen)) 
			{
			DisplayName=CopyStrLen(DisplayName,File->Name,Settings.DisplayNameLen);
			DisplayName=CatStr(DisplayName,"...");
			}
			else DisplayName=CopyStr(DisplayName,File->Name);


		if (Settings.DirListFlags & DIR_INTERACTIVE)
		{
			if (Flags & SELECT_ALL) CheckBox=MCatStr(CheckBox,"<td align=\"center\"><input type=\"checkbox\" name=\"selected\" value=\"",File->Name,"\" checked /></td>",NULL);
			else CheckBox=MCatStr(CheckBox,"<td align=\"center\"><input type=\"checkbox\" name=\"selected\" value=\"",File->Name,"\" /></td>",NULL);

			//Interaction string will be added to end of line
			Interact=MCatStr(Interact,"<input type='submit' name='edit:",File->URL,"' value='Edit' /> ",NULL);
			Interact=MCatStr(Interact,"<input type='submit' name='del:",File->URL,"' value='Del' /> ",NULL);
			
			//one day, but not yet
			//if (strncasecmp(File->ContentType,"audio/",6)==0) Interact=MCatStr(Interact,"<input type=\"button\" onclick=\"javascript: addaudio('",File->URL,"');\" value=\"Play\" /> ",NULL);
		}
		}

		Tempstr=FormatStr(Tempstr,"%s<td title=\"%s\">%s</td><td><a href=\"%s\" title=\"%s\">%s</a></td><td align=right> &nbsp; %s</td><td align=right> &nbsp; %s</td><td align=center>%s</td>",CheckBox,Comment,FileType,File->URL, File->Path, DisplayName, DateStr, GetHumanReadableDataQty((double) File->Size,0), Interact);

		//Append it all to our output
		RetStr=MCatStr(RetStr,Tempstr,"</tr>\r\n",NULL);

		DestroyString(DisplayName);
		DestroyString(FileType);
		DestroyString(Interact);
		DestroyString(Comment);
		DestroyString(Tempstr);
		DestroyString(DateStr);

	ListDestroy(Vars,DestroyString);

return(RetStr);
}
Exemplo n.º 8
0
//Display progress of download
void DisplayProgress(char *FullTitle, char *Format, double bytes_read, double DocSize, int PrintName)
{
double Percent=0, Bps=0, ETAsecs=0;
char *HUDocSize=NULL, *BpsStr=NULL, *ETAStr=NULL, *Title=NULL;
static time_t SpeedStart=0, LastDisplay=0;
static double PrevBytesRead=0;
time_t Now;

time(&Now);
if (bytes_read==0) SpeedStart=Now;

if (CheckForKeyboardInput()) PrintName=TRUE;


Title=CopyStrLen(Title,FullTitle,30);
Title=CatStr(Title,"...");
if (! (Flags & FLAG_QUIET)) 
{
if (PrintName) fprintf(stderr,"\nGetting: %s  Size: %s  Format: %s\n",Title,GetHumanReadableDataQty(DocSize,0), Format);
}

if ((Now != SpeedStart) && (Now != LastDisplay))
{
BpsStr=CopyStr(BpsStr,"");
if (SpeedStart > 0)
{
	Bps=(bytes_read - PrevBytesRead) / (Now-SpeedStart);
	BpsStr=MCopyStr(BpsStr,GetHumanReadableDataQty(Bps,0),"/s ",NULL);
}

if (DocSize)
{
	HUDocSize=CopyStr(HUDocSize,GetHumanReadableDataQty(DocSize,0));

	Percent=bytes_read * 100.0 / DocSize;

	if (! (Flags & FLAG_QUIET)) 
	{
		if (bytes_read > 0)
		{
		ETAsecs=(DocSize-bytes_read) / Bps;
		ETAStr=FormatStr(ETAStr,"%d:%02d",(int) ETAsecs/60, (int) ETAsecs % 60);
		}
		else ETAStr=CopyStr(ETAStr,"??:??");

		fprintf(stderr,"	Progress: %0.2f%%  %s of %s  %s  ETA: %s         \r",Percent,GetHumanReadableDataQty(bytes_read,0),HUDocSize,BpsStr,ETAStr);
		
	}


	sprintf(CmdLine,"%s %0.2f%% %s          \0",ProgName,Percent,Title);

	if ((PlayerPid==0) && (Percent > PlayerLaunchPercent) && (Player)) LaunchPlayer();
}
else
{
	if (! (Flags & FLAG_QUIET)) fprintf(stderr,"	Progress: %s %s     \r",GetHumanReadableDataQty((double) bytes_read,0),BpsStr);
	sprintf(CmdLine,"%s %s              \0",ProgName,Title);
}

fflush(NULL);
if (Now - SpeedStart > 5) 
{
	SpeedStart=Now;
	PrevBytesRead=bytes_read;
}
LastDisplay=Now;
}

DestroyString(HUDocSize);
DestroyString(BpsStr);
DestroyString(Title);
}