Example #1
0
bool_t UpperPath(tchar_t* Path, tchar_t* Last, size_t LastLen)
{
	tchar_t *a,*b,*c;
	bool_t HasHost;
    tchar_t Mime[32];

	if (!*Path)
		return 0;

	RemovePathDelimiter(Path);
	c = (tchar_t*)GetProtocol(Path,Mime,TSIZEOF(Mime),&HasHost);
	
	a = tcsrchr(c,'\\');
	b = tcsrchr(c,'/');
	if (!a || (b && b>a))
		a=b;

#ifdef TARGET_PS2SDK
    if (!a && (a = tcschr(c,':'))!=NULL)
        if (a[1]==0)
            a = NULL;
#endif

	if (!a)
	{
        if (tcsicmp(Mime, T("smb")) == 0) {
            *c = 0;
            tcscpy_s(Last, LastLen, Path);
            return 1;
        }

        if (HasHost && tcsicmp(Mime, T("upnp"))!=0)
			return 0;
		a=c;
		if (!a[0]) // only mime left
			a=c=Path;
	}
	else
		++a;

	if (Last)
		tcscpy_s(Last,LastLen,a);

	if (a==c)
		*a = 0;

#ifdef TARGET_PS2SDK
    if (a>c && a[-1]==':')
        *a = 0;
#endif

	while (--a>=c && (*a=='\\' || *a=='/'))
		*a = 0;

	return 1;
}
Example #2
0
File: node.c Project: Erikhht/TCPMP
static NOINLINE int FindModule(context* p,const tchar_t* Path,int Id)
{
	// important to find from the begining for Palm OS 
	// so the exising plugins are found first

	int No,Count;
	int Result = -1;

	LockEnter(p->NodeLock);
	Count = ARRAYCOUNT(p->NodeModule,nodemodule);
	if (!Path) Path = T("");
	for (No=0;No<Count;++No)
	{
		bool_t SameId = ARRAYBEGIN(p->NodeModule,nodemodule)[No].Id == Id;
		bool_t SameName = tcsicmp(Path,LangStrDef(MODULE_PATH,No))==0;

		if (SameId && Id!=0) // same Id means same module
			SameName = 1;
		if (SameName && !Id)
			SameId = 1;

		if (SameId && SameName)
		{
			Result = No;
			break;
		}
	}
	LockLeave(p->NodeLock);
	return Result;
}
Example #3
0
int StreamProtocolPriority(anynode *AnyNode, const tchar_t* URL)
{
	tchar_t Protocol[MAXPROTOCOL];
    GetProtocol(URL,Protocol,TSIZEOF(Protocol),NULL);
    if (tcsicmp(Protocol,T("file"))==0) // override for local files
        return PRI_MAXIMUM;
    return NodeClass_Priority(NodeContext_FindClass(AnyNode,NodeEnumClassStr(AnyNode,NULL,STREAM_CLASS,NODE_PROTOCOL,Protocol)));
}
Example #4
0
static CFStringBuiltInEncodings GetEncoding(const tchar_t* From)
{
    if (!From)
		return kCFStringEncodingUTF8; // use UTF-8 internally
    else if (!From[0])
		return kCFStringEncodingASCII; // regular/default strings are ASCII
	else if (tcsicmp(From,T("ASCII"))==0)
		return kCFStringEncodingASCII;
	else if (tcsicmp(From,T("UTF-8"))==0)
		return kCFStringEncodingUTF8;
	else if (tcsicmp(From,T("UTF-16"))==0)
		return kCFStringEncodingUTF16;
	else if (tcsicmp(From,T("UTF-32"))==0)
		return kCFStringEncodingUTF32;
	else if (tcsnicmp(From,T("CP"),2)==0)
		return CFStringConvertWindowsCodepageToEncoding(atoi(From+2));

	return (CFStringBuiltInEncodings)kCFStringEncodingInvalidId;
}
Example #5
0
bool_t ParserIsToken(parser* p, const tchar_t* Token)
{
	size_t n = tcslen(Token);
	tchar_t* Tmp = alloca(sizeof(tchar_t)*(n+1));
	const char* i;

	SkipSpace(p);
	if ((i=(const char*)ParserPeek(p,n))!=NULL)
	{
		GetAsciiToken(Tmp,n+1,i,n);
		if (tcsicmp(Tmp,Token)==0)
		{
			p->Buffer.ReadPos += n;
			return 1;
		}
	}
	return 0;
}
charconv* CharConvOpen(const tchar_t* From, const tchar_t* To)
{
    iconv_t CC;

    GetDefault();

    if (!From || !From[0])
        From = Current;

    if (!To || !To[0])
        To = Current;

    if (tcsicmp(To,From)==0)
        return NULL;

    CC = iconv_open(To,From);
    if (CC == (iconv_t)-1)
        return NULL;

    return (charconv*)CC;
}
Example #7
0
static int CALLBACK CompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
	openfile* p = (openfile*)lParamSort;
	openitem* a = (openitem*)lParam1;
	openitem* b = (openitem*)lParam2;
	int Result = 0;

	if (!a) return b?-1:0;
	if (!b) return 1;

	if (a->Image==IMG_DIR)
		if (b->Image==IMG_DIR)
			Result = tcsicmp(a->Name,b->Name);
		else
			Result = -1;
	else
	if (b->Image==IMG_DIR)
		Result = 1;
	else
	switch(p->SortCol)
	{
	case 0: 
		Result = tcsicmp(a->Name,b->Name); 
		break;
	case 1: 
		Result = tcsicmp(a->Ext,b->Ext); 
		if (!Result) 
			Result = tcsicmp(a->Name,b->Name);
		break;
	case 2: 
		if (a->Size == b->Size) 
			Result = tcsicmp(a->Name,b->Name);
		else
			Result = a->Size > b->Size ? 1:-1;
		break;
	case 3:
		if (a->Date == b->Date) 
			Result = tcsicmp(a->Name,b->Name);
		else
			Result = a->Date > b->Date ? 1:-1;
		break;
	}

	if (p->SortDir)
		Result = -Result;
	return Result;
}
Example #8
0
static void AddHistory(openfile* p,const tchar_t* s)
{
	int i;

	for (i=0;i<p->HistoryCount;++i)
		if (p->History[i] && tcsicmp(p->History[i],s)==0)
		{
			for (;i>0;--i)
				SwapPChar(&p->History[i],&p->History[i-1]);
			break;
		}

	if (i==p->HistoryCount)
	{
		if (i<MAXHISTORY)
			p->HistoryCount++;
		else
			free(p->History[--i]);

		for (;i>0;--i)
			p->History[i] = p->History[i-1];

		p->History[0] = tcsdup(s);
	}

	if (!p->Win.Smartphone)
	{
		int i;
		SendMessage(p->WndURL,CB_RESETCONTENT,0,0);
		for (i=0;i<p->HistoryCount;++i)
			if (p->History[i])
				SendMessage(p->WndURL,CB_ADDSTRING,0,(LPARAM)p->History[i]);
	}

	SetURLText(p,s);
}
Example #9
0
void ID3v2_Parse(const void* Ptr,size_t Len,pin* Pin,filepos_t Offset)
{
	const uint8_t* Data = (const uint8_t*)Ptr;

	
	size_t Size = ID3v2_Query(Ptr,Len);

	uint8_t* Data_org=(const uint8_t*)Ptr;
	Data_org+=Size;

	


	
//	RETAILMSG(1, (TEXT(" ^^^^11111111111111111111^^^^^^^^ID3v2_Parse  = %x , %x, %x  \r\n"), Size,&Size,Data));


	if (Size>0 && Pin)
	{
		int HeadFlag = Data[5];
		int Ver = Data[3];
		if (Ver >= 2 && Ver <= 4 && Size<=Len)
		{
			uint8_t* Tmp = NULL;

			// jump after header
			Data += 10;
			Size -= 10;
			
			if (Ver<4 && (HeadFlag & FLAG_UNSYNC))
			{
				// undo unsync coding
				Tmp = malloc(Size);
				if (Tmp)
				{
					Size = UnSync(Tmp,Data,Size);
					Data = Tmp;
				}
				else
					return;
			}

			if ((HeadFlag & FLAG_EXTENDED) && Size>=4)
			{
				// skip extended header
				size_t n = (Ver>=4)?Read7Bit(Data,4):Read8Bit(Data,4);
				Data += 4+n;
				Size -= 4+n;
			}

			while (Data_org > Data )
			{
				// parse frame
				uint8_t* Tmp = NULL;
				uint8_t* Tmp2 = NULL;
				const uint8_t* p;

				bool_t NeedDecompress = 0;
				bool_t NeedUnSync = 0;
				int Id = 0;
				int Len = 0;
				int Len2 = 0;
				int Flag = 0;
				const int* Info;

			

				if( Size <= 0 ||  Data[0]==0)
					break;

				switch (Ver)
				{
				case 2:
				    if (Size >= 6)
					{
						Id = FOURCC(Data[0],Data[1],Data[2],' ');
						Len = Read8Bit(Data+3,3);
						Data += 6;
						Size -= 6;
					}
					break;
				case 3:
				    if (Size >= 10)
					{
						Id = FOURCC(Data[0],Data[1],Data[2],Data[3]);
						Len = Read8Bit(Data+4,4);
						Flag = Read8Bit(Data+8,2);
						Data += 10;
						Size -= 10;

						if (Flag & FLAG3_UNKNOWN)
							Id = 0;

						if ((Flag & FLAG3_COMPRESSION) && Size>=4)
						{
							NeedDecompress = 1;
							Len2 = Read8Bit(Data,4);
							Data += 4;
							Size -= 4;
						}

						if ((Flag & FLAG3_GROUPID) && Size>=1)
						{
							Data++;
							Size--;
						}
					}
					break;
				case 4:
				    if (Size >= 10)
					{
						Id = FOURCC(Data[0],Data[1],Data[2],Data[3]);
						Len = Read8Bit(Data+4,4);
						Flag = Read8Bit(Data+8,2);
						Data += 10;
						Size -= 10;

						if (Flag & FLAG4_UNKNOWN)
							Id = 0;
						if ((Flag & FLAG4_GROUPID) && Size>=1)
						{
							Data++;
							Size--;
						}
						if ((Flag & FLAG4_DATALENGTH) && Size>=4)
						{
							Len2 = Read8Bit(Data,4);
							Data += 4;
							Size -= 4;
						}
						if (Flag & FLAG4_COMPRESSION)
							NeedDecompress = 1;

						if (Flag & FLAG4_UNSYNC)
							NeedUnSync = 1;
					}
					break;
				}

				p = Data;
				Data += Len;
				Size -= Len;

				if (Id && Size>=0)
					for (Info=FrameInfo;Info[0];Info+=3)
						if (Info[0]==Id)
						{
							int n;
							tchar_t Value[512];

							if (NeedUnSync)
							{
								Tmp = malloc(Len);
								if (!Tmp)
									break;
								Len = UnSync(Tmp,p,Len);
								p = Tmp;
							}

							if (NeedDecompress && Len2>0)
							{
								unsigned long n = Len2;
								Tmp2 = malloc(Len2);
								if (!Tmp2 || uncompress(Tmp2,&n,p,Len)!=Z_OK)
									break;
								Len = n;
								p = Tmp2;
							}

							switch (Info[2])
							{
							case FIELD_STRING:
								if (Len>1)
								{
									ReadStrEncode(p+1,Len-1,p[0],Value,TSIZEOF(Value));
									AddFieldStr(Pin,Info[1],Value);
								}
								break;
							case FIELD_COMMENT:
								if (Len>5)
									for (n=4;n<Len;++n)
										if (p[n]==0)
										{
											ReadStrEncode(p+n+1,Len-n-1,p[0],Value,TSIZEOF(Value));
											AddFieldStr(Pin,Info[1],Value);
											break;
										}
								break;
							case FIELD_APIC:
								if (Len>5)
								{
									int Encode = *(p++);
									--Len;

									if (Ver==2)
									{
										tcscpy_s(Value,TSIZEOF(Value),T("image/"));
										GetAsciiToken(Value+tcslen(Value),TSIZEOF(Value)-tcslen(Value),(const char*)p,3);
										Len -= 3;
										p += 3;

										if (tcsicmp(Value,T("image/jpg"))==0)
											tcscpy_s(Value,TSIZEOF(Value),T("image/jpeg"));
									}
									else
									{
										n = ReadStrEncode(p,Len,Encode,Value,TSIZEOF(Value));
										Len -= n;
										p += n;
									}
								
									++p;
									--Len;

									n = ReadStrEncode(p,Len,Encode,NULL,0); // skip description
									Len -= n;
									p += n;

									AddFieldAttachment(Pin,COMMENT_COVER,(p-(const uint8_t*)Ptr)+Offset,Len,Value);
								}
								break;
							}
							break;
						}

				free(Tmp);
				free(Tmp2);
			}

			free(Tmp);
		}
	}
}
Example #10
0
void SplitPath(const tchar_t* URL, tchar_t* Dir, int DirLen, tchar_t* Name, int NameLen, tchar_t* Ext, int ExtLen)
{
	const tchar_t *p,*p2,*p3;
	bool_t HasHost;
	tchar_t LocalURL[MAXPATH];
	tchar_t Protocol[MAXPATH];

	// mime 
	p = GetProtocol(URL,Protocol,TSIZEOF(Protocol),&HasHost);

	// dir
	p2 = tcsrchr(p,'\\');
    p3 = tcsrchr(p,'/');
	if (!p2 || (p3 && p3>p2))
        p2 = p3;

#ifdef TARGET_PS2SDK
    // "host:test.elf" -> "host:"
    // "host:/test.elf" -> "host:/" (keeping end delimiter)
    if ((p2 && p2>p && p2[-1]==':') || (!p2 && (p2 = tcschr(p,':'))!=NULL))
	{
		if (Dir)
			tcsncpy_s(Dir,DirLen,URL,p2-URL+1);
		URL = p2+1;
	}
	else
#endif
	if (p2)
	{
		if (Dir)
			tcsncpy_s(Dir,DirLen,URL,p2-URL);
		URL = p2+1;
	}
	else
	if (HasHost) // no filename, only host
	{
		if (Dir)
			tcscpy_s(Dir,DirLen,URL);
		URL += tcslen(URL);
	}
	else // no directory
	{
		if (Dir)
			tcsncpy_s(Dir,DirLen,URL,p-URL);
		URL = p;
	}

	// name
	if (tcsicmp(Protocol,T("http"))==0 && tcsrchr(URL,T('#')))
	{
		tchar_t *NulChar;
		tcscpy_s(LocalURL,TSIZEOF(LocalURL),URL);
		URL = LocalURL;
		NulChar = tcsrchr(LocalURL,T('#'));
		*NulChar = 0;
	}

	if (Name && Name == Ext)
		tcscpy_s(Name,NameLen,URL);
	else
	{
		p = tcsrchr(URL,'.');
		if (p)
		{
			if (Name)
				tcsncpy_s(Name,NameLen,URL,p-URL);
			if (Ext)
            {
                if (p[1]) ++p; // remove '.', but only if there is a real extension
				tcscpy_s(Ext,ExtLen,p);
            }
		}
		else
		{
			if (Name)
				tcscpy_s(Name,NameLen,URL);
			if (Ext)
				Ext[0] = 0;
		}
	}
}