-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.h
98 lines (66 loc) · 1.41 KB
/
utils.h
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "headers.h"
#include "declarations.h"
//Converts an integer to a string.
void itoa(int n,char buff[])
{
int i =0,j;
if(n==0)
{
buff[0] = '0';
buff[1] = '\0';
i=1;
}
while(n>0)
{
int rem = n %10;
n=n/10;
buff[i]=rem+48;
i++;
}
buff[i]='\0';
for(j=0;j<i/2;j++)
{
char temp = buff[j];
buff[j] = buff[i-j-1];
buff[i-j-1] = temp;
}
}
char *extractIpaddress(char *buff,char a,char b)
{
char *ptr = (char *)malloc(20);
int i=0,j=0;
while(buff[i]!=a)
{
i++;
}
i=i+1;
while(buff[i]!=b)
{
ptr[j++]=buff[i];
i++;
}
ptr[j]='\0';
return ptr;
}
int extractNodeno(char * buff)
{
char *nodeno=extractIpaddress(buff,')','[');
return atoi(nodeno);
}
/***
This function decides if a request is a GET request or a PUT request.
- **Parameters**:
- `rec_buff[]`: The received buffer which contains either 'GET' or 'PUT'.
- **Operations**:
- Checks if the first character in `rec_buff` is 'g' or 'G' (for a GET request).
- Returns 1 for GET requests and 0 otherwise.
Code Explanation:
- `if(rec_buff[0] == 'g' || rec_buff[0] == 'G') return 1; else return 0;`: Checks the first character to identify if it's a GET request (returns 1) or PUT request (returns 0).
***/
int getOrPut(char rec_buff[]) //method to check whether put or get request.
{
if(rec_buff[0] == 'g' || rec_buff[0] == 'G')
return 1;
else
return 0;
}