demo:
----return :返回值------------------
int mosquitto_username_pw_set(struct mosquitto *mosq, const char *username, const char *password)
{
if(!mosq) return MOSQ_ERR_INVAL;
if(mosq->username){
_mosquitto_free(mosq->username);
mosq->username = NULL;
}
if(mosq->password){
_mosquitto_free(mosq->password);
mosq->password = NULL;
}
if(username){
mosq->username = _mosquitto_strdup(username);
if(!mosq->username) return MOSQ_ERR_NOMEM;
if(password){
mosq->password = _mosquitto_strdup(password);
if(!mosq->password){
_mosquitto_free(mosq->username);
mosq->username = NULL;
return MOSQ_ERR_NOMEM;
}
}
}
return MOSQ_ERR_SUCCESS;
}
//----------------------------------------------------------------------------------------------------
void main(void){
int x=1;
x= mosquitto_username_pw_set(mosq, username, password);
printf("----------------------------------------------data= %d\n",x);
printf("username= %s\n",username);
}