Fix warning as error for V2

Change-Id: I70cfd971fda629011ba1be84fef15afea196d393
diff --git a/mbtk/libmbtk_lib_v2/mqtt/MQTTClient.c b/mbtk/libmbtk_lib_v2/mqtt/MQTTClient.c
index 4a349a7..b197a85 100755
--- a/mbtk/libmbtk_lib_v2/mqtt/MQTTClient.c
+++ b/mbtk/libmbtk_lib_v2/mqtt/MQTTClient.c
@@ -79,7 +79,7 @@
 
 void mbtk_ali_auth_regnwl_sava(MQTTMessage msg)
 {
-    printf("pub, payload: %d,%s\n", msg.payloadlen, msg.payload);
+    printf("pub, payload: %d,%s\n", msg.payloadlen, (char*)msg.payload);
     int32_t res = SUCCESS;
 
     char *client_key = "clientId",*deviceToken_key="deviceToken";
@@ -118,9 +118,9 @@
 
 int sendPacket(Client* c, int length, Timer* timer)
 {
-    int rc = FAILURE, 
+    int rc = FAILURE,
         sent = 0;
-    
+
     while (sent < length && !expired(timer))
     {
         rc = c->ipstack->mqttwrite(c->ipstack, &c->buf[sent], length, left_ms(timer));
@@ -131,7 +131,7 @@
     printf("rc ----%d,sent----%d,length----%d\n",rc,sent,length);
     if (sent == length)
     {
-        countdown(&c->ping_timer, c->keepAliveInterval); // record the fact that we have successfully sent the packet    
+        countdown(&c->ping_timer, c->keepAliveInterval); // record the fact that we have successfully sent the packet
         rc = SUCCESS;
     }
     else
@@ -144,7 +144,7 @@
 {
     int i;
     c->ipstack = network;
-    
+
     for (i = 0; i < MAX_MESSAGE_HANDLERS; ++i)
         c->messageHandlers[i].topicFilter = 0;
     c->command_timeout_ms = command_timeout_ms;
@@ -187,7 +187,7 @@
 }
 
 
-int readPacket(Client* c, Timer* timer) 
+int readPacket(Client* c, Timer* timer)
 {
     int rc = FAILURE;
     MQTTHeader header = {0};
@@ -223,7 +223,7 @@
     char* curf = topicFilter;
     char* curn = topicName->lenstring.data;
     char* curn_end = curn + topicName->lenstring.len;
-    
+
     while (*curf && curn < curn_end)
     {
         if (*curn == '/' && *curf != '/')
@@ -241,7 +241,7 @@
         curf++;
         curn++;
     };
-    
+
     return (curn == curn_end) && (*curf == '\0');
 }
 
@@ -266,15 +266,15 @@
             }
         }
     }
-    
-    if (rc == FAILURE && c->defaultMessageHandler != NULL) 
+
+    if (rc == FAILURE && c->defaultMessageHandler != NULL)
     {
         MessageData md;
         NewMessageData(&md, topicName, message);
         c->defaultMessageHandler(&md);
         rc = SUCCESS;
-    }   
-    
+    }
+
     return rc;
 }
 
@@ -287,7 +287,7 @@
         rc = SUCCESS;
         goto exit;
     }
-    
+
     if (expired(&c->ping_timer))
     {
         if (!c->ping_outstanding)
@@ -303,7 +303,7 @@
         }
     	else
     	{
-    	    printf("fail_count-------------\n",c->fail_count);
+    	    printf("fail_count:%d-------------\n",c->fail_count);
             ++(c->fail_count);
             if (c->fail_count >= MAX_FAIL_ALLOWED)
             {
@@ -334,7 +334,7 @@
 		rc =  DISCONNECTED;
 		goto exit;
 	}
-    
+
     switch (packet_type)
     {
         case CONNACK:
@@ -412,9 +412,9 @@
     int rc = SUCCESS;
     Timer timer;
 
-    InitTimer(&timer);    
+    InitTimer(&timer);
     countdown_ms(&timer, timeout_ms);
-    static int i = 0;
+//    static int i = 0;
     if (c->isconnected)
     		rc = keepalive(c);
     if(rc < 0)
@@ -435,10 +435,10 @@
 */
     do
     {
-            if (expired(&timer)) 
+            if (expired(&timer))
             break; // we timed out
     }
-    while ((rc = cycle(c, &timer)) != PUBLISH);  
+    while ((rc = cycle(c, &timer)) != PUBLISH);
     rc = SUCCESS;
     return rc;
 }
@@ -450,11 +450,11 @@
     int rc = FAILURE;
     do
     {
-            if (expired(timer)) 
+            if (expired(timer))
             break; // we timed out
     }
-    while ((rc = cycle(c, timer)) != packet_type &&  (rc = cycle(c, timer)) != DISCONNECTED);  
-    
+    while ((rc = cycle(c, timer)) != packet_type &&  (rc = cycle(c, timer)) != DISCONNECTED);
+
     return rc;
 }
 
