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