-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProjectManager.c
161 lines (136 loc) · 3.64 KB
/
ProjectManager.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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// client code for UDP socket programming
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#include "login.h"
#include "replace.h"
#include <time.h>
#define IP_PROTOCOL 0
#define IP_ADDRESS "127.0.0.1" // localhost
#define PORT_NO 15050
#define NET_BUF_SIZE 2048
#define cipherKey 'S'
#define sendrecvflag 0
// function to clear buffer
void clearBuf(char* b)
{
int i;
for (i = 0; i < NET_BUF_SIZE; i++)
b[i] = '\0';
}
// function for decryption
char Cipher(char ch)
{
return ch ^ cipherKey;
}
// function to receive file
int recvFile(char* buf, int s)
{
int i;
char ch;
printf("\n");
printf("Status Bug ID Bug Name Date Reported Created By Assigned To\n");
printf("---------------------------------------------------------------------\n");
for (i = 0; i < s; i++) {
ch = buf[i];
ch = Cipher(ch);
if (ch == EOF)
return 1;
else
printf("%c",ch);
}
return 0;
}
// driver code
int main(int argc,char** argv)
{
int sockfd, nBytes;
struct sockaddr_in addr_con;
int addrlen = sizeof(addr_con);
addr_con.sin_family = AF_INET;
addr_con.sin_port = htons(PORT_NO);
addr_con.sin_addr.s_addr = inet_addr(IP_ADDRESS);
char net_buf[NET_BUF_SIZE];
FILE* fp;
//user login
char *res=login();
if(strlen(res)==6){
// socket()
sockfd = socket(AF_INET, SOCK_DGRAM,
IP_PROTOCOL);
if (sockfd < 0)
printf("\nConnection denied\n");
else
{
sendto(sockfd, res, sizeof(res),
sendrecvflag, (struct sockaddr*)&addr_con,
addrlen);
}
if (strcmp(argv[1],"view")==0){
strcpy(net_buf,"null");
sendto(sockfd, net_buf, NET_BUF_SIZE,
sendrecvflag, (struct sockaddr*)&addr_con,
addrlen);
while (1) {
// receive
clearBuf(net_buf);
nBytes = recvfrom(sockfd, net_buf, NET_BUF_SIZE,
sendrecvflag, (struct sockaddr*)&addr_con,
&addrlen);
// process
if (recvFile(net_buf, NET_BUF_SIZE)) {
break;
}
return 0;
}
}
else
{
char var[100];
char bugid[10],devId[10];
FILE* fp;
FILE* fp2;
int cur,len;
char new_str[100];
char* statusUpdate;
char *result;
printf("\nEnter bug id\n");
scanf("%s",bugid);
printf("\nEnter dev id\n");
scanf("%s",devId);
fp=fopen("bugs.txt","r+");
FILE *file;
file=fopen("temp1.txt","a");
while(fgets(var, sizeof(var), fp)!=NULL)
{
len=strlen(var);
if(strstr(var,bugid))
{
strcpy(new_str,var);
statusUpdate=str_replace("new", "assigned", new_str);
result=str_replace("null", devId, statusUpdate);
//printf("%s",result);
fprintf(file,"%s",result);
}
else
{
fprintf(file,"%s",var);
}
}
fclose(file);
fclose(fp);
remove("bugs.txt");
/* Rename temp file as original file */
rename("temp1.txt", "bugs.txt");
}
}
else{
printf("Invalid credentials");
}
return 0;
}