@@ -473,7 +473,7 @@
 
     if (options == 0)
         options = &default_options; // set default options if none were supplied
-    
+
     c->keepAliveInterval = options->keepAliveInterval;
     countdown(&c->ping_timer, c->keepAliveInterval);
     printf("[%s]c->keepAliveInterval = %d", __FUNCTION__,c->keepAliveInterval);
@@ -481,7 +481,7 @@
         goto exit;
     if ((rc = sendPacket(c, len, &connect_timer)) != SUCCESS)  // send the connect packet
         goto exit; // there was a problem
-    
+
     // this will be a blocking call, wait for the connack
     if (waitfor(c, CONNACK, &connect_timer) == CONNACK)
     {
@@ -494,7 +494,7 @@
     }
     else
         rc = FAILURE;
-    
+
 exit:
     if (rc == SUCCESS)
         c->isconnected = 1;
@@ -503,31 +503,31 @@
 
 
 int MQTTSubscribe(Client* c, const char* topicFilter, enum QoS qos, messageHandler messageHandler)
-{ 
-    int rc = FAILURE;  
+{
+    int rc = FAILURE;
     Timer timer;
     int len = 0;
     MQTTString topic = MQTTString_initializer;
     topic.cstring = (char *)topicFilter;
-    
+
     InitTimer(&timer);
     countdown_ms(&timer, c->command_timeout_ms);
 
     if (!c->isconnected)
         goto exit;
-    
+
     len = MQTTSerialize_subscribe(c->buf, c->buf_size, 0, getNextPacketId(c), 1, &topic, (int*)&qos);
     if (len <= 0)
         goto exit;
     if ((rc = sendPacket(c, len, &timer)) != SUCCESS) // send the subscribe packet
         goto exit;             // there was a problem
-    
-    if (waitfor(c, SUBACK, &timer) == SUBACK)      // wait for suback 
+
+    if (waitfor(c, SUBACK, &timer) == SUBACK)      // wait for suback
     {
         int count = 0, grantedQoS = -1;
         unsigned short mypacketid;
         if (MQTTDeserialize_suback(&mypacketid, 1, &count, &grantedQoS, c->readbuf, c->readbuf_size) == 1)
-            rc = grantedQoS; // 0, 1, 2 or 0x80 
+            rc = grantedQoS; // 0, 1, 2 or 0x80
         if (rc != 0x80)
         {
             int i;
@@ -543,9 +543,9 @@
             }
         }
     }
-    else 
+    else
         rc = FAILURE;
-        
+
 exit:
     return rc;
 }
@@ -565,16 +565,16 @@
 }
 
 int MQTTUnsubscribe(Client* c, const char* topicFilter)
-{   
+{
     int rc = FAILURE;
-    Timer timer;    
+    Timer timer;
     MQTTString topic = MQTTString_initializer;
     topic.cstring = (char *)topicFilter;
     int len = 0;
 
     InitTimer(&timer);
     countdown_ms(&timer, c->command_timeout_ms);
-    
+
     if (!c->isconnected)
         goto exit;
     if(messageHandlersFindIndex(c,topicFilter) < 0)
@@ -598,14 +598,14 @@
                 && (strcmp(c->messageHandlers[i].topicFilter, topicFilter) == 0))
                 {
                     c->messageHandlers[i].topicFilter=NULL;
-                    rc = 0; 
+                    rc = 0;
                 }
             }
         }
     }
     else
         rc = FAILURE;
-    
+
 exit:
     return rc;
 }
@@ -614,20 +614,20 @@
 int MQTTPublish(Client* c, const char* topicName, MQTTMessage* message)
 {
     int rc = FAILURE;
-    Timer timer;   
+    Timer timer;
     MQTTString topic = MQTTString_initializer;
     topic.cstring = (char *)topicName;
     int len = 0;
 
     InitTimer(&timer);
     countdown_ms(&timer, c->command_timeout_ms);
-    
+
     if (!c->isconnected)
         goto exit;
     if (message->qos == QOS1 || message->qos == QOS2)
         message->id = getNextPacketId(c);
-    
-    len = MQTTSerialize_publish(c->buf, c->buf_size, 0, message->qos, message->retained, message->id, 
+
+    len = MQTTSerialize_publish(c->buf, c->buf_size, 0, message->qos, message->retained, message->id,
               topic, (unsigned char*)message->payload, message->payloadlen);
 
     if (len <= 0)
@@ -659,14 +659,14 @@
         else
             rc = FAILURE;
     }
-    
+
 exit:
     return rc;
 }
 
 
 int MQTTDisconnect(Client* c ,Network * n)
