comparison libmpdemux/url.c @ 5933:14b46420840b

printf to mp_msg
author albeu
date Thu, 02 May 2002 10:40:35 +0000
parents d2a7fcfeec6f
children 6e9d7a6b1806
comparison
equal deleted inserted replaced
5932:1ebeebca86f3 5933:14b46420840b
10 #include <string.h> 10 #include <string.h>
11 #include <stdlib.h> 11 #include <stdlib.h>
12 #include <stdio.h> 12 #include <stdio.h>
13 13
14 #include "url.h" 14 #include "url.h"
15 #include "mp_msg.h"
15 16
16 URL_t* 17 URL_t*
17 url_new(char* url) { 18 url_new(char* url) {
18 int pos1, pos2; 19 int pos1, pos2;
19 URL_t* Curl; 20 URL_t* Curl;
22 if( url==NULL ) return NULL; 23 if( url==NULL ) return NULL;
23 24
24 // Create the URL container 25 // Create the URL container
25 Curl = (URL_t*)malloc(sizeof(URL_t)); 26 Curl = (URL_t*)malloc(sizeof(URL_t));
26 if( Curl==NULL ) { 27 if( Curl==NULL ) {
27 printf("Memory allocation failed!\n"); 28 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed!\n");
28 return NULL; 29 return NULL;
29 } 30 }
30 // Initialisation of the URL container members 31 // Initialisation of the URL container members
31 memset( Curl, 0, sizeof(URL_t) ); 32 memset( Curl, 0, sizeof(URL_t) );
32 33
33 // Copy the url in the URL container 34 // Copy the url in the URL container
34 Curl->url = strdup(url); 35 Curl->url = strdup(url);
35 if( Curl->url==NULL ) { 36 if( Curl->url==NULL ) {
36 printf("Memory allocation failed!\n"); 37 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed!\n");
37 return NULL; 38 return NULL;
38 } 39 }
39 40
40 // extract the protocol 41 // extract the protocol
41 ptr1 = strstr(url, "://"); 42 ptr1 = strstr(url, "://");
42 if( ptr1==NULL ) { 43 if( ptr1==NULL ) {
43 printf("Not an URL!\n"); 44 mp_msg(MSGT_NETWORK,MSGL_V,"Not an URL!\n");
44 return NULL; 45 return NULL;
45 } 46 }
46 pos1 = ptr1-url; 47 pos1 = ptr1-url;
47 Curl->protocol = (char*)malloc(pos1+1); 48 Curl->protocol = (char*)malloc(pos1+1);
48 strncpy(Curl->protocol, url, pos1); 49 strncpy(Curl->protocol, url, pos1);
72 pos2 = ptr2-url; 73 pos2 = ptr2-url;
73 } 74 }
74 // copy the hostname in the URL container 75 // copy the hostname in the URL container
75 Curl->hostname = (char*)malloc(pos2-pos1-3+1); 76 Curl->hostname = (char*)malloc(pos2-pos1-3+1);
76 if( Curl->hostname==NULL ) { 77 if( Curl->hostname==NULL ) {
77 printf("Memory allocation failed!\n"); 78 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed!\n");
78 return NULL; 79 return NULL;
79 } 80 }
80 strncpy(Curl->hostname, ptr1+3, pos2-pos1-3); 81 strncpy(Curl->hostname, ptr1+3, pos2-pos1-3);
81 Curl->hostname[pos2-pos1-3] = '\0'; 82 Curl->hostname[pos2-pos1-3] = '\0';
82 83
87 // check if it's not a trailing '/' 88 // check if it's not a trailing '/'
88 if( strlen(ptr2)>1 ) { 89 if( strlen(ptr2)>1 ) {
89 // copy the path/filename in the URL container 90 // copy the path/filename in the URL container
90 Curl->file = strdup(ptr2); 91 Curl->file = strdup(ptr2);
91 if( Curl->file==NULL ) { 92 if( Curl->file==NULL ) {
92 printf("Memory allocation failed!\n"); 93 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed!\n");
93 return NULL; 94 return NULL;
94 } 95 }
95 } 96 }
96 } 97 }
97 // Check if a filenme was given or set, else set it with '/' 98 // Check if a filenme was given or set, else set it with '/'
98 if( Curl->file==NULL ) { 99 if( Curl->file==NULL ) {
99 Curl->file = (char*)malloc(2); 100 Curl->file = (char*)malloc(2);
100 if( Curl->file==NULL ) { 101 if( Curl->file==NULL ) {
101 printf("Memory allocation failed!\n"); 102 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed!\n");
102 return NULL; 103 return NULL;
103 } 104 }
104 strcpy(Curl->file, "/"); 105 strcpy(Curl->file, "/");
105 } 106 }
106 107