--- libaitwww/src/url.c 2012/03/10 15:00:45 1.1.2.1 +++ libaitwww/src/url.c 2012/03/10 15:38:45 1.1.2.2 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: url.c,v 1.1.2.1 2012/03/10 15:00:45 misho Exp $ +* $Id: url.c,v 1.1.2.2 2012/03/10 15:38:45 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -154,28 +154,22 @@ www_URLGet(const char *csURL, struct tagIOURL *url) } /* - * www_Path2File() - Parse and make path/filename pair + * www_URLGetFile() - Get file from parsed URL * - * @csArgs = Input argument line - * @psPath = Output Path, if ==NULL path not returned - * @pathLen = Size of path array - * @psFile = Output File - * @fileLen = Size of file array - * return: 0 error format; -1 error:: can`t read; >0 ok, number of readed items + * @url = Input parsed URL + * @psValue = Return filename, if not specified file in url path, replace with / + * @valLen = Size of psValue array + * return: -1 error:: can`t read; 0 ok */ -inline int -www_Path2File(const char * __restrict csArgs, char * __restrict psPath, - int pathLen, char * __restrict psFile, int fileLen) +int +www_URLGetFile(struct tagIOURL *url, char * __restrict psValue, int valLen) { char *pos, *psBuf; - if (!csArgs || !psFile || !fileLen) + if (!url || !psValue || !valLen) return -1; - if (psPath && !pathLen) - return -1; - else - memset(psPath, 0, pathLen); - psBuf = strdup(csArgs); + + psBuf = strdup(url->url_path.value); if (!psBuf) { LOGERR; return -1; @@ -183,37 +177,17 @@ www_Path2File(const char * __restrict csArgs, char * _ pos = strrchr(psBuf, '/'); if (!pos) { - strlcpy(psFile, psBuf, fileLen); + /* whole string is filename */ + strlcpy(psValue, psBuf, valLen); free(psBuf); return 1; - } else + } else { *pos++ = 0; - strlcpy(psFile, pos, fileLen); - if (psPath) - strlcpy(psPath, psBuf, pathLen); - - free(psBuf); - return 2; -} - -/* - * www_URLGetFile() - Get file from parsed URL - * - * @url = Input parsed URL - * @psValue = Return filename, if not specified file in url path, replace with / - * @valLen = Size of psValue array - * return: -1 error:: can`t read; 0 ok - */ -int -www_URLGetFile(struct tagIOURL *url, char * __restrict psValue, int valLen) -{ - if (!url || !psValue || !valLen) - return -1; - - if (www_Path2File(url->url_path.value, NULL, 0, psValue, valLen) < 1) - return -1; + strlcpy(psValue, pos, valLen); + free(psBuf); + } /* If not specified file in path, default replace to / */ if (!*psValue)