char * strremove_wrapper(char *hay, char *needle) { strremove(hay, needle); return hay; }
void print_to_file(FILE* file, char* card, const int i, const int max_card){ //sledim 4tobi v faile ne bilo pystih strok. //pri zapisi poslednego elementa ne perehodim na novyiy stroky if(i < max_card - 1) fprintf(file, "%s", card); else { strremove(card, "\n"); fprintf(file, "%s", card); strcat(card, "\n"); } }
/** * 调用时已经确保pblk中包含请求行,可以不含有HTTP/1.1 * 0: 表示ip抽取成功 * <0: 表示抽取失败 */ int __extract_ip( buffer_t *pbuf, block_t *pblk, char *ip, size_t size, uint16_t *port ) { char *pS, *p, *tp; int n; pS = strnstr( BLOCK_SENDADDR(pblk), BLOCK_SENDATA(pblk), "GET", 3 ); if ( NULL == pS ) pS = strnstr( BLOCK_SENDADDR(pblk), BLOCK_SENDATA(pblk), "POST", 4 ); if ( NULL == pS ) return -1; p = memchr( pS, '/', BLOCK_SENDATA(pblk)-(int)(pS-BLOCK_SENDADDR(pblk)) ); if ( NULL == p ) return -2; tp = memchr( p, ':', BLOCK_SENDATA(pblk)-(int)(p-BLOCK_SENDADDR(pblk)) ); if ( NULL == tp ) return -2; memset( ip, 0, size ); strncpy( ip, p+1, (tp-p)-1 ); //判断:之前的是否是http的字段还是ip if ( NULL != strstr(ip, "HTTP") ) { //http 的字段,没有vm:port *port = 0; memset( ip, 0, sizeof(ip) ); return 1; } if ( NULL != port ) { *port = 0; for ( ++tp; *tp <= '9' && *tp >= '0'; ++ tp ) { *port = *port * 10 + ( *tp - '0' ); } } //rewrite ... if ( '/' == *tp ) ++ tp; n = tp-p-1; strremove( pblk->data, p+1-pblk->data, n, pblk->end ); //数据向前移动n位 log_message( LOG_DEBUG, "remove vm:port %d bytes", n ); pblk->end -= n; pbuf->size -=n; return 0; }