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