-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpps-client-find.c
52 lines (40 loc) · 1.12 KB
/
pps-client-find.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "network.h"
#include "client.h"
#include "node.h"
#include "system.h"
int main(int argc, char* argv[])
{
//initialize client
client_t client;
client_init_args_t cl_init;
cl_init.client = &client;
cl_init.argv = &argv;
cl_init.required_args = 2;
cl_init.supported_args = (TOTAL_SERVERS | GET_NEEDED | PUT_NEEDED);
cl_init.argc = argc;
error_code err = client_init(cl_init);
if(err != ERR_NONE) {
printf("FAIL\n");
return -1; // error in main
}
pps_key_t key1 = argv[0];
pps_key_t key2 = argv[1];
pps_value_t value1 = NULL;
pps_value_t value2 = NULL;
error_code res1 = network_get(client, key1, &value1);
error_code res2 = network_get(client, key2, &value2);
if(res1 != ERR_NONE || res2 != ERR_NONE) {
printf("FAIL\n");
return -1;
} else {
char* ptrRes = strstr(value1, value2);
if(ptrRes == NULL) {
printf("OK -1\n");
} else {
ptrdiff_t diff = (ptrRes - value1) / sizeof(char);
printf("OK %td\n", diff);
}
}
client_end(&client);
return 0;
}