[Mplayer-cvslog] CVS: main/libmpdemux url.c,1.9,1.10 url.h,1.4,1.5

Bertrand Baudet bertrand at mplayer.dev.hu
Sat Dec 15 00:48:50 CET 2001


Update of /cvsroot/mplayer/main/libmpdemux
In directory mplayer:/var/tmp.root/cvs-serv11710

Modified Files:
	url.c url.h 
Log Message:
Added 2 functions to escape/unescape the url as described in the RFC 2396.
Code borrowed from ASFRecorder.


Index: url.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/url.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- url.c	14 Dec 2001 20:45:30 -0000	1.9
+++ url.c	14 Dec 2001 23:48:47 -0000	1.10
@@ -1,4 +1,4 @@
-/* 
+/*
  * URL Helper
  * by Bertrand Baudet <bertrand_baudet at yahoo.com>
  * (C) 2001, MPlayer team.
@@ -134,3 +134,63 @@
 	if(url->password) free(url->password);
 	free(url);
 }
+
+
+/* Replace escape sequences in an URL (or a part of an URL) */
+/* works like strcpy(), but without return argument */
+/* unescape_url_string comes from ASFRecorder */
+void
+url_unescape_string(char *outbuf, char *inbuf)
+{
+	unsigned char c;
+	do {
+		c = *inbuf++;
+		if (c == '%') {
+			unsigned char c1 = *inbuf++;
+			unsigned char c2 = *inbuf++;
+			if (	((c1>='0' && c1<='9') || (c1>='A' && c1<='F')) &&
+				((c2>='0' && c2<='9') || (c2>='A' && c2<='F')) ) {
+				if (c1>='0' && c1<='9') c1-='0';
+				else c1-='A';
+				if (c2>='0' && c2<='9') c2-='0';
+				else c2-='A';
+				c = (c1<<4) + c2;
+			}
+		}
+		*outbuf++ = c;
+	} while (c != '\0');
+}
+
+/* Replace specific characters in the URL string by an escape sequence */
+/* works like strcpy(), but without return argument */
+/* escape_url_string comes from ASFRecorder */
+void
+url_escape_string(char *outbuf, char *inbuf) {
+	unsigned char c;
+	do {
+		c = *inbuf++;
+		if(	(c >= 'A' && c <= 'Z') ||
+			(c >= 'a' && c <= 'z') ||
+			(c >= '0' && c <= '9') ||
+			(c >= 0x7f) ||						/* fareast languages(Chinese, Korean, Japanese) */
+			c=='-' || c=='_' || c=='.' || c=='!' || c=='~' ||	/* mark characters */
+			c=='*' || c=='\'' || c=='(' || c==')' || c=='%' || 	/* do not touch escape character */
+			c==';' || c=='/' || c=='?' || c==':' || c=='@' || 	/* reserved characters */
+			c=='&' || c=='=' || c=='+' || c=='$' || c==',' || 	/* see RFC 2396 */
+			c=='\0' ) {
+			*outbuf++ = c;
+		} else {
+			/* all others will be escaped */
+			unsigned char c1 = ((c & 0xf0) >> 4);
+			unsigned char c2 = (c & 0x0f);
+			if (c1 < 10) c1+='0';
+			else c1+='A';
+			if (c2 < 10) c2+='0';
+			else c2+='A';
+			*outbuf++ = '%';
+			*outbuf++ = c1;
+			*outbuf++ = c2;
+		}
+	} while (c != '\0');
+}
+

Index: url.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/url.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- url.h	20 Nov 2001 22:15:32 -0000	1.4
+++ url.h	14 Dec 2001 23:48:47 -0000	1.5
@@ -21,4 +21,7 @@
 URL_t* url_copy(URL_t* url);
 void   url_free(URL_t* url);
 
+void url_unescape_string(char *outbuf, char *inbuf);
+void url_escape_string(char *outbuf, char *inbuf);
+
 #endif




More information about the MPlayer-cvslog mailing list