]> git.sur5r.net Git - ngadmin/blob - lib/src/mirror.c
daa7f471632733ced114065179b889374b609535
[ngadmin] / lib / src / mirror.c
1
2 #include <ngadmin.h>
3
4 #include <nsdp/attr.h>
5 #include <nsdp/protocol.h>
6
7 #include "lib.h"
8 #include "network.h"
9
10
11 int ngadmin_getMirror (struct ngadmin *nga, char *ports)
12 {
13         List *attr;
14         struct attr *at;
15         int ret = ERR_OK;
16         
17         
18         if (nga == NULL || ports == NULL)
19                 return ERR_INVARG;
20         else if (nga->current == NULL)
21                 return ERR_NOTLOG;
22         
23         
24         attr = createEmptyList();
25         pushBackList(attr, newEmptyAttr(ATTR_MIRROR));
26         ret = readRequest(nga, attr);
27         if (ret < 0)
28                 goto end;
29         
30         filterAttributes(attr, ATTR_MIRROR, ATTR_END);
31         
32         memset(ports, 0, 1 + nga->current->ports);
33         
34         if (attr->first != NULL) {
35                 at = attr->first->data;
36                 memcpy(ports, at->data, 1 + nga->current->ports);
37         }
38         
39         
40 end:
41         destroyList(attr, (void(*)(void*))freeAttr);
42         
43         
44         return ret;
45 }
46
47
48 int ngadmin_setMirror (struct ngadmin *nga, const char *ports)
49 {
50         List *attr;
51         char *p;
52         struct swi_attr *sa;
53         
54         
55         if (nga == NULL)
56                 return ERR_INVARG;
57         
58         sa = nga->current;
59         if (sa == NULL)
60                 return ERR_NOTLOG;
61         
62         
63         p = malloc(1 + sa->ports);
64         if (p == NULL)
65                 return ERR_MEM;
66         
67         if (ports == NULL)
68                 memset(p, 0, 1 + sa->ports);
69         else
70                 memcpy(p, ports, 1 + sa->ports);
71         
72         attr = createEmptyList();
73         pushBackList(attr, newAttr(ATTR_MIRROR, 1 + sa->ports, p));
74         
75         
76         return writeRequest(nga, attr);
77 }
78