int putProcess(const ExHttp * pHttp, int rType) { static const char * c100 = "HTTP/1.1 100 Continue\n\n" ; size_t size ; int code ; const char * csize = get_head_info( pHttp, "Content-Length" ) ; size = csize==NULL ? 0 : atoi( csize ) ; char buf[size] ; char *pBuf = buf ; int ret = 0 ; ex_sock_nwrite( pHttp->sock, ( char * ) c100, strlen( c100 ) ) ; ex_sock_nread( pHttp->sock, ( char * ) &buf, sizeof (buf), size ) ; switch ( rType ) { case 0: /* static file */ case 1: /* dyanamic page: '.cgi' extension */ code = 200 ; writeFileStream( pHttp->url, ( char * ) &buf, size ) ; break ; case 404: code = 201 ; writeFileStream( pHttp->url, ( char * ) &buf, size ) ; break ; default: break ; } pBuf += codeSet( pBuf, code ) ; pBuf += sprintf( pBuf, "Connection: close\n" ) ; ret = sendHead( pHttp, buf, pBuf-buf ) ; return -1 ; }
int ex_error_reply(const ExHttp *pHttp, int stscode) { char buf[128] ; char *pBuf = buf ; pBuf += codeSet( pBuf, stscode ) ; return sendHead( pHttp, buf, pBuf-buf ) ; }
/* * use hashmap to set Http Header key-value */ int ex_send(ExHttp *pHttp, const ex_hashmap *pHeader, const char *type, const void *data){ char hBuf[BUFSIZ]; char *pBuf = nBuf; int ret; pBuf += codeSet(pBuf, 200); }
int ex_send_msg(ExHttp *pHttp, const char *type, const char *buf, size_t len) { char hBuf[BUFSIZ] ; char *pBuf = hBuf ; int ret ; pBuf += codeSet( pBuf, 200 ) ; pBuf += typeSet( pBuf, type ) ; pBuf += lengthSet( pBuf, len ) ; do { if ( (ret = sendHead( pHttp, hBuf, pBuf-hBuf ))<0 ) break ; if ( (ret = ex_sock_nwrite( pHttp->sock, ( char * ) buf, len ))<0 ) break ; } while ( 0 ) ; return ret ; }
int ex_send_file(ExHttp *pHttp, const char *filePath) { char buf[BUFSIZ] ; char *pBuf = buf ; int ret = 0 ; pBuf += codeSet( pBuf, 200 ) ; pHttp->url = ( char * ) filePath ; stat( filePath, &pHttp->st ) ; pBuf += fileSet( pBuf, pHttp ) ; do { if ( (ret = sendHead( pHttp, buf, pBuf-buf ))<0 ) break ; if ( (ret = sendFileStream( pHttp, filePath ))<0 ) break ; } while ( 0 ) ; return ret ; }
int deleteProcess(const ExHttp * pHttp, int rType) { char buf[BUFSIZ] ; char *pBuf = buf ; int code ; switch ( rType ) { case 0: /* static file */ case 1: /* dyanamic page: '.cgi' extension */ if ( remove( pHttp->url )==0 ) code = 200 ; break ; } pBuf += codeSet( pBuf, code ) ; strcat( pBuf, "\n\n" ) ; sendHead( pHttp, buf, pBuf-buf ) ; return -1 ; }
static int staticProcess(const ExHttp *pHttp) { char buf[BUFSIZ]; char *pBuf = buf; int ret = 0; int code = cacheCheck(pHttp); pBuf += codeSet(pBuf , code); if (code == 200) { pBuf += fileSet(pBuf , pHttp); pBuf += connectionSet(pBuf); } do { if ((ret = sendHead(pHttp, buf , pBuf - buf)) < 0) break; if (code == 304 || 'H' == *(pHttp->method)) break; ret = sendFileStream(pHttp, pHttp->url); } while (0); return ret; }
static int staticProcess(const ExHttp *pHttp) { char buf[BUFSIZ] ; char *pBuf = buf ; int ret = 0 ; int code = cacheCheck( pHttp ) ; pBuf += codeSet( pBuf, code ) ; if ( code==200 ) { pBuf += fileSet( pBuf, pHttp ) ; } if ( strcmp( get_mime_type( pHttp->url ), "image/png" )!=0 ) pBuf += setCookie( pBuf, pHttp ) ; do { if ( code==206 ) { char rangeTemp[128] ; char * range = ( char * ) get_head_info( pHttp, "Range" ) ; strncpy( ( char * ) &rangeTemp, range, 128 ) ; range = ( char * ) &rangeTemp ; SKIP( &range, '=' ) ; char * sRange = range ; SKIP( &range, '-' ) ; char date[35] ; strftime( date, 35, "%a, %d %b %Y %X GMT", localtime( &(pHttp->st.st_ctime) ) ) ; int startRange = (*sRange=='\0') ? -1 : atoi( sRange ) ; int endRange = (*range=='\0') ? -1 : atoi( range ) ; // printf("start :%d end :%d\n",startRange,endRange ) ; if ( startRange<0 ) { startRange = pHttp->st.st_size-endRange ; endRange = pHttp->st.st_size ; } else if ( endRange<0 ) { endRange = pHttp->st.st_size ; } pBuf += sprintf( pBuf, "connection: close\n" "Last-Modified: %s\n" "Accept-Ranges: bytes\n" "Content-Length: %d\n" "Content-Range: bytes %d-%d/%d\n", date, endRange-startRange, startRange, endRange, pHttp->st.st_size ) ; if ( (ret = sendHead( pHttp, buf, pBuf-buf ))<0 ) break ; ret = sendFileRangeStream( pHttp, pHttp->url, startRange, endRange + 1 ) ; break ; } if ( (ret = sendHead( pHttp, buf, pBuf-buf ))<0 ) break ; if ( code==304|| code == 412 || 'H'== *(pHttp->method) ) break ; ret = sendFileStream( pHttp, pHttp->url ) ; } while ( 0 ) ; return ret ; }