@@ -96,7 +96,7 @@ static void myPushCallback(ParseClient client, int error, const char *buffer) {
9696
9797static void saveCurrentDeviceState (ParseClient client , int device_state ) {
9898 char objectJson [1024 ];
99- sprintf (objectJson , "{\"installationId\": \"%s\", \"value\": {\"state\": \"%s\"}, \"alarm\": true, \"ACL\":{ \"%s\": { \"read\": true, \"write\": true}}}" ,
99+ snprintf (objectJson , sizeof ( objectJson ) , "{\"installationId\": \"%s\", \"value\": {\"state\": \"%s\"}, \"alarm\": true, \"ACL\":{ \"%s\": { \"read\": true, \"write\": true}}}" ,
100100 installationObjectId , ledStates [device_state ], userObjectId );
101101 parseSendRequest (client , "POST" , "/1/classes/Event" , objectJson , NULL );
102102}
@@ -127,8 +127,8 @@ static void blinkGetInstallationObjectIdByIdCallback(ParseClient client, int err
127127static void blinkGetInstallationObjectId (ParseClient client )
128128{
129129 if (installationObjectId [0 ] == '\0' ) {
130- char query [60 ];
131- sprintf (query , "where={\"installationId\":\"%s\"}" , parseGetInstallationId (client ));
130+ char query [128 ];
131+ snprintf (query , sizeof ( query ) , "where={\"installationId\":\"%s\"}" , parseGetInstallationId (client ));
132132 parseSendRequest (client , "GET" , "/1/installations" , query , blinkGetInstallationObjectIdByIdCallback );
133133 }
134134}
@@ -172,16 +172,15 @@ static void blinkUpdateInstallation(ParseClient client)
172172 blinkGetModelObjectId (client );
173173 blinkGetUserObjectId (client );
174174
175- char path [40 ] = {0 };
175+ char path [128 ] = {0 };
176176 char objectJson [1024 ] = {0 };
177- sprintf (path , "/1/installations/%s" , installationObjectId );
178- sprintf (objectJson , "{\"deviceName\": \"%s\", \"deviceSubtype\": \"fluffy\", \"model\": {\"__type\":\"Pointer\",\"className\":\"Model\",\"objectId\":\"%s\"}, \"owner\": {\"__type\":\"Pointer\",\"className\":\"_User\",\"objectId\":\"%s\"}}" ,
177+ snprintf (path , sizeof ( path ) , "/1/installations/%s" , installationObjectId );
178+ snprintf (objectJson , sizeof ( objectJson ) , "{\"deviceName\": \"%s\", \"deviceSubtype\": \"fluffy\", \"model\": {\"__type\":\"Pointer\",\"className\":\"Model\",\"objectId\":\"%s\"}, \"owner\": {\"__type\":\"Pointer\",\"className\":\"_User\",\"objectId\":\"%s\"}}" ,
179179 "Raspberry PI blink" , modelObjectId , userObjectId );
180180 parseSendRequest (client , "PUT" , path , objectJson , NULL );
181181 }
182182}
183183
184-
185184int main (int argc , char * argv []) {
186185
187186 ParseClient client = parseInitialize (YOUR_PARSE_APP_ID , YOUR_PARSE_CLIENT_KEY );
@@ -229,8 +228,6 @@ int main(int argc, char *argv[]) {
229228 tv .tv_usec = 0 ;
230229
231230 clock_gettime (CLOCK_MONOTONIC , & current );
232- printf ("=========================================\n" );
233- printf ("current = (%2d, %09d)\n" , current .tv_sec , current .tv_nsec );
234231
235232 if (device_state == STATE_BLINK ) {
236233
0 commit comments