-{  
+{
     int rc = FAILURE;
     Timer timer;     // we might wait for incomplete incoming publishes to complete
     int len = MQTTSerialize_disconnect(c->buf, c->buf_size);
@@ -676,7 +676,7 @@
 
     if (len > 0)
         rc = sendPacket(c, len, &timer);            // send the disconnect packet
-        
+
     c->isconnected = 0;
     n->disconnect(n);
     return rc;
diff --git a/mbtk/libmbtk_lib_v2/mqtt/MQTTPacket/MQTTFormat.c b/mbtk/libmbtk_lib_v2/mqtt/MQTTPacket/MQTTFormat.c
index 3015a0e..9878492 100755
--- a/mbtk/libmbtk_lib_v2/mqtt/MQTTPacket/MQTTFormat.c
+++ b/mbtk/libmbtk_lib_v2/mqtt/MQTTPacket/MQTTFormat.c
@@ -119,7 +119,7 @@
 	int index = 0;

 	int rem_length = 0;

 	MQTTHeader header = {0};

-	int strindex = 0;

+//	int strindex = 0;

 

 	header.byte = buf[index++];

 	index += MQTTPacket_decodeBuf(&buf[index], &rem_length);

@@ -130,7 +130,7 @@
 	{

 		unsigned char sessionPresent, connack_rc;

 		if (MQTTDeserialize_connack(&sessionPresent, &connack_rc, buf, buflen) == 1)

-			strindex = MQTTStringFormat_connack(strbuf, strbuflen, connack_rc, sessionPresent);

+			MQTTStringFormat_connack(strbuf, strbuflen, connack_rc, sessionPresent);

 	}

 	break;

 	case PUBLISH:

@@ -141,7 +141,7 @@
 		MQTTString topicName = MQTTString_initializer;

 		if (MQTTDeserialize_publish(&dup, &qos, &retained, &packetid, &topicName,

 				&payload, &payloadlen, buf, buflen) == 1)

-			strindex = MQTTStringFormat_publish(strbuf, strbuflen, dup, qos, retained, packetid,

+			MQTTStringFormat_publish(strbuf, strbuflen, dup, qos, retained, packetid,

 					topicName, payload, payloadlen);

 	}

 	break;

@@ -153,7 +153,7 @@
 		unsigned char packettype, dup;

 		unsigned short packetid;

 		if (MQTTDeserialize_ack(&packettype, &dup, &packetid, buf, buflen) == 1)

-			strindex = MQTTStringFormat_ack(strbuf, strbuflen, packettype, dup, packetid);

+			MQTTStringFormat_ack(strbuf, strbuflen, packettype, dup, packetid);

 	}

 	break;

 	case SUBACK:

@@ -162,20 +162,20 @@
 		int maxcount = 1, count = 0;

 		int grantedQoSs[1];

 		if (MQTTDeserialize_suback(&packetid, maxcount, &count, grantedQoSs, buf, buflen) == 1)

-			strindex = MQTTStringFormat_suback(strbuf, strbuflen, packetid, count, grantedQoSs);

+			MQTTStringFormat_suback(strbuf, strbuflen, packetid, count, grantedQoSs);

 	}

 	break;

 	case UNSUBACK:

 	{

 		unsigned short packetid;

 		if (MQTTDeserialize_unsuback(&packetid, buf, buflen) == 1)

-			strindex = MQTTStringFormat_ack(strbuf, strbuflen, UNSUBACK, 0, packetid);

+			MQTTStringFormat_ack(strbuf, strbuflen, UNSUBACK, 0, packetid);

 	}

 	break;

 	case PINGREQ:

 	case PINGRESP:

 	case DISCONNECT:

-		strindex = snprintf(strbuf, strbuflen, "%s", MQTTPacket_names[header.bits.type]);

+		snprintf(strbuf, strbuflen, "%s", MQTTPacket_names[header.bits.type]);

 		break;

 	}

 	return strbuf;

@@ -187,7 +187,7 @@
 	int index = 0;

 	int rem_length = 0;

 	MQTTHeader header = {0};

-	int strindex = 0;

+//	int strindex = 0;

 

 	header.byte = buf[index++];

 	index += MQTTPacket_decodeBuf(&buf[index], &rem_length);

