本文整理汇总了C++中SetStrLen函数的典型用法代码示例。如果您正苦于以下问题:C++ SetStrLen函数的具体用法?C++ SetStrLen怎么用?C++ SetStrLen使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SetStrLen函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HashFinish
int HashFinish(HASH *Hash, int Encoding, char **Return)
{
char *Token=NULL, *Bytes=NULL, *Hashed=NULL, *ptr;
int len;
ptr=GetToken(Hash->Type, "\\S", &Token, 0);
len=Hash->Finish(Hash, &Bytes);
while (StrValid(ptr))
{
ptr=GetToken(ptr, "\\S", &Token, 0);
len=HashBytes(&Hashed, Token, Bytes, len, 0);
Bytes=SetStrLen(Bytes, len);
memcpy(Bytes,Hashed,len);
}
if (Encoding > 0)
{
*Return=EncodeBytes(*Return, Bytes, len, Encoding);
len=StrLen(*Return);
}
else
{
*Return=SetStrLen(*Return, len);
memcpy(*Return, Bytes, len);
}
DestroyString(Hashed);
DestroyString(Token);
DestroyString(Bytes);
return(len);
}
示例2: PBK2DF2
int PBK2DF2(char **Return, char *Type, char *Bytes, int Len, char *Salt, int SaltLen, uint32_t Rounds, int Encoding)
{
char *Tempstr=NULL, *Hash=NULL;
uint32_t RoundsBE;
int i, len, hlen;
//Network byte order is big endian
RoundsBE=htonl(Rounds);
Tempstr=SetStrLen(Tempstr, Len + SaltLen + 20);
memcpy(Tempstr, Bytes, Len);
memcpy(Tempstr+Len, Salt, SaltLen);
memcpy(Tempstr+Len+SaltLen, &RoundsBE, sizeof(uint32_t));
len=Len+SaltLen+sizeof(uint32_t);
for (i=0; i <Rounds; i++)
{
hlen=HashBytes(&Hash, Type, Tempstr, len, 0);
Tempstr=SetStrLen(Tempstr, Len + hlen + 20);
memcpy(Tempstr, Bytes, Len);
memcpy(Tempstr+Len, Hash, hlen);
len=Len + hlen;
}
*Return=EncodeBytes(*Return, Hash, hlen, Encoding);
DestroyString(Tempstr);
DestroyString(Hash);
StrLen(*Return);
}
示例3: while
char *VFormatStr(char *InBuff, const char *InputFmtStr, va_list args)
{
int inc=100, count=1, result=0, FmtLen;
char *Tempstr=NULL, *FmtStr=NULL, *ptr;
va_list argscopy;
Tempstr=InBuff;
//Take a copy of the supplied Format string and change it.
//Do not allow '%n', it's useable for exploits
FmtLen=StrLen(InputFmtStr);
FmtStr=CopyStr(FmtStr,InputFmtStr);
//Deny %n. Replace it with %x which prints out the value of any supplied argument
ptr=strstr(FmtStr,"%n");
while (ptr)
{
memcpy(ptr,"%x",2);
ptr++;
ptr=strstr(ptr,"%n");
}
inc=4 * FmtLen; //this should be a good average
for (count=1; count < 100; count++)
{
result=inc * count +1;
Tempstr=SetStrLen(Tempstr, result);
//the vsnprintf function DESTROYS the arg list that is passed to it.
//This is just plain WRONG, it's a long-standing bug. The solution is to
//us va_copy to make a new one every time and pass that in.
va_copy(argscopy,args);
result=vsnprintf(Tempstr,result,FmtStr,argscopy);
va_end(argscopy);
/* old style returns -1 to say couldn't fit data into buffer.. so we */
/* have to guess again */
if (result==-1) continue;
/* new style returns how long buffer should have been.. so we resize it */
if (result > (inc * count))
{
Tempstr=SetStrLen(Tempstr, result+10);
va_copy(argscopy,args);
result=vsnprintf(Tempstr,result+10,FmtStr,argscopy);
va_end(argscopy);
}
break;
}
DestroyString(FmtStr);
return(Tempstr);
}
示例4: HTTPServerRecieveURL
void HTTPServerRecieveURL(STREAM *S,HTTPSession *Heads)
{
STREAM *Doc;
struct stat FileStat;
char *Buffer=NULL, *Tempstr=NULL;
int BuffSize=4096;
Doc=STREAMOpenFile(Heads->Path, SF_CREAT | SF_TRUNC | SF_WRONLY);
if (! Doc) HTTPServerSendHTML(S, Heads, "403 Forbidden","Can't open document for write.");
else
{
fchmod(Doc->in_fd,0660);
Buffer=SetStrLen(Buffer,BuffSize);
STREAMSendFile(S,Doc,Heads->ContentSize, SENDFILE_KERNEL | SENDFILE_LOOP);
STREAMClose(Doc);
stat(Heads->Path,&FileStat);
LogToFile(Settings.LogPath,"%[email protected]%s (%s) uploaded %s (%d bytes)",Heads->UserName,Heads->ClientHost,Heads->ClientIP,Heads->Path,FileStat.st_size);
HTTPServerSendHTML(S, Heads, "201 Created","");
}
DestroyString(Tempstr);
DestroyString(Buffer);
}
示例5: HTTPServerReadBody
int HTTPServerReadBody(HTTPSession *Session, char **Data)
{
char *Tempstr=NULL;
int bytes_read=0, len;
if (Session->ContentSize > 0)
{
*Data=SetStrLen(*Data,Session->ContentSize+10);
while (bytes_read < Session->ContentSize)
{
len=STREAMReadBytes(Session->S, (*Data) + bytes_read, Session->ContentSize-bytes_read);
if (len < 1) break;
bytes_read+=len;
}
}
else
{
Tempstr=STREAMReadLine(Tempstr,Session->S);
while (Tempstr)
{
len=StrLen(Tempstr);
*Data=CatStrLen(*Data,Tempstr,len);
bytes_read+=len;
Tempstr=STREAMReadLine(Tempstr,Session->S);
}
}
DestroyString(Tempstr);
return(bytes_read);
}
示例6: HashFile
int HashFile(char **Return, const char *Type, const char *Path, int Encoding)
{
HASH *Hash;
STREAM *S;
char *Tempstr=NULL;
int result;
S=STREAMOpen(Path,"r");
if (! S) return(FALSE);
Hash=HashInit(Type);
if (! Hash)
{
STREAMClose(S);
return(FALSE);
}
Tempstr=SetStrLen(Tempstr,4096);
result=STREAMReadBytes(S,Tempstr,4096);
while (result !=EOF)
{
Hash->Update(Hash, Tempstr, result);
result=STREAMReadBytes(S,Tempstr,4096);
}
DestroyString(Tempstr);
STREAMClose(S);
result=HashFinish(Hash, Encoding, Return);
return(result);
}
示例7: SSL_CIPHER_get_name
const char *OpenSSLQueryCipher(STREAM *S)
{
void *ptr;
if (! S) return(NULL);
ptr=STREAMGetItem(S,"LIBUSEFUL-SSL-CTX");
if (! ptr) return(NULL);
#ifdef HAVE_LIBSSL
const SSL_CIPHER *Cipher;
char *Tempstr=NULL;
Cipher=SSL_get_current_cipher((const SSL *) ptr);
if (Cipher)
{
Tempstr=FormatStr(Tempstr,"%d bit %s",SSL_CIPHER_get_bits(Cipher,NULL), SSL_CIPHER_get_name(Cipher));
STREAMSetValue(S,"SSL-Cipher",Tempstr);
Tempstr=SetStrLen(Tempstr,1024);
Tempstr=SSL_CIPHER_description(Cipher, Tempstr, 1024);
STREAMSetValue(S,"SSL-Cipher-Details",Tempstr);
}
DestroyString(Tempstr);
return(STREAMGetValue(S,"SSL-Cipher"));
#else
return(NULL);
#endif
}
示例8: setenv
char *GetDateStrFromSecs(const char *DateFormat, time_t Secs, const char *TimeZone)
{
time_t val;
struct tm *TMS;
static char *Buffer=NULL;
char *Tempstr=NULL;
#define DATE_BUFF_LEN 255
val=Secs;
if (StrLen(TimeZone))
{
if (getenv("TZ")) Tempstr=CopyStr(Tempstr,getenv("TZ"));
setenv("TZ",TimeZone,TRUE);
tzset();
}
TMS=localtime(&val);
if (StrLen(TimeZone))
{
if (! Tempstr) unsetenv("TZ");
else setenv("TZ",Tempstr,TRUE);
tzset();
}
val=StrLen(DateFormat)+ DATE_BUFF_LEN;
Buffer=SetStrLen(Buffer,val);
strftime(Buffer,val,DateFormat,TMS);
DestroyString(Tempstr);
return(Buffer);
}
示例9: HTTPServerSendResponse
void HTTPServerSendResponse(STREAM *S, HTTPSession *Session, char *ResponseLine, char *ContentType, char *Body)
{
HTTPSession *Response;
char *Tempstr=NULL;
long ResponseCode=0;
LogToFile(Settings.LogPath,"RESPONSE: '%s' to %[email protected]%s for '%s %s'",ResponseLine,Session->UserName,Session->ClientIP,Session->Method,Session->Path);
ResponseCode=strtol(ResponseLine,NULL,10);
//Create 'Response' rather than using session, because things set by the client in 'Session' might
//get copied into the response and interfere with the response otherwise
Response=HTTPSessionCreate();
/*Copy Values from Session object into Response */
if (Session)
{
Response->MethodID=Session->MethodID;
Response->LastModified=Session->LastModified;
Response->Flags |= Session->Flags & (SESSION_KEEPALIVE | SESSION_AUTHENTICATED);
//Response->Flags |= SESSION_KEEPALIVE;
Response->ClientIP=CopyStr(Response->ClientIP,Session->ClientIP);
Response->Path=CopyStr(Response->Path,Session->Path);
Response->Method=CopyStr(Response->Method,Session->Method);
Response->URL=CopyStr(Response->URL,Session->URL);
Response->UserName=CopyStr(Response->UserName,Session->UserName);
}
Response->ResponseCode=CopyStr(Response->ResponseCode,ResponseLine);
if (ResponseCode==302) SetVar(Response->Headers,"Location",Body);
else Response->ContentSize=StrLen(Body);
Response->ContentType=CopyStr(Response->ContentType,ContentType);
if (HTTPServerDecideToCompress(Session,NULL))
{
Response->Flags |= SESSION_ENCODE_GZIP;
Tempstr=SetStrLen(Tempstr,Response->ContentSize *2);
Response->ContentSize=CompressBytes(&Tempstr, "gzip",Body, StrLen(Body), 5);
}
else Tempstr=CopyStr(Tempstr,Body);
if ((ResponseCode==401) || (ResponseCode==407)) HTTPServerSendHeaders(S, Response,HEADERS_AUTH);
else HTTPServerSendHeaders(S, Response, HEADERS_KEEPALIVE);
STREAMWriteBytes(S,Tempstr,Response->ContentSize);
STREAMFlush(S);
/* If HTTPServerSendHeaders set SESSION_REUSE then set that in the Session object */
//if (Response->Flags & SESSION_REUSE) Session->Flags |= SESSION_REUSE;
//else Session->Flags &= ~SESSION_REUSE;
ProcessSessionEventTriggers(Response);
HTTPSessionDestroy(Response);
DestroyString(Tempstr);
}
示例10:
char *EncodeBase64(char *Return, char *Text, int len)
{
char *RetStr;
RetStr=SetStrLen(Return,len *2);
to64frombits(RetStr,Text,len);
return(RetStr);
}
示例11: HMACPrepare
void HMACPrepare(HASH *HMAC, const char *Data, int Len)
{
int i;
char *Key=NULL, *Tempstr=NULL;
//Whatever we've been given as a key, we have to turn it into a
//key of 'HMAC_BLOCKSIZE', either by hashing it to make it shorter
//or by padding with NULLS
Key=SetStrLen(Key,HMAC_BLOCKSIZE);
memset(Key,0,HMAC_BLOCKSIZE);
if (Len > HMAC_BLOCKSIZE)
{
HMAC->Key1Len=HashBytes(&Tempstr,HMAC->Type,HMAC->Key1,HMAC->Key1Len,0);
memcpy(Key,Tempstr,HMAC->Key1Len);
}
else
{
memcpy(Key,HMAC->Key1,HMAC->Key1Len);
}
HMAC->Key1=SetStrLen(HMAC->Key1,HMAC_BLOCKSIZE);
HMAC->Key2=SetStrLen(HMAC->Key2,HMAC_BLOCKSIZE);
HMAC->Key1Len=HMAC_BLOCKSIZE;
HMAC->Key2Len=HMAC_BLOCKSIZE;
for (i=0; i < HMAC_BLOCKSIZE; i++)
{
//inner key
HMAC->Key1[i]=Key[i] ^ 0x36;
//outer key
HMAC->Key2[i]=Key[i] ^ 0x5c;
}
//first thing to be hashed is the inner key, then data is 'concatted' onto it
HMACUpdate(HMAC, HMAC->Key1, HMAC->Key1Len);
HMACUpdate(HMAC, Data, Len);
HMAC->Update=HMACUpdate;
DestroyString(Tempstr);
DestroyString(Key);
}
示例12: HTTPChunkedRead
int HTTPChunkedRead(TProcessingModule *Mod, const char *InBuff, int InLen, char **OutBuff, int *OutLen)
{
int len=0, val=0;
THTTPChunk *Chunk;
char *ptr, *vptr;
Chunk=(THTTPChunk *) Mod->Data;
len=Chunk->BuffLen+InLen;
Chunk->Buffer=SetStrLen(Chunk->Buffer,len);
memcpy(Chunk->Buffer+Chunk->BuffLen,InBuff,InLen);
Chunk->BuffLen=len;
ptr=Chunk->Buffer;
if (Chunk->ChunkSize==0)
{
vptr=ptr;
if (*vptr=='\r') vptr++;
if (*vptr=='\n') vptr++;
ptr=strchr(vptr,'\n');
if (ptr)
{
*ptr='\0';
ptr++;
}
else ptr=Chunk->Buffer;
Chunk->ChunkSize=strtol(vptr,NULL,16);
Chunk->BuffLen=Chunk->Buffer+len-ptr;
memmove(Chunk->Buffer,ptr,Chunk->BuffLen);
if (Chunk->ChunkSize==0) return(0);
}
else if (len >= Chunk->ChunkSize)
{
val=Chunk->ChunkSize;
//We should really grow OutBuff to take all the data
//but for the sake of simplicity we'll just use the space
//supplied
if (val > *OutLen) val=*OutLen;
memcpy(*OutBuff,Chunk->Buffer,val);
ptr=Chunk->Buffer+val;
Chunk->BuffLen-=val;
Chunk->ChunkSize-=val;
memmove(Chunk->Buffer, ptr, Chunk->BuffLen);
}
if (Chunk->ChunkSize < 0) Chunk->ChunkSize=0;
return(val);
}
示例13: HashFinishCRC
int HashFinishCRC(HASH *Hash, char **HashStr)
{
unsigned long crc;
int len;
len=sizeof(unsigned long);
crc32Finish((unsigned long *) Hash->Ctx);
crc=htonl(* (unsigned long *) Hash->Ctx);
*HashStr=SetStrLen(*HashStr,len);
memcpy(*HashStr,&crc,len);
return(len);
}
示例14: SendResponse
void SendResponse(ConnectStruct *Con,DNSMessageStruct *Response)
{
struct sockaddr_in Send_sa;
short int sendlen;
int len, salen;
char *Buffer=NULL;
ListNode *Curr;
ResourceRecord *RR;
Buffer=SetStrLen(Buffer,1024);
len=CreateResponsePacket(Buffer,Buffer+1024,Response,&Settings);
if (len==0)
{
LogToFile(Settings.LogFilePath,"ERROR: Zero length response packet");
DestroyString(Buffer);
return;
}
if (Con->Type==TCP_CONNECT)
{
sendlen=htons(len);
write(Con->fd, &sendlen, sizeof(short int));
write(Con->fd, Buffer, len);
}
else if (Con->Type==UDP_CONNECT)
{
Send_sa.sin_family=AF_INET;
Send_sa.sin_addr.s_addr=Response->ClientIP;
Send_sa.sin_port=Response->ClientPort;
salen=sizeof(struct sockaddr_in);
sendto(Con->fd,Buffer,len,0,(struct sockaddr *) &Send_sa,salen);
}
else LogToFile(Settings.LogFilePath,"ERROR: Unknown Comms Type %d on send",Con->Type);
if (Settings.LogLevel >= LOG_RESPONSES)
{
LogToFile(Settings.LogFilePath,"Sent %d answers to %s for %s query",ListSize(Response->Answers), IPtoStr(Response->ClientIP),Response->Question);
Curr=ListGetNext(Response->Answers);
while (Curr)
{
RR=(ResourceRecord *) Curr->Item;
LogToFile(Settings.LogFilePath," ANS: %s->%s type=%d ttl=%d",RR->Question,RR->Answer,RR->Type,RR->TTL);
Curr=ListGetNext(Curr);
}
}
DestroyString(Buffer);
}
示例15: SMTPLogin
int SMTPLogin(STREAM *S, int Caps, const char *User, const char *Pass)
{
char *Tempstr=NULL, *Base64=NULL, *ptr;
int len, result=FALSE;
if (Caps & CAP_AUTH_LOGIN)
{
Tempstr=CopyStr(Tempstr, "AUTH LOGIN\r\n");
if (SMTPInteract(Tempstr, S))
{
Base64=EncodeBytes(Base64, User, StrLen(User), ENCODE_BASE64);
Tempstr=MCopyStr(Tempstr, Base64, "\r\n", NULL);
if (SMTPInteract(Tempstr, S))
{
Base64=EncodeBytes(Base64, Pass, StrLen(Pass), ENCODE_BASE64);
Tempstr=MCopyStr(Tempstr, Base64, "\r\n", NULL);
if (SMTPInteract(Tempstr, S)) result=TRUE;
}
}
}
else if (Caps & CAP_AUTH_PLAIN)
{
Tempstr=SetStrLen(Tempstr, StrLen(User) + StrLen(Pass) +10);
//this isn't what it looks like. The '\0' here do not terminate the string
//as this authentication system uses a string with '\0' as separators
len=StrLen(User);
ptr=Tempstr;
memcpy(ptr, User, len);
ptr+=len;
*ptr='\0';
ptr++;
len=StrLen(Pass);
memcpy(ptr, Pass, len);
ptr+=len;
*ptr='\0';
ptr++;
Base64=EncodeBytes(Base64, Tempstr, ptr-Tempstr, ENCODE_BASE64);
Tempstr=MCopyStr(Tempstr, "AUTH PLAIN ", Base64, "\r\n",NULL);
if (SMTPInteract(Tempstr, S)) result=TRUE;
}
DestroyString(Tempstr);
DestroyString(Base64);
return(result);
}