comparison stream/url.c @ 21125:4aff19cc00bb

Also support absolute url redirection, e.g. http://www.youtube.com/v/buKaqRG2SFA (video does not play anyway though).
author reimar
date Tue, 21 Nov 2006 16:26:38 +0000
parents 720206eef78b
children 83dc11e40f28
comparison
equal deleted inserted replaced
21124:2e0938ba9756 21125:4aff19cc00bb
20 #endif 20 #endif
21 21
22 URL_t *url_redirect(URL_t **url, const char *redir) { 22 URL_t *url_redirect(URL_t **url, const char *redir) {
23 URL_t *u = *url; 23 URL_t *u = *url;
24 URL_t *res; 24 URL_t *res;
25 if (!strchr(redir, '/')) { 25 if (!strchr(redir, '/') || *redir == '/') {
26 char *tmp; 26 char *tmp;
27 char *newurl = malloc(strlen(u->url) + strlen(redir) + 1); 27 char *newurl = malloc(strlen(u->url) + strlen(redir) + 1);
28 strcpy(newurl, u->url); 28 strcpy(newurl, u->url);
29 if (*redir == '/') {
30 redir++;
31 tmp = strstr(newurl, "://");
32 if (tmp) tmp = strchr(tmp + 3, '/');
33 } else
29 tmp = strrchr(newurl, '/'); 34 tmp = strrchr(newurl, '/');
30 if (tmp) tmp[1] = 0; 35 if (tmp) tmp[1] = 0;
31 strcat(newurl, redir); 36 strcat(newurl, redir);
32 res = url_new(newurl); 37 res = url_new(newurl);
33 free(newurl); 38 free(newurl);