void __w3curlparse(const char *szurl, char *szprotocol, char *szuser, char *szpassword, char *szaddress, unsigned long &nport, char *szuri){ char szport[1024]="\0"; unsigned long npos=0; bool bflag=false; while(strlen(szurl)>0 && npos<strlen(szurl) && strncmp((szurl+npos), ":", 1)) ++npos; if(!strncmp((szurl+npos+1), "/", 1)){ // is protocol if(szprotocol){ strncpy(szprotocol, szurl, npos); szprotocol[npos]=0; } bflag=true; }else{ // is host if(szprotocol){ strncpy(szprotocol, "http", 4); szprotocol[5]='\0'; } } unsigned long nsp=0, usp=0; if(bflag){ usp=nsp=npos+=3; }else{ usp=nsp=npos=0; } while(strlen(szurl)>0 && usp<strlen(szurl) && strncmp((szurl+usp), "@", 1)) ++usp; if(usp<strlen(szurl)){ // find username and find password unsigned long ssp=nsp; while(strlen(szurl)>0 && npos<strlen(szurl) && strncmp((szurl+ssp), ":", 1)) ++ssp; if(ssp<usp){// find strncpy(szuser, szurl+nsp, ssp-nsp); szuser[ssp-nsp+1]='\0'; strncpy(szpassword, szurl+ssp+1, usp-ssp-1); szpassword[usp-ssp]='\0'; } nsp=npos=usp+1; } bflag=false; while(strlen(szurl)>0 && npos<strlen(szurl) && strncmp((szurl+npos), "/", 1)) ++npos; unsigned long nf=nsp; for(;nf<=npos;nf++){ if(!strncmp((szurl+nf), ":", 1)){ // find PORT bflag=true; break; } } if(bflag){ char sztmp[1024]="\0"; strncpy(sztmp, (szurl+nf+1), npos-nf); nport=atol(sztmp); strncpy(szaddress, (szurl+nsp), nf-nsp); }else if(!strcmp(szprotocol,"https")){ nport=INTERNET_DEFAULT_HTTPS_PORT; strncpy(szaddress, (szurl+nsp), npos-nsp); }else if(!strcmp(szprotocol, "ftp")){ nport=INTERNET_DEFAULT_FTP_PORT; strncpy(szaddress, (szurl+nsp), npos-nsp); }else { nport=INTERNET_DEFAULT_HTTP_PORT; strncpy(szaddress, (szurl+nsp), npos-nsp); } if(npos<strlen(szurl)){ // find URI strncpy(szuri, (szurl+npos), strlen(szurl)-npos); }else{ szuri[0]='/'; szuri[1]='\0'; } return; }
Copyrights © - Joinc, All Rights Reserved. Inherited From - Yundream Rebranded By - Joonphil
설명
코드
변경사항
2004/01/08
Recent Posts
Archive Posts
Tags