headerparser.cpp

来自「KphoneSI (kpsi) is a SIP (Session Initia」· C++ 代码 · 共 82 行

CPP
82
字号
#include <sys/stat.h>#include <fcntl.h>#include <unistd.h>#include <ctype.h>#include <stdio.h>#include "headerparser.h"HeaderParser::HeaderParser( void ){}HeaderParser::~HeaderParser( void ){}bool HeaderParser::parse( const QString &buf, size_t bufEnd, int *headerend, int *bodystart, int *bodylength ){	size_t pos   = 0;	size_t start = 0;	size_t len   = 0;	// Get field name	while( pos < bufEnd ) {		if ( buf[ pos ] == ':' ) {			break;		}		pos++;	}	len = pos;	// Remove any white space at end of field-name	while( len > 0 ) {		if( !isspace( buf[ len - 1 ] ) ) break;		len--;	}	*headerend = len;	if( pos < bufEnd && buf[ pos ] == ':') {		pos++;	}	// Skip spaces and tabs (but not newline!)	while( pos < bufEnd ) {		if( buf[ pos ] != ' ' && buf[ pos ] != '\t' ) break;		pos++;	}	start = pos;	len = 0;	// Get field body	while( pos < bufEnd ) {		if( buf[ pos ] == '\n' ) {			// Are we at the end of the string?			if( pos == bufEnd - 1 ) {				pos++;				break;			}			// Is this really the end of the field body, and not just			// the end of a wrapped line?			else if( buf[ pos + 1 ] != ' ' && buf[ pos + 1 ] != '\t' ) {				pos++;				break;			}		}		pos++;	}	// Remove white space at end of field-body	while( pos > start ) {		if( !isspace( buf[ pos - 1 ] ) ) break;			pos--;	}	len = pos - start;	*bodystart = start;	*bodylength = len;	return true;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?