@@ -199,7 +199,7 @@
 		MQTTPacket_connectData data;

 		int rc;

 		if ((rc = MQTTDeserialize_connect(&data, buf, buflen)) == 1)

-			strindex = MQTTStringFormat_connect(strbuf, strbuflen, &data);

+			MQTTStringFormat_connect(strbuf, strbuflen, &data);

 	}

 	break;

 	case PUBLISH:

@@ -210,7 +210,7 @@
 		MQTTString topicName = MQTTString_initializer;

 		if (MQTTDeserialize_publish(&dup, &qos, &retained, &packetid, &topicName,

 				&payload, &payloadlen, buf, buflen) == 1)

-			strindex = MQTTStringFormat_publish(strbuf, strbuflen, dup, qos, retained, packetid,

+			MQTTStringFormat_publish(strbuf, strbuflen, dup, qos, retained, packetid,

 					topicName, payload, payloadlen);

 	}

 	break;

@@ -222,7 +222,7 @@
 		unsigned char packettype, dup;

 		unsigned short packetid;

 		if (MQTTDeserialize_ack(&packettype, &dup, &packetid, buf, buflen) == 1)

-			strindex = MQTTStringFormat_ack(strbuf, strbuflen, packettype, dup, packetid);

+			MQTTStringFormat_ack(strbuf, strbuflen, packettype, dup, packetid);

 	}

 	break;

 	case SUBSCRIBE:

@@ -234,7 +234,7 @@
 		int requestedQoSs[1];

 		if (MQTTDeserialize_subscribe(&dup, &packetid, maxcount, &count,

 				topicFilters, requestedQoSs, buf, buflen) == 1)

-			strindex = MQTTStringFormat_subscribe(strbuf, strbuflen, dup, packetid, count, topicFilters, requestedQoSs);;

+			MQTTStringFormat_subscribe(strbuf, strbuflen, dup, packetid, count, topicFilters, requestedQoSs);;

 	}

 	break;

 	case UNSUBSCRIBE:

@@ -244,13 +244,13 @@
 		int maxcount = 1, count = 0;

 		MQTTString topicFilters[1];

 		if (MQTTDeserialize_unsubscribe(&dup, &packetid, maxcount, &count, topicFilters, buf, buflen) == 1)

-			strindex =  MQTTStringFormat_unsubscribe(strbuf, strbuflen, dup, packetid, count, topicFilters);

+			MQTTStringFormat_unsubscribe(strbuf, strbuflen, dup, packetid, count, topicFilters);

 	}

 	break;

 	case PINGREQ:

 	case PINGRESP:

 	case DISCONNECT:

-		strindex = snprintf(strbuf, strbuflen, "%s", MQTTPacket_names[header.bits.type]);

+		snprintf(strbuf, strbuflen, "%s", MQTTPacket_names[header.bits.type]);

 		break;

 	}

 	strbuf[strbuflen] = '\0';

diff --git a/mbtk/libmbtk_lib_v2/mqtt/mbtk_mqtt.c b/mbtk/libmbtk_lib_v2/mqtt/mbtk_mqtt.c
index 3b78429..40bd5e5 100755
--- a/mbtk/libmbtk_lib_v2/mqtt/mbtk_mqtt.c
+++ b/mbtk/libmbtk_lib_v2/mqtt/mbtk_mqtt.c
@@ -19,6 +19,9 @@
 #include "arpa/inet.h"
 #include "fcntl.h"
 #include "mbtk_sock2.h"
+#include "MQTTPacket/core_sha256.h"
+#include "MQTTPacket/core_sha1.h"
+
 
 #include "mbtk_type.h"
 #include "mbtk_http.h"
@@ -111,17 +114,17 @@
     printf("product_secret: %s\n", product_secret);
     printf("device_name: %s\n", device_name);
 
-    int32_t res = 0, content_len = 0;
+//    int32_t content_len = 0;
     char content[255] = {0};
     char random[15+1]={0};;
     char  sign[65] = {0};
-    int dynamic_register_request_len = 0;
+//    int dynamic_register_request_len = 0;
 //    char *content_fmt = "productKey=%s&deviceName=%s&random=%s&sign=%s&signMethod=%s";
-    char *signMethod = MBTK_MQTT_HTTP_SIGN_METHOD_HMACSHA256;
+//    char *signMethod = MBTK_MQTT_HTTP_SIGN_METHOD_HMACSHA256;
 
 
     memcpy(random, "8Ygb7ULYh53B6OA", strlen("8Ygb7ULYh53B6OA"));
