Mercurial > mplayer.hg
annotate url.c @ 947:76fd9463b9d3
FAST_OSD option to disable font outline antialiasing
author | arpi_esp |
---|---|
date | Sat, 02 Jun 2001 16:02:38 +0000 |
parents | ede5785faa53 |
children | 647f5781d490 |
rev | line source |
---|---|
902 | 1 /* |
2 * URL Helper | |
3 * by Bertrand Baudet <bertrand_baudet@yahoo.com> | |
4 * (C) 2001, MPlayer team. | |
5 * | |
6 * TODO: | |
7 * Extract the username/password if present | |
8 */ | |
9 | |
833 | 10 #include <string.h> |
11 #include <stdlib.h> | |
12 #include <stdio.h> | |
13 | |
14 #include "url.h" | |
15 | |
16 URL_t* | |
902 | 17 url_new(char* url) { |
833 | 18 int pos1, pos2; |
19 URL_t* Curl; | |
20 char *ptr1, *ptr2; | |
21 | |
22 // Create the URL container | |
23 Curl = (URL_t*)malloc(sizeof(URL_t)); | |
24 if( Curl==NULL ) { | |
25 printf("Memory allocation failed!\n"); | |
26 exit(1); | |
27 } | |
840 | 28 // Initialisation of the URL container members |
902 | 29 memset( Curl, 0, sizeof(URL_t) ); |
840 | 30 |
833 | 31 // Copy the url in the URL container |
32 Curl->url = (char*)malloc(strlen(url)+1); | |
33 if( Curl->url==NULL ) { | |
34 printf("Memory allocation failed!\n"); | |
35 exit(1); | |
36 } | |
37 strcpy(Curl->url, url); | |
38 | |
39 // extract the protocol | |
40 ptr1 = strstr(url, "://"); | |
41 if( ptr1==NULL ) { | |
840 | 42 printf("Malformed URL or not an URL!\n"); |
833 | 43 return NULL; |
44 } | |
45 pos1 = ptr1-url; | |
46 Curl->protocol = (char*)malloc(pos1+1); | |
47 strncpy(Curl->protocol, url, pos1); | |
48 Curl->protocol[pos1] = '\0'; | |
49 | |
50 // look if the port is given | |
51 ptr2 = strstr(ptr1+3, ":"); | |
52 if( ptr2==NULL ) { | |
53 // No port is given | |
54 // Look if a path is given | |
55 ptr2 = strstr(ptr1+3, "/"); | |
56 if( ptr2==NULL ) { | |
57 // No path/filename | |
58 // So we have an URL like http://www.hostname.com | |
59 pos2 = strlen(url); | |
60 } else { | |
61 // We have an URL like http://www.hostname.com/file.txt | |
62 pos2 = ptr2-url; | |
63 } | |
64 } else { | |
65 // We have an URL beginning like http://www.hostname.com:1212 | |
66 // Get the port number | |
67 Curl->port = atoi(ptr2+1); | |
68 pos2 = ptr2-url; | |
69 } | |
70 // copy the hostname in the URL container | |
71 Curl->hostname = (char*)malloc(strlen(url)+1); | |
72 if( Curl->hostname==NULL ) { | |
73 printf("Memory allocation failed!\n"); | |
74 exit(1); | |
75 } | |
76 strncpy(Curl->hostname, ptr1+3, pos2-pos1-3); | |
840 | 77 Curl->hostname[pos2-pos1-3] = '\0'; |
833 | 78 |
79 // Look if a path is given | |
80 ptr2 = strstr(ptr1+3, "/"); | |
81 if( ptr2!=NULL ) { | |
82 // A path/filename is given | |
83 // check if it's not a trailing '/' | |
84 if( strlen(ptr2)>1 ) { | |
85 // copy the path/filename in the URL container | |
869
e350849ff400
Url given without a filename/path get the filename/path '/'
bertrand
parents:
840
diff
changeset
|
86 Curl->file = (char*)malloc(strlen(ptr2)+1); |
840 | 87 if( Curl->file==NULL ) { |
833 | 88 printf("Memory allocation failed!\n"); |
89 exit(1); | |
90 } | |
869
e350849ff400
Url given without a filename/path get the filename/path '/'
bertrand
parents:
840
diff
changeset
|
91 Curl->file[0]='/'; |
e350849ff400
Url given without a filename/path get the filename/path '/'
bertrand
parents:
840
diff
changeset
|
92 strcpy(Curl->file+1, ptr2+1); |
833 | 93 } |
869
e350849ff400
Url given without a filename/path get the filename/path '/'
bertrand
parents:
840
diff
changeset
|
94 } |
e350849ff400
Url given without a filename/path get the filename/path '/'
bertrand
parents:
840
diff
changeset
|
95 // Check if a filenme was given or set else set it with '/' |
e350849ff400
Url given without a filename/path get the filename/path '/'
bertrand
parents:
840
diff
changeset
|
96 if( Curl->file==NULL ) { |
e350849ff400
Url given without a filename/path get the filename/path '/'
bertrand
parents:
840
diff
changeset
|
97 Curl->file = (char*)malloc(2); |
e350849ff400
Url given without a filename/path get the filename/path '/'
bertrand
parents:
840
diff
changeset
|
98 if( Curl->file==NULL ) { |
e350849ff400
Url given without a filename/path get the filename/path '/'
bertrand
parents:
840
diff
changeset
|
99 printf("Memory allocation failed!\n"); |
e350849ff400
Url given without a filename/path get the filename/path '/'
bertrand
parents:
840
diff
changeset
|
100 exit(1); |
e350849ff400
Url given without a filename/path get the filename/path '/'
bertrand
parents:
840
diff
changeset
|
101 } |
e350849ff400
Url given without a filename/path get the filename/path '/'
bertrand
parents:
840
diff
changeset
|
102 strcpy(Curl->file, "/"); |
833 | 103 } |
104 | |
105 return Curl; | |
106 } | |
107 | |
108 void | |
902 | 109 url_free(URL_t* url) { |
833 | 110 if(url) return; |
111 if(url->url) free(url->url); | |
112 if(url->protocol) free(url->protocol); | |
113 if(url->hostname) free(url->hostname); | |
840 | 114 if(url->file) free(url->file); |
902 | 115 if(url->username) free(url->username); |
116 if(url->password) free(url->password); | |
833 | 117 free(url); |
118 } |