瀏覽代碼

rm duplicate symbol #94

ithewei 4 年之前
父節點
當前提交
9fdcca636f
共有 9 個文件被更改,包括 67 次插入67 次删除
  1. 1 1
      http/client/WebSocketClient.cpp
  2. 6 6
      http/wsdef.c
  3. 1 1
      protocol/smtp.c
  4. 2 2
      util/base64.c
  5. 2 2
      util/base64.h
  6. 20 20
      util/md5.c
  7. 4 4
      util/md5.h
  8. 22 22
      util/sha1.c
  9. 9 9
      util/sha1.h

+ 1 - 1
http/client/WebSocketClient.cpp

@@ -67,7 +67,7 @@ int WebSocketClient::open(const char* _url) {
                 *p = rand();
             }
             char ws_key[32] = {0};
-            base64_encode(rand_key, 16, ws_key);
+            hv_base64_encode(rand_key, 16, ws_key);
             http_req_->headers[SEC_WEBSOCKET_KEY] = ws_key;
             http_req_->headers[SEC_WEBSOCKET_VERSION] = "13";
             std::string http_msg = http_req_->Dump(true, true);

+ 6 - 6
http/wsdef.c

@@ -11,12 +11,12 @@
 void ws_encode_key(const char* key, char accept[]) {
     char magic[] = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
     unsigned char digest[20] = {0};
-    SHA1_CTX ctx;
-    SHA1Init(&ctx);
-    SHA1Update(&ctx, (unsigned char*)key, strlen(key));
-    SHA1Update(&ctx, (unsigned char*)magic, strlen(magic));
-    SHA1Final(digest, &ctx);
-    base64_encode(digest, 20, accept);
+    HV_SHA1_CTX ctx;
+    HV_SHA1Init(&ctx);
+    HV_SHA1Update(&ctx, (unsigned char*)key, strlen(key));
+    HV_SHA1Update(&ctx, (unsigned char*)magic, strlen(magic));
+    HV_SHA1Final(digest, &ctx);
+    hv_base64_encode(digest, 20, accept);
 }
 
 // fix-header[2] + var-length[2/8] + mask[4] + data[data_len]

+ 1 - 1
protocol/smtp.c

@@ -111,7 +111,7 @@ int sendmail(const char* smtp_server,
         memcpy(basic+1+usernamelen+1, password, passwordlen);
         basiclen = 1 + usernamelen + 1 + passwordlen;
     }
-    base64_encode((unsigned char*)basic, basiclen, buf);
+    hv_base64_encode((unsigned char*)basic, basiclen, buf);
     cmdlen = BASE64_ENCODE_OUT_SIZE(basiclen);
     buf[cmdlen] = '\r';
     buf[cmdlen+1] = '\n';

+ 2 - 2
util/base64.c

@@ -50,7 +50,7 @@ static const signed char base64de[] = {
         44,  45,  46,  47,  48,  49,  50,  51,
 };
 
