Skip to content

Commit 7985c95

Browse files
Merge pull request #42 from nmcdonnell-kx/master
Reapply Rian's change without strndup
2 parents b27c5f9 + 48b6206 commit 7985c95

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/mqtt.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@ static char* getStringFromList(K propValues,int row, const char** value, char* e
5151
return errStr;
5252
}
5353

54+
static char* getCharArrayAsStringFromList(K propValues,int row, const char** value, char* errStr)
55+
{
56+
if ((int)(kK(propValues)[row]->t) == KC)
57+
{
58+
// Don't use strndup because it's not supported on early OS X builds
59+
char* str = malloc(kK(propValues)[row]->n + 1);
60+
memcpy(str, kC(kK(propValues)[row]), kK(propValues)[row]->n);
61+
str[kK(propValues)[row]->n] = '\0';
62+
*value = str;
63+
return 0;
64+
}
65+
return errStr;
66+
}
67+
5468
static char* getIntFromList(K propValues,int row, int* value, char* errStr)
5569
{
5670
if ((int)(kK(propValues)[row]->t) == -KI)
@@ -77,6 +91,7 @@ EXP K connX(K tcpconn,K pname, K opt){
7791
return krr("options");
7892
client = 0;
7993

94+
MQTTClient_willOptions will_opts = MQTTClient_willOptions_initializer;
8095
MQTTClient_connectOptions conn_opts = MQTTClient_connectOptions_initializer;
8196

8297
K propNames = (kK(opt)[0]);
@@ -115,6 +130,15 @@ EXP K connX(K tcpconn,K pname, K opt){
115130
errStr = getIntFromList(propValues,row,&conn_opts.maxInflightMessages,"maxInflightMessages type incorrect");
116131
else if (strcmp(kS(propNames)[row],"cleanstart")==0)
117132
errStr = getIntFromList(propValues,row,&conn_opts.cleanstart,"cleanstart type incorrect");
133+
else if (strcmp(kS(propNames)[row],"lastWillTopic")==0){
134+
conn_opts.will = &will_opts;
135+
errStr = getStringFromList(propValues,row,&will_opts.topicName,"lastWillTopic type incorrect");}
136+
else if (strcmp(kS(propNames)[row],"lastWillQos")==0)
137+
errStr = getIntFromList(propValues,row,&will_opts.qos,"lastWillQos type incorrect");
138+
else if (strcmp(kS(propNames)[row],"lastWillMessage")==0)
139+
errStr = getCharArrayAsStringFromList(propValues,row,&will_opts.message,"lastWillMessage type incorrect");
140+
else if (strcmp(kS(propNames)[row],"lastWillRetain")==0)
141+
errStr = getIntFromList(propValues,row,&will_opts.retained,"lastWillRetain type incorrect");
118142
else
119143
errStr = "Unsupported conn opt name in dictionary";
120144
}

0 commit comments

Comments
 (0)