-    char *content_src[] = { product_key, device_name, random,sign,signMethod};
+//    char *content_src[] = { product_key, device_name, random,sign,signMethod};
     mbtk_imqtt_http_dynreg_sign(product_key,product_secret,device_name,random,sign);
 
     sprintf(content, "productKey=%s&deviceName=%s&random=%s&sign=%s&signMethod=%s",
@@ -145,7 +148,7 @@
     {
         char* ptr_start = NULL;
         char* ptr_end = NULL;
-        char fac[64] = {'\0'};
+//        char fac[64] = {'\0'};
         ptr_start = strstr(data, "deviceSecret");
         if(ptr_start != NULL)
         {
@@ -217,9 +220,10 @@
     const mbtk_http_session_t* session = mbtk_http_session_get(http_handle, http_session);
     printf("HTTP:%d,%s,%d,%s\n",session->option,session->host,session->port,session->uri);
 
+#if 0
     char *header = "Accept: text/xml,text/javascript,text/html,application/json\r\n" \
                           "Content-Type: application/x-www-form-urlencoded\r\n";
-
+#endif
 
     mbtk_http_session_head_add(http_handle, http_session, "Accept", "text/xml,text/javascript,text/html,application/json");
 
@@ -260,7 +264,7 @@
 void mbtk_aliyun_mqtt_get_connect_para(char *password,char *cliendid,char *username, mbtk_mqtt_device_session_t *mbtk_mqtt_device_t)
 {
   /*********password.mqttClientId.user_name *************/
-    char content[MBTK_IMQTT_PASSWORD_LEN] = {0};
+    char content[1024] = {0};
 
     printf("mbtk_mqtt_device_t->device_name: %s\n", mbtk_mqtt_device_t->device_name);
     printf("mbtk_mqtt_device_t->product_key: %s\n", mbtk_mqtt_device_t->product_key);
@@ -272,15 +276,15 @@
 
 //    snprintf((char *)cliendid,MBTK_IMQTT_CLIENT_ID_LEN,"%s|securemode=-2,authType=regnwl,random=123,signmethod=hmacsha1,instanceId=%s|",mbtk_mqtt_device_t->device_name,"iot-06z00ag5qidat54");
 
-    snprintf((char *)cliendid,MBTK_IMQTT_CLIENT_ID_LEN,"%s|securemode=-2,authType=regnwl,random=123,signmethod=hmacsha1|",mbtk_mqtt_device_t->device_name);
-    snprintf((char *)username,MBTK_IMQTT_USER_NAME_LEN,"%s&%s",mbtk_mqtt_device_t->device_name,mbtk_mqtt_device_t->product_key);
+    snprintf((char *)cliendid,sizeof(content),"%s|securemode=-2,authType=regnwl,random=123,signmethod=hmacsha1|",mbtk_mqtt_device_t->device_name);
+    snprintf((char *)username,sizeof(content),"%s&%s",mbtk_mqtt_device_t->device_name,mbtk_mqtt_device_t->product_key);
 }
 
 
 void mbtk_imqtt_auth_hostname(char *dest, char *product_key, int host)
 {
 //  char *host = "&product_key.iot-as-mqtt.cn-shanghai.aliyuncs.com";
-    int8_t      public_instance = 1;
+//    int8_t      public_instance = 1;
 
     snprintf(dest, 100, "%s.%s", product_key, mqtt_url[host]);
 }
@@ -507,7 +511,7 @@
         ret = -101;
         goto __END;
     }
-    MQTTClient(&piot_mqtt->Client, piot_mqtt->network, 1000*30, piot_mqtt->mqtt_buffer, MQTT_BUF_SIZE, piot_mqtt->mqtt_read_buffer, MQTT_BUF_SIZE);
+    MQTTClient(&piot_mqtt->Client, piot_mqtt->network, 1000*30, (unsigned char*)piot_mqtt->mqtt_buffer, MQTT_BUF_SIZE, (unsigned char*)piot_mqtt->mqtt_read_buffer, MQTT_BUF_SIZE);
     MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
 
     data.MQTTVersion = piot_mqtt->mqtt_version;
@@ -549,7 +553,7 @@
         ret = -101;
         goto __END;
     }
-    MQTTClient(&piot_mqtt->Client, piot_mqtt->network, 1000, piot_mqtt->mqtt_buffer, MQTT_BUF_SIZE, piot_mqtt->mqtt_read_buffer, MQTT_BUF_SIZE);
+    MQTTClient(&piot_mqtt->Client, piot_mqtt->network, 1000, (unsigned char*)piot_mqtt->mqtt_buffer, MQTT_BUF_SIZE, (unsigned char*)piot_mqtt->mqtt_read_buffer, MQTT_BUF_SIZE);
     MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
 
     if (piot_mqtt->willFlag) {