f044be7a59001e2edac5da0bb9cc92a094c237fb
[platform/upstream/iotivity.git] / resource / csdk / security / provisioning / sample / cloud / cloudWrapper.c
1 /* *****************************************************************
2  *
3  * Copyright 2016 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * *****************************************************************/
20 #include "logger.h"
21 #include "occloudprovisioning.h"
22 #include "oic_malloc.h"
23 #include "oic_string.h"
24 #include "srmutility.h"
25 #include "aclresource.h"
26 #include "utlist.h"
27
28 #include "utils.h"
29
30 #define TAG "CLOUD-WRAPPER"
31
32 #define MAX_ID_LENGTH       (64)
33 #define MAX_STRING_LENGTH   (256)
34
35 #define UUID_EXAMPLE_1 "9cfbeb8e-5a1e-4d1c-9d01-2ae6fdb"
36 #define UUID_EXAMPLE_2 "123e4567-e89b-12d3-a456-4266554"
37 #define UUID_EXAMPLE_3 "987e6543-e21b-12d3-a456-4266554"
38 #define SUBJECT_ID_EXAMPLE "72616E64-5069-6E44-6576-557569643030"
39
40 #define ACL_ID_EXAMPLE "0f3d9f7fe5491d54077d"
41 #define ACE_ID_EXAMPLE "a0001"
42
43 #define ID_EXAMPLE_1   "78f98b4f25f21e2487e8"
44 #define ID_EXAMPLE_2   "6caa7009386290fd3681"
45
46 #define RESOURCE_URI_EXAMPLE "/a/light/0"
47 #define RESOURCE_TYPE_EXAMPLE "core.light"
48 #define INTERFACE_EXAMPLE "oic.if.baseline"
49
50 //in case of optional parameters absence should be sent NULL
51 #define OPTIONAL(str) (str[0] ? str : NULL)
52
53 /**
54  * Skip special characters from stdin
55  * */
56 static void skipSpecialCharacters()
57 {
58     for( ; 0x20<=getchar(); );  // for removing overflow garbages
59                                 // '0x20<=code' is character region
60 }
61
62 static bool readOptional(const char* description)
63 {
64     if (NULL == description)
65     {
66         return false;
67     }
68
69     printf("Do you want to Enter %s (y/n):\n", description);
70     char choice = 0;
71
72     while(1)
73     {
74         scanf("%c", &choice);
75         skipSpecialCharacters();
76
77         switch (choice)
78         {
79             case 'y': return true;
80             case 'n': return false;
81             default: printf("Wrong value entered. Please press 'y' or 'n'\n");
82         }
83     }
84     return false;
85 }
86
87 void readString(char* item, int length, const char* description, const char* example)
88 {
89     printf("Enter %s (f.e. %s):\n", description, example);
90     char template[8] = { 0 };
91     snprintf(template, sizeof(template), "%%%ds", length - 1);
92     scanf(template, item);
93     skipSpecialCharacters();
94 }
95
96 /**
97  * Read user input (expect string value, but it is optional and can be skipped by user)
98  *
99  * @param[out] item           string item to fill
100  * @param[in] length          max allowed string length
101  * @param[in] description     item description
102  * @param[in] example         item example
103  */
104 static void readOptionalString(char* item, int length, const char* description, const char* example)
105 {
106     if (readOptional(description))
107     {
108         readString(item, length, description, example);
109     }
110 }
111
112 void readInteger(int* item, const char* description, const char* example)
113 {
114     printf("Enter %s (f.e. %s):\n", description, example);
115     scanf("%d", item);
116     skipSpecialCharacters();
117 }
118
119 /**
120  * Read user input (expect array of strings)
121  *
122  * @param[out] list           array of strings structure
123  * @param[in] length          max allowed array item length
124  * @param[in] description     whole array description
125  * @param[in] example         array item example
126  */
127 static void readStringArray(stringArray_t *list, int length, const char* description, const char* example)
128 {
129     int i = 0;
130     int count = 0;
131     char hint[MAX_STRING_LENGTH] = { 0 };
132
133     snprintf(hint, sizeof(hint), "%s items count", description);
134     readInteger(&count, hint, "2");
135
136     char **item = NULL;
137
138     if (0 == count)
139     {
140         return;
141     }
142
143     item = OICCalloc(count, sizeof(char*));
144
145     if (NULL == item)
146     {
147         goto no_memory;
148     }
149
150     for (i = 0; i < count; i++)
151     {
152         item[i] = OICCalloc(length, sizeof(char));
153
154         if (NULL == item[i])
155         {
156             goto no_memory;
157         }
158
159         snprintf(hint, sizeof(hint), "%s %d item", description, i + 1);
160         readString(item[i], length, hint, example);
161     }
162     list->array  = item;
163     list->length = count;
164     return;
165
166 no_memory:
167     //free already allocated memory here
168     for (int k = 0; k < i; k++)
169     {
170         OICFree(item[k]);
171     }
172     OICFree(item);
173 }
174
175 /**
176  * Read user input (expect array of strings)
177  * It is optional and can be skipped by user.
178  *
179  * @param[out] list           array of strings structure
180  * @param[in] length          max allowed array item length
181  * @param[in] description     whole array description
182  * @param[in] example         array item example
183  */
184 static void readOptionalStringArray(stringArray_t *list, int length, const char* description, const char* example)
185 {
186     if (readOptional(description))
187     {
188         readStringArray(list, length, description, example);
189     }
190 }
191
192 void printStringArray(stringArray_t *list)
193 {
194     if (NULL == list)
195     {
196         OIC_LOG(INFO, TAG, "Received NULL list");
197         return;
198     }
199
200     OIC_LOG_V(INFO, TAG, "List contains %zu items", list->length);
201
202     for (size_t i = 0; i < list->length; i++)
203     {
204         OIC_LOG_V(INFO, TAG, "item[%zu] = %s", i, list->array[i]);
205     }
206 }
207
208 void printInviteResponse(inviteResponse_t *in)
209 {
210     if (NULL == in)
211     {
212         OIC_LOG(INFO, TAG, "Received NULL invitation response");
213         return;
214     }
215
216     OIC_LOG(INFO, TAG, "Received next invite gid list:");
217     printStringArray(&in->invite.gidlist);
218
219     OIC_LOG(INFO, TAG, "Received next invite mid list:");
220     printStringArray(&in->invite.midlist);
221
222     OIC_LOG(INFO, TAG, "Received next invited gid list:");
223     printStringArray(&in->invited.gidlist);
224
225     OIC_LOG(INFO, TAG, "Received next invited mid list:");
226     printStringArray(&in->invited.midlist);
227 }
228
229 void clearInviteResponse(inviteResponse_t *in)
230 {
231     if (NULL == in)
232     {
233         return;
234     }
235
236     clearStringArray(&in->invite.gidlist);
237     clearStringArray(&in->invite.midlist);
238
239     clearStringArray(&in->invited.gidlist);
240     clearStringArray(&in->invited.midlist);
241 }
242
243 bool readFile(const char *name, OCByteString *out)
244 {
245     FILE *file = NULL;
246     int length = 0;
247     uint8_t *buffer = NULL;
248     bool result = false;
249
250     //Open file
251     file = fopen(name, "rb");
252     if (!file)
253     {
254         OIC_LOG_V(ERROR, TAG, "Unable to open file %s", name);
255         return result;
256     }
257
258     //Get file length
259     if (fseek(file, 0, SEEK_END))
260     {
261         OIC_LOG(ERROR, TAG, "Failed to SEEK_END");
262         goto exit;
263     }
264
265     length = ftell(file);
266     if (length < 0)
267     {
268         OIC_LOG(ERROR, TAG, "Failed to ftell");
269         goto exit;
270     }
271
272     if (fseek(file, 0, SEEK_SET))
273     {
274         OIC_LOG(ERROR, TAG, "Failed to SEEK_SET");
275         goto exit;
276     }
277
278     //Allocate memory
279     buffer = (uint8_t *)malloc(length);
280     if (!buffer)
281     {
282         OIC_LOG(ERROR, TAG, "Failed to allocate buffer");
283         goto exit;
284     }
285
286     //Read file contents into buffer
287     size_t count = 1;
288     size_t realCount = fread(buffer, length, count, file);
289     if (realCount != count)
290     {
291         OIC_LOG_V(ERROR, TAG, "Read %d bytes %zu times instead of %zu", length, realCount, count);
292         goto exit;
293     }
294
295     out->bytes = buffer;
296     out->len   = length;
297
298     result = true;
299 exit:
300     fclose(file);
301     return result;
302 }
303
304 /**
305  * Frees particular cloudAce object
306  *
307  * @param[in] ace   ace object to free
308  * */
309 static void freeCloudAce(cloudAce_t *ace)
310 {
311     OICFree(ace->aceId);
312
313     //Clean Resources
314     OicSecRsrc_t* rsrc = NULL;
315     OicSecRsrc_t* tmpRsrc = NULL;
316     LL_FOREACH_SAFE(ace->resources, rsrc, tmpRsrc)
317     {
318         LL_DELETE(ace->resources, rsrc);
319         FreeRsrc(rsrc);
320     }
321
322     OICFree(ace);
323 }
324
325 /**
326  * Deletes cloudAce list
327  *
328  * @param[in] ace   aces list to delete
329  * */
330 static void deleteCloudAceList(cloudAce_t *aces)
331 {
332     cloudAce_t *ace = NULL;
333     cloudAce_t *tmpAce = NULL;
334     LL_FOREACH_SAFE(aces, ace, tmpAce)
335     {
336         LL_DELETE(aces, ace);
337         freeCloudAce(ace);
338     }
339 }
340
341 OCStackResult OCWrapperCertificateIssueRequest(const OCDevAddr *endPoint, OCCloudResponseCB callback)
342 {
343     return OCCloudCertificateIssueRequest(NULL, endPoint, callback);
344 }
345
346 OCStackResult OCWrapperGetCRL(const OCDevAddr *endPoint, OCCloudResponseCB callback)
347 {
348     return OCCloudGetCRL(NULL, endPoint, callback);
349 }
350
351 OCStackResult OCWrapperPostCRL(const OCDevAddr *endPoint, OCCloudResponseCB callback)
352 {
353     OCStackResult result = OC_STACK_ERROR;
354     OCByteString crlData = {0, 0};
355     char filename[64] = {0};
356     char thisUpdate[16] = { 0 };
357     char nextUpdate[16] = { 0 };
358     stringArray_t serialNumbers = {0, 0};
359
360     readString(thisUpdate, sizeof(thisUpdate), "Crl's thisUpdate value", "20160727000000");
361     readString(nextUpdate, sizeof(nextUpdate), "Crl's nextUpdate value", "20161027000000");
362     readOptionalStringArray(&serialNumbers, 16, "Revoked serial numbers", "1234");
363
364     if (NULL == serialNumbers.array)
365     {
366         readString(filename, sizeof(filename),
367                    "filename from which binary Crl in DER format will be read", "crl");
368
369         if (!readFile(filename, &crlData))
370         {
371             printf("Can't read crl from file %s\n", filename);
372             goto exit;
373         }
374     }
375     stringArray_t *rcsn = serialNumbers.array? &serialNumbers : NULL;
376     OCByteString *crl = crlData.bytes? &crlData : NULL;
377
378     result = OCCloudPostCRL(NULL, thisUpdate, nextUpdate, crl, rcsn,
379                             endPoint, callback);
380 exit:
381     clearStringArray(&serialNumbers);
382     OICFree(crlData.bytes);
383
384     return result;
385 }
386
387 OCStackResult OCWrapperAclIdGetByDevice(const OCDevAddr *endPoint, OCCloudResponseCB callback)
388 {
389     char di[MAX_ID_LENGTH] = { 0 };
390
391     readString(di, sizeof(di), "device id", UUID_EXAMPLE_1);
392
393     return OCCloudGetAclIdByDevice(NULL, di, endPoint, callback);
394 }
395
396 OCStackResult OCWrapperAclIdCreate(const OCDevAddr *endPoint, OCCloudResponseCB callback)
397 {
398     char oid[MAX_ID_LENGTH]  = { 0 };
399     char di[MAX_ID_LENGTH]   = { 0 };
400
401     readString(oid, sizeof(oid), "owner id", UUID_EXAMPLE_2);
402     readString(di, sizeof(di), "device id", UUID_EXAMPLE_1);
403
404     return OCCloudAclIdCreate(NULL, oid, di, endPoint, callback);
405 }
406
407 OCStackResult OCWrapperAclIdDelete(const OCDevAddr *endPoint, OCCloudResponseCB callback)
408 {
409     char aclid[MAX_ID_LENGTH] = { 0 };
410
411     readString(aclid, sizeof(aclid), "acl id", ACL_ID_EXAMPLE);
412
413     return OCCloudAclIdDelete(NULL, aclid, endPoint, callback);
414 }
415
416 OCStackResult OCWrapperAclIndividualGetInfo(const OCDevAddr *endPoint, OCCloudResponseCB callback)
417 {
418     char aclid[MAX_ID_LENGTH] = { 0 };
419
420     readString(aclid, sizeof(aclid), "acl id", ACL_ID_EXAMPLE);
421
422     return OCCloudAclIndividualGetInfo(NULL, aclid, endPoint, callback);
423 }
424
425 OCStackResult OCWrapperAclIndividualUpdateAce(const OCDevAddr *endPoint, OCCloudResponseCB callback)
426 {
427     OCStackResult result = OC_STACK_NO_MEMORY;
428
429     char aclid[MAX_ID_LENGTH] = { 0 };
430     readString(aclid, sizeof(aclid), "acl id", ACL_ID_EXAMPLE);
431
432     int acllist_count = 0;
433     readInteger(&acllist_count, "acl list count", "1");
434
435     cloudAce_t *aces = NULL;
436
437     for (int i = 0; i < acllist_count; i++)
438     {
439         cloudAce_t *ace = OICCalloc(1, sizeof(cloudAce_t));
440         if (!ace)
441         {
442             OIC_LOG(ERROR, TAG, "Can't allocate memory for ace");
443             goto exit;
444         }
445         LL_APPEND(aces, ace);
446
447         char aceid[MAX_ID_LENGTH] = { 0 };
448         char subjectuuid[MAX_ID_LENGTH] = { 0 };
449         int stype = 0;
450         int permission = 0;
451
452         do
453         {
454             readString(subjectuuid, sizeof(subjectuuid), "subjectuuid", SUBJECT_ID_EXAMPLE);
455         } while (OC_STACK_OK != ConvertStrToUuid(subjectuuid, &ace->subjectuuid));
456
457         readInteger(&stype, "subject type", "0 â€“ Device, 1 â€“ User, 2 - Group");
458         readInteger(&permission, "permission", "6");
459
460         ace->aceId = OICStrdup(aceid);
461         ace->stype = stype;
462         ace->permission = permission;
463
464         int reslist_count = 0;
465         readInteger(&reslist_count, "resources list count", "1");
466
467         for (int i = 0; i < reslist_count; i++)
468         {
469             OicSecRsrc_t *res = OICCalloc(1, sizeof(OicSecRsrc_t));
470             if (!res)
471             {
472                 OIC_LOG(ERROR, TAG, "Can't allocate memory for res");
473                 goto exit;
474             }
475             LL_APPEND(ace->resources, res);
476
477             char href[32] = { 0 };
478             readString(href, sizeof(href), "href", RESOURCE_URI_EXAMPLE);
479
480             stringArray_t rt = {0, 0};
481             readStringArray(&rt, MAX_ID_LENGTH, "resource type", RESOURCE_TYPE_EXAMPLE);
482
483             stringArray_t _if = {0, 0};
484             readStringArray(&_if, MAX_ID_LENGTH, "interface", INTERFACE_EXAMPLE);
485
486             res->href = OICStrdup(href);
487             res->types = rt.array;
488             res->typeLen = rt.length;
489             res->interfaces = _if.array;
490             res->interfaceLen = _if.length;
491         }
492     }
493
494     result = OCCloudAclIndividualUpdateAce(NULL, aclid, aces, endPoint, callback);
495 exit:
496     deleteCloudAceList(aces);
497     return result;
498 }
499
500 OCStackResult OCWrapperAclIndividualUpdate(const OCDevAddr *endPoint, OCCloudResponseCB callback)
501 {
502     OCStackResult result = OC_STACK_NO_MEMORY;
503
504     char aclid[MAX_ID_LENGTH] = { 0 };
505     readString(aclid, sizeof(aclid), "acl id", ACL_ID_EXAMPLE);
506
507     cloudAce_t *ace = OICCalloc(1, sizeof(cloudAce_t));
508     if (!ace)
509     {
510         OIC_LOG(ERROR, TAG, "Can't allocate memory for ace");
511         goto exit;
512     }
513
514     char aceid[MAX_ID_LENGTH] = { 0 };
515     char subjectuuid[MAX_ID_LENGTH] = { 0 };
516     int stype = 0;
517     int permission = 0;
518
519     readString(aceid, sizeof(aceid), "ace id", ACE_ID_EXAMPLE);
520     do
521     {
522         readString(subjectuuid, sizeof(subjectuuid), "subjectuuid", SUBJECT_ID_EXAMPLE);
523     } while (OC_STACK_OK != ConvertStrToUuid(subjectuuid, &ace->subjectuuid));
524
525     readInteger(&stype, "subject type", "0 â€“ Device, 1 â€“ User, 2 - Group");
526     readInteger(&permission, "permission", "6");
527
528     ace->stype = stype;
529     ace->permission = permission;
530
531     int reslist_count = 0;
532     readInteger(&reslist_count, "resources list count", "1");
533
534     for (int i = 0; i < reslist_count; i++)
535     {
536         OicSecRsrc_t *res = OICCalloc(1, sizeof(OicSecRsrc_t));
537         if (!res)
538         {
539             OIC_LOG(ERROR, TAG, "Can't allocate memory for res");
540             goto exit;
541         }
542         LL_APPEND(ace->resources, res);
543
544         char href[32] = { 0 };
545         readString(href, sizeof(href), "href", RESOURCE_URI_EXAMPLE);
546
547         stringArray_t rt = {0, 0};
548         readStringArray(&rt, MAX_ID_LENGTH, "resource type", RESOURCE_TYPE_EXAMPLE);
549
550         stringArray_t _if = {0, 0};
551         readStringArray(&_if, MAX_ID_LENGTH, "interface", INTERFACE_EXAMPLE);
552
553         res->href = OICStrdup(href);
554         res->types = rt.array;
555         res->typeLen = rt.length;
556         res->interfaces = _if.array;
557         res->interfaceLen = _if.length;
558     }
559
560
561     result = OCCloudAclIndividualUpdate(NULL, aclid,aceid, ace, endPoint, callback);
562 exit:
563     return result;
564 }
565
566 OCStackResult OCWrapperAclIndividualDelete(const OCDevAddr *endPoint, OCCloudResponseCB callback)
567 {
568     char aclid[MAX_ID_LENGTH] = { 0 };
569
570     readString(aclid, sizeof(aclid), "acl id", ACL_ID_EXAMPLE);
571
572     return OCCloudAclIndividualDelete(NULL, aclid, endPoint, callback);
573 }
574
575 OCStackResult OCWrapperAclIndividualDeleteAce(const OCDevAddr *endPoint, OCCloudResponseCB callback)
576 {
577     char aclid[MAX_ID_LENGTH] = { 0 };
578     char aceid[MAX_ID_LENGTH] = { 0 };
579
580     readString(aclid, sizeof(aclid), "acl id", ACL_ID_EXAMPLE);
581     readString(aceid, sizeof(aceid), "ace id", ACE_ID_EXAMPLE);
582
583     return OCCloudAclIndividualDeleteAce(NULL, aclid, aceid, endPoint, callback);
584 }
585
586 OCStackResult OCWrapperAclCreateGroup(const OCDevAddr *endPoint, OCCloudResponseCB callback)
587 {
588     char gtype[16] = { 0 };
589     char gmid[MAX_ID_LENGTH] = { 0 };
590
591     readString(gtype, sizeof(gtype), "Group type value", "Public");
592     readOptionalString(gmid, sizeof(gmid), "group member id value", UUID_EXAMPLE_2);
593
594     return OCCloudAclCreateGroup(NULL, gtype, OPTIONAL(gmid), endPoint, callback);
595 }
596
597 OCStackResult OCWrapperAclFindMyGroup(const OCDevAddr *endPoint, OCCloudResponseCB callback)
598 {
599     char mid[MAX_ID_LENGTH]  = { 0 };
600
601     readOptionalString(mid, sizeof(mid), "member id value", UUID_EXAMPLE_2);
602
603     return OCCloudAclFindMyGroup(NULL, OPTIONAL(mid), endPoint, callback);
604 }
605
606 OCStackResult OCWrapperAclDeleteGroup(const OCDevAddr *endPoint, OCCloudResponseCB callback)
607 {
608     char gid[MAX_ID_LENGTH]  = { 0 };
609     char gmid[MAX_ID_LENGTH] = { 0 };
610
611     readString(gid, sizeof(gid), "Group id value", ID_EXAMPLE_1);
612
613     readOptionalString(gmid, sizeof(gmid), "group member id value", UUID_EXAMPLE_2);
614
615     return OCCloudAclDeleteGroup(NULL, gid, OPTIONAL(gmid), endPoint, callback);
616 }
617
618 OCStackResult OCWrapperAclJoinToInvitedGroup(const OCDevAddr *endPoint, OCCloudResponseCB callback)
619 {
620     char gid[MAX_ID_LENGTH]  = { 0 };
621
622     readString(gid, sizeof(gid), "Group id value", ID_EXAMPLE_1);
623
624     return OCCloudAclJoinToInvitedGroup(NULL, gid, endPoint, callback);
625 }
626
627 OCStackResult OCWrapperAclObserveGroup(const OCDevAddr *endPoint, OCCloudResponseCB callback)
628 {
629     char gid[MAX_ID_LENGTH]  = { 0 };
630
631     readString(gid, sizeof(gid), "Group id value", ID_EXAMPLE_1);
632
633     return OCCloudAclObserveGroup(NULL, gid, endPoint, callback);
634 }
635
636 OCStackResult OCWrapperAclShareDeviceIntoGroup(const OCDevAddr *endPoint, OCCloudResponseCB callback)
637 {
638     OCStackResult result = OC_STACK_NO_MEMORY;
639     char gid[MAX_ID_LENGTH]  = { 0 };
640     stringArray_t midlist = {0,0};
641     stringArray_t dilist = {0,0};
642
643     readString(gid, sizeof(gid), "Group id value", ID_EXAMPLE_1);
644
645     readStringArray(&midlist, MAX_ID_LENGTH, "member id list", UUID_EXAMPLE_2);
646
647     readStringArray(&dilist, MAX_ID_LENGTH, "device list", UUID_EXAMPLE_1);
648
649     result = OCCloudAclShareDeviceIntoGroup(NULL, gid, &midlist, &dilist, endPoint, callback);
650
651     clearStringArray(&midlist);
652     clearStringArray(&dilist);
653
654     return result;
655 }
656
657 OCStackResult OCWrapperAclDeleteDeviceFromGroup(const OCDevAddr *endPoint, OCCloudResponseCB callback)
658 {
659     OCStackResult result = OC_STACK_NO_MEMORY;
660     char gid[MAX_ID_LENGTH]  = { 0 };
661     stringArray_t midlist = {0,0};
662     stringArray_t dilist = {0,0};
663
664     readString(gid, sizeof(gid), "Group id value", ID_EXAMPLE_1);
665
666     readStringArray(&midlist, MAX_ID_LENGTH, "member id list", UUID_EXAMPLE_2);
667
668     readStringArray(&dilist, MAX_ID_LENGTH, "device list", UUID_EXAMPLE_1);
669
670     result = OCCloudAclDeleteDeviceFromGroup(NULL, gid, &midlist, &dilist, endPoint, callback);
671
672     clearStringArray(&midlist);
673     clearStringArray(&dilist);
674
675     return result;
676 }
677
678 OCStackResult OCWrapperAclGroupGetInfo(const OCDevAddr *endPoint, OCCloudResponseCB callback)
679 {
680     char gid[MAX_ID_LENGTH]  = { 0 };
681     char mid[MAX_ID_LENGTH]  = { 0 };
682
683     readString(gid, sizeof(gid), "Group id value", ID_EXAMPLE_1);
684
685     readOptionalString(mid, sizeof(mid), "member id value", UUID_EXAMPLE_2);
686
687     return OCCloudAclGroupGetInfo(NULL, gid, OPTIONAL(mid), endPoint, callback);
688 }
689
690 OCStackResult OCWrapperAclInviteUser(const OCDevAddr *endPoint, OCCloudResponseCB callback)
691 {
692     OCStackResult result = OC_STACK_NO_MEMORY;
693     char uid[MAX_ID_LENGTH]  = { 0 };
694     stringArray_t midlist = {0,0};
695     stringArray_t gidlist = {0,0};
696
697     readOptionalString(uid, sizeof(uid), "user id value", UUID_EXAMPLE_2);
698
699     readStringArray(&gidlist, MAX_ID_LENGTH, "group id list", UUID_EXAMPLE_1);
700
701     readStringArray(&midlist, MAX_ID_LENGTH, "member id list", UUID_EXAMPLE_2);
702
703     result = OCCloudAclInviteUser(NULL, OPTIONAL(uid), &gidlist, &midlist, endPoint, callback);
704
705     clearStringArray(&midlist);
706     clearStringArray(&gidlist);
707
708     return result;
709 }
710
711 OCStackResult OCWrapperAclGetInvitation(const OCDevAddr *endPoint, OCCloudResponseCB callback)
712 {
713     char uid[MAX_ID_LENGTH]  = { 0 };
714
715     readOptionalString(uid, sizeof(uid), "user uuid value", UUID_EXAMPLE_2);
716
717     return OCCloudAclGetInvitation(NULL, OPTIONAL(uid), endPoint, callback);
718 }
719
720 OCStackResult OCWrapperAclDeleteInvitation(const OCDevAddr *endPoint, OCCloudResponseCB callback)
721 {
722     char uid[MAX_ID_LENGTH]  = { 0 };
723     char gid[MAX_ID_LENGTH]  = { 0 };
724
725     readOptionalString(uid, sizeof(uid), "user uuid value", UUID_EXAMPLE_2);
726     readString(gid, sizeof(gid), "Group id value", ID_EXAMPLE_1);
727
728     return OCCloudAclDeleteInvitation(NULL, OPTIONAL(uid), gid, endPoint, callback);
729 }
730
731 OCStackResult OCWrapperAclCancelInvitation(const OCDevAddr *endPoint, OCCloudResponseCB callback)
732 {
733     char uid[MAX_ID_LENGTH]  = { 0 };
734     char gid[MAX_ID_LENGTH]  = { 0 };
735     char mid[MAX_ID_LENGTH]  = { 0 };
736
737     readOptionalString(uid, sizeof(uid), "user uuid value", UUID_EXAMPLE_2);
738
739     readString(gid, sizeof(gid), "Group id value", ID_EXAMPLE_1);
740     readString(mid, sizeof(mid), "member id value", ID_EXAMPLE_1);
741
742     return OCCloudAclCancelInvitation(NULL, OPTIONAL(uid), gid, mid, endPoint, callback);
743 }
744
745 OCStackResult OCWrapperAclPolicyCheck(const OCDevAddr *endPoint, OCCloudResponseCB callback)
746 {
747     char sid[MAX_ID_LENGTH] = { 0 };
748     char di[MAX_ID_LENGTH]  = { 0 };
749     char rm[16]  = { 0 };
750     char user_uri[32] = { 0 };
751
752     readString(sid, sizeof(sid), "subject id", UUID_EXAMPLE_1);
753     readString(di, sizeof(di), "device id", UUID_EXAMPLE_2);
754     readString(rm, sizeof(rm), "request method", "GET or POST or DELETE");
755     readString(user_uri, sizeof(user_uri), "request uri", RESOURCE_URI_EXAMPLE);
756
757     return OCCloudAclPolicyCheck(NULL, sid, di, rm, user_uri, endPoint, callback);
758 }