ProtocolSignature structure
Contains information about the first few bytes of a protocol send by a clientSyntax
typedef struct ProtocolSignature{
int len;
char buf[len];
} ProtocolSignature;
Members
len The length, in bytes, of the buffer pointed to by the buf member.
buf A buffer with the length of member len with the first few bytes of a protocol send by a client.
Example
This is an example of how to make a list of ProtocolSignature structures based on the HTTP protocol that supports the commands GET, POST and HEAD.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "tvsserver_base.h"
#include "tvs_redefine_api_names.h"
#define AMMOUNT_OF_SUPPPORTED_COMMANDS 3
char* supportedCommands[AMMOUNT_OF_SUPPPORTED_COMMANDS] = {"GET", "POST", "HEAD"};
int main() {
createProtocolSignatureFromArray(supportedCommands, AMMOUNT_OF_SUPPPORTED_COMMANDS);
}
char* createProtocolSignatureFromArray(char* p_array[], int ammountItems) {
int bufSize, i, tmpLen;
char* tmpBuf, *retBuf;
//Calculate the size of every integer that will contain the size of the command (that last one is zero)
bufSize = (ammountItems + 1) * sizeof(int);
//Calculate the size of the buf members for the ProtocolSignature structure
for(i=0; i<ammountItems; i++) {
bufSize += strlen(p_array[i]);
}
//Allocate size for the ProtocolSignature structure
retBuf = (char*) malloc(bufSize);
tmpBuf = retBuf;
//Copy every item with there size to the array
for(i=0; i<ammountItems; i++) {
tmpLen = strlen(p_array[i]);
*(int*)tmpBuf = tmpLen;
tmpBuf += sizeof(int);
strcpy(tmpBuf, p_array[i]);
tmpBuf += tmpLen;
}
*(int*)tmpBuf = 0;
return retBuf;
}
Requirements
Minimum supported API | 1.00
|
Header | tvsserver_base.h
|