-int base64_encode(const unsigned char *in, unsigned int inlen, char *out) {
+int hv_base64_encode(const unsigned char *in, unsigned int inlen, char *out) {
     unsigned int i, j;
 
     for (i = j = 0; i < inlen; i++) {
@@ -85,7 +85,7 @@ int base64_encode(const unsigned char *in, unsigned int inlen, char *out) {
     return BASE64_OK;
 }
 
-int base64_decode(const char *in, unsigned int inlen, unsigned char *out) {
+int hv_base64_decode(const char *in, unsigned int inlen, unsigned char *out) {
     unsigned int i, j;
 
     for (i = j = 0; i < inlen; i++) {

+ 2 - 2
util/base64.h

@@ -10,8 +10,8 @@ enum {BASE64_OK = 0, BASE64_INVALID};
 
 BEGIN_EXTERN_C
 
-HV_EXPORT int base64_encode(const unsigned char *in, unsigned int inlen, char *out);
-HV_EXPORT int base64_decode(const char *in, unsigned int inlen, unsigned char *out);
+HV_EXPORT int hv_base64_encode(const unsigned char *in, unsigned int inlen, char *out);
+HV_EXPORT int hv_base64_decode(const char *in, unsigned int inlen, unsigned char *out);
 
 END_EXTERN_C
 

+ 20 - 20
util/md5.c

@@ -32,9 +32,9 @@
         a += b; \
     }
 
-static void MD5Transform(unsigned int state[4],unsigned char block[64]);
-static void MD5Encode(unsigned char *output,unsigned int *input,unsigned int len);
-static void MD5Decode(unsigned int *output,unsigned char *input,unsigned int len);
+static void HV_MD5Transform(unsigned int state[4],unsigned char block[64]);
+static void HV_MD5Encode(unsigned char *output,unsigned int *input,unsigned int len);
+static void HV_MD5Decode(unsigned int *output,unsigned char *input,unsigned int len);
 
 static unsigned char PADDING[] = {
     0x80,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
@@ -43,7 +43,7 @@ static unsigned char PADDING[] = {
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
 };
 
-void MD5Init(MD5_CTX *ctx) {
+void HV_MD5Init(HV_MD5_CTX *ctx) {
     ctx->count[0] = 0;
     ctx->count[1] = 0;
     ctx->state[0] = 0x67452301;
@@ -52,7 +52,7 @@ void MD5Init(MD5_CTX *ctx) {
     ctx->state[3] = 0x10325476;
 }
 
-void MD5Update(MD5_CTX *ctx,unsigned char *input,unsigned int inputlen) {
+void HV_MD5Update(HV_MD5_CTX *ctx,unsigned char *input,unsigned int inputlen) {
     unsigned int i = 0,index = 0,partlen = 0;
     index = (ctx->count[0] >> 3) & 0x3F;
     partlen = 64 - index;
@@ -64,9 +64,9 @@ void MD5Update(MD5_CTX *ctx,unsigned char *input,unsigned int inputlen) {
 
     if(inputlen >= partlen) {
         memcpy(&ctx->buffer[index],input,partlen);
-        MD5Transform(ctx->state,ctx->buffer);
+        HV_MD5Transform(ctx->state,ctx->buffer);
         for(i = partlen;i+64 <= inputlen;i+=64) {
-            MD5Transform(ctx->state,&input[i]);
+            HV_MD5Transform(ctx->state,&input[i]);
         }
         index = 0;
     } else {
@@ -76,18 +76,18 @@ void MD5Update(MD5_CTX *ctx,unsigned char *input,unsigned int inputlen) {
     memcpy(&ctx->buffer[index],&input[i],inputlen-i);
 }
 
-void MD5Final(MD5_CTX *ctx,unsigned char digest[16]) {
+void HV_MD5Final(HV_MD5_CTX *ctx,unsigned char digest[16]) {
     unsigned int index = 0,padlen = 0;
     unsigned char bits[8];
     index = (ctx->count[0] >> 3) & 0x3F;
     padlen = (index < 56)?(56-index):(120-index);
-    MD5Encode(bits,ctx->count,8);
-    MD5Update(ctx,PADDING,padlen);
-    MD5Update(ctx,bits,8);
-    MD5Encode(digest,ctx->state,16);
+    HV_MD5Encode(bits,ctx->count,8);
+    HV_MD5Update(ctx,PADDING,padlen);
+    HV_MD5Update(ctx,bits,8);
+    HV_MD5Encode(digest,ctx->state,16);
 }
 
-void MD5Encode(unsigned char *output,unsigned int *input,unsigned int len) {
+void HV_MD5Encode(unsigned char *output,unsigned int *input,unsigned int len) {
     unsigned int i = 0,j = 0;
     while(j < len) {
         output[j] = input[i] & 0xFF;
@@ -99,7 +99,7 @@ void MD5Encode(unsigned char *output,unsigned int *input,unsigned int len) {
     }
 }
 
-void MD5Decode(unsigned int *output,unsigned char *input,unsigned int len) {
+void HV_MD5Decode(unsigned int *output,unsigned char *input,unsigned int len) {
     unsigned int i = 0,j = 0;
     while(j < len) {
         output[i] = (input[j]) | (input[j+1] << 8) | (input[j+2] << 16) | (input[j+3] << 24);
@@ -108,14 +108,14 @@ void MD5Decode(unsigned int *output,unsigned char *input,unsigned int len) {
     }
 }
 
-void MD5Transform(unsigned int state[4],unsigned char block[64]) {
+void HV_MD5Transform(unsigned int state[4],unsigned char block[64]) {
     unsigned int a = state[0];
     unsigned int b = state[1];
     unsigned int c = state[2];
     unsigned int d = state[3];
     unsigned int x[64];
 
-    MD5Decode(x,block,64);
+    HV_MD5Decode(x,block,64);
 
     FF(a, b, c, d, x[ 0], 7, 0xd76aa478);
     FF(d, a, b, c, x[ 1], 12, 0xe8c7b756);
@@ -192,10 +192,10 @@ void MD5Transform(unsigned int state[4],unsigned char block[64]) {
 }
 
 void hv_md5(unsigned char* input, unsigned int inputlen, unsigned char digest[16]) {
-    MD5_CTX ctx;
-    MD5Init(&ctx);
-    MD5Update(&ctx, input, inputlen);
-    MD5Final(&ctx, digest);
+    HV_MD5_CTX ctx;
+    HV_MD5Init(&ctx);
+    HV_MD5Update(&ctx, input, inputlen);
+    HV_MD5Final(&ctx, digest);
 }
 
 static inline char i2hex(unsigned char i) {

+ 4 - 4
util/md5.h

@@ -7,13 +7,13 @@ typedef struct {
     unsigned int    count[2];
     unsigned int    state[4];
     unsigned char   buffer[64];
-} MD5_CTX;
+} HV_MD5_CTX;
 
 BEGIN_EXTERN_C
 
-void MD5Init(MD5_CTX *ctx);
-void MD5Update(MD5_CTX *ctx, unsigned char *input, unsigned int inputlen);
-void MD5Final(MD5_CTX *ctx, unsigned char digest[16]);
+HV_EXPORT void HV_MD5Init(HV_MD5_CTX *ctx);
+HV_EXPORT void HV_MD5Update(HV_MD5_CTX *ctx, unsigned char *input, unsigned int inputlen);
+HV_EXPORT void HV_MD5Final(HV_MD5_CTX *ctx, unsigned char digest[16]);
 
 HV_EXPORT void hv_md5(unsigned char* input, unsigned int inputlen, unsigned char digest[16]);
 

+ 22 - 22
util/sha1.c

@@ -46,7 +46,7 @@ A million repetitions of "a"
 
 /* Hash a single 512-bit block. This is the core of the algorithm. */
 
-void SHA1Transform(
+void HV_SHA1Transform(
     uint32_t state[5],
     const unsigned char buffer[64]
 )
@@ -172,10 +172,10 @@ void SHA1Transform(
 }
 
 
-/* SHA1Init - Initialize new context */
+/* HV_SHA1Init - Initialize new context */
 
-void SHA1Init(
-    SHA1_CTX * context
+void HV_SHA1Init(
+    HV_SHA1_CTX * context
 )
 {
     /* SHA1 initialization constants */
@@ -190,8 +190,8 @@ void SHA1Init(
 
 /* Run your data through this. */
 
-void SHA1Update(
-    SHA1_CTX * context,
+void HV_SHA1Update(
+    HV_SHA1_CTX * context,
     const unsigned char *data,
     uint32_t len
 )
@@ -208,10 +208,10 @@ void SHA1Update(
     if ((j + len) > 63)
     {
         memcpy(&context->buffer[j], data, (i = 64 - j));
-        SHA1Transform(context->state, context->buffer);
+        HV_SHA1Transform(context->state, context->buffer);
         for (; i + 63 < len; i += 64)
         {
-            SHA1Transform(context->state, &data[i]);
+            HV_SHA1Transform(context->state, &data[i]);
         }
         j = 0;
     }
@@ -223,9 +223,9 @@ void SHA1Update(
 
 /* Add padding and return the message digest. */
 
-void SHA1Final(
+void HV_SHA1Final(
     unsigned char digest[20],
-    SHA1_CTX * context
+    HV_SHA1_CTX * context
 )
 {
     unsigned i;
@@ -257,13 +257,13 @@ void SHA1Final(
     }
 #endif
     c = 0200;
-    SHA1Update(context, &c, 1);
+    HV_SHA1Update(context, &c, 1);
     while ((context->count[0] & 504) != 448)
     {
         c = 0000;
-        SHA1Update(context, &c, 1);
+        HV_SHA1Update(context, &c, 1);
     }
-    SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */
+    HV_SHA1Update(context, finalcount, 8); /* Should cause a HV_SHA1Transform() */
     for (i = 0; i < 20; i++)
     {
         digest[i] = (unsigned char)
@@ -274,26 +274,26 @@ void SHA1Final(
     memset(&finalcount, '\0', sizeof(finalcount));
 }
 
-void SHA1(
+void HV_SHA1(
     char *hash_out,
     const char *str,
     int len)
 {
-    SHA1_CTX ctx;
+    HV_SHA1_CTX ctx;
     unsigned int ii;
 
-    SHA1Init(&ctx);
+    HV_SHA1Init(&ctx);
     for (ii=0; ii<len; ii+=1)
-        SHA1Update(&ctx, (const unsigned char*)str + ii, 1);
-    SHA1Final((unsigned char *)hash_out, &ctx);
+        HV_SHA1Update(&ctx, (const unsigned char*)str + ii, 1);
+    HV_SHA1Final((unsigned char *)hash_out, &ctx);
     hash_out[20] = '\0';
 }
 
 void hv_sha1(unsigned char* input, uint32_t inputlen, unsigned char digest[20]) {
-    SHA1_CTX ctx;
-    SHA1Init(&ctx);
-    SHA1Update(&ctx, input, inputlen);
-    SHA1Final(digest, &ctx);
+    HV_SHA1_CTX ctx;
+    HV_SHA1Init(&ctx);
+    HV_SHA1Update(&ctx, input, inputlen);
+    HV_SHA1Final(digest, &ctx);
 }
 
 static inline char i2hex(unsigned char i) {

+ 9 - 9
util/sha1.h

@@ -16,31 +16,31 @@ typedef struct {
     uint32_t state[5];
     uint32_t count[2];
     unsigned char buffer[64];
-} SHA1_CTX;
+} HV_SHA1_CTX;
 
 BEGIN_EXTERN_C
 
-void SHA1Transform(
+HV_EXPORT void HV_SHA1Transform(
     uint32_t state[5],
     const unsigned char buffer[64]
     );
 
-void SHA1Init(
-    SHA1_CTX * context
+HV_EXPORT void HV_SHA1Init(
+    HV_SHA1_CTX * context
     );
 
-void SHA1Update(
-    SHA1_CTX * context,
+HV_EXPORT void HV_SHA1Update(
+    HV_SHA1_CTX * context,
     const unsigned char *data,
     uint32_t len
     );
 
-void SHA1Final(
+HV_EXPORT void HV_SHA1Final(
     unsigned char digest[20],
-    SHA1_CTX * context
+    HV_SHA1_CTX * context
     );
 
-void SHA1(
+HV_EXPORT void HV_SHA1(
     char *hash_out,
     const char *str,
     int len);