diff --git a/http.c b/http.c index 4be45d4..caacfbe 100644 --- a/http.c +++ b/http.c @@ -220,23 +220,13 @@ error_t fill_dirnode (struct netnode *dir) * www.gnu.org/gpl.html will be changed to * www.gnu.org.gpl.html */ conn_req=(char *)malloc((strlen(go->f_name)+8)*sizeof(char)); - url = strdup(go->f_name); - strcpy(url,strtok(url,"/")); - temp = strdup(go->f_name); - f_name = (char *) malloc(strlen(go->f_name)*sizeof(char)); - bzero(f_name,sizeof(f_name)); - while ( temp!=NULL && strchr(temp,'/') != NULL ) - { - /* find / replace it with . */ - temp1 = strdup(temp); - strcat(f_name,strtok(temp1,"/")); - strcpy(temp,strchr(temp,'/')); - temp++; - if ( strchr(temp,'/') != NULL ) - strcat(f_name,"."); - } - if ( strlen(temp) > 0 ) - strcat(f_name,temp); + url = strndup(go->f_name, strchr(go->f_name, '/') - go->f_name); + f_name = strdup(go->f_name); + int i; + for (i = 0; f_name[i] != '\0'; i++) + if (f_name[i] == '/') + f_name[i] = '.'; + sprintf(conn_req,"%s%s","http://",go->f_name); } else @@ -246,7 +236,10 @@ error_t fill_dirnode (struct netnode *dir) url=strdup(dir->url); if ( go != list_of_entries ) { - conn_req=(char *)malloc((strlen(dir->conn_req)+strlen(go->f_name)+1)*sizeof(char)); + size_t conn_req_size = strlen(dir->conn_req) + strlen(go->f_name) + 1; + if( go->f_type==HTTP_DIR || go->f_type==HTTP_DIR_NOT_FILLED ) + conn_req_size++; /* We'll need to add a trailing slash later. */ + conn_req=(char *)malloc(conn_req_size*sizeof(char)); sprintf(conn_req,"%s%s",dir->conn_req,go->f_name); } else @@ -256,7 +249,10 @@ error_t fill_dirnode (struct netnode *dir) /* the file corresponding to base url * user has given a file explicitly in * the url */ - conn_req=(char *)malloc((strlen(dir->conn_req)+strlen(go->f_name)+1)*sizeof(char)); + size_t conn_req_size = strlen(dir->conn_req) + strlen(go->f_name) + 1; + if( go->f_type==HTTP_DIR || go->f_type==HTTP_DIR_NOT_FILLED ) + conn_req_size++; /* We'll need to add a trailing slash later. */ + conn_req=(char *)malloc(conn_req_size*sizeof(char)); sprintf(conn_req,"%s%s",dir->conn_req,go->f_name); } else @@ -264,8 +260,10 @@ error_t fill_dirnode (struct netnode *dir) /* the file corresponding to base url * user has not given a file explicitly * the url so its the index.html */ - - conn_req=(char *)malloc((strlen(dir->conn_req)+1)*sizeof(char)); + size_t conn_req_size = strlen(dir->conn_req) + 1; + if( go->f_type==HTTP_DIR || go->f_type==HTTP_DIR_NOT_FILLED ) + conn_req_size++; /* We'll need to add a trailing slash later. */ + conn_req=(char *)malloc(conn_req_size*sizeof(char)); sprintf(conn_req,"%s",dir->conn_req); } }