Skip to content

Commit bcca419

Browse files
authored
Add files via upload
log file added
1 parent 98b63f3 commit bcca419

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

hidalgo/config.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#define CHUNK 50
2+
#define HTTP_conf "conf/http.conf"
23

34
int get_http_(char match){
45

@@ -7,12 +8,12 @@ int get_http_(char match){
78
size_t len;
89
int xport;
910

10-
http_port_fd = fopen("conf/http.conf", "r");
11+
http_port_fd = fopen(HTTP_conf, "r");
1112
if (http_port_fd) {
1213
while ((read = getline(&line, &len, http_port_fd)) != -1){
1314
if(line[0] != '$'){
1415
if(line[0] == match){
15-
xport = get_integerFs(line);
16+
xport = get_integerFs(line, 0, 0);
1617
printf("SET :: %s", line);
1718
return xport;
1819
}
@@ -25,9 +26,7 @@ int get_http_(char match){
2526
fclose(http_port_fd);
2627
}
2728
}
28-
int get_integerFs(char *line){
29-
int num=0;
30-
int count=0;
29+
int get_integerFs(char *line, int num, int count){
3130
int i=0;
3231

3332
while (sscanf(line, "%*[^0-9]%d%n", &num, &i)==1){

hidalgo/hidalga.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@
66
#include<sys/types.h>
77
#include<unistd.h>
88
#include<string.h>
9+
#include<stdbool.h>
910

11+
#define Hid_Port 'P'
12+
#define Hid_IP 'I'

hidalgo/httpserver.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#include "hidalga.h"
22
#include "config.c"
3-
//Hidalga Server Socket MainStream
3+
#include "log_generator.c"
4+
//Hidalgo Server Socket MainStream
45
//(c) - 2018 | ALL RIGHT RESERVED
56

67
int main() {
7-
int port = get_http_('P');
8-
int ip = get_http_('I');
8+
int port = get_http_(Hid_Port);
9+
int ip = get_http_(Hid_IP);
910
int create_socket, new_socket;
1011
socklen_t addrlen;
1112
int bufsize = 1024;
@@ -51,7 +52,9 @@ int main() {
5152
}
5253

5354
recv(new_socket, buffer, bufsize, 0);
54-
printf("%s\n", buffer);
55+
//printf("%s\n", buffer);
56+
if(guest_logs(buffer)) printf("\nLogs Saved\n");
57+
else printf("\nLog Writing Err :: log_generator.c\n");
5558
write(new_socket, page, strlen(page));
5659
close(new_socket);
5760
}

hidalgo/log_generator.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
bool guest_logs(char *data){
2+
bool val = false;
3+
FILE *guest_log;
4+
guest_log = fopen("visitors.log", "a");
5+
6+
if(guest_log){
7+
puts(data);
8+
fwrite(data, sizeof(char), sizeof(data), guest_log);
9+
return (val=true);
10+
}
11+
else return val;
12+
}

0 commit comments

Comments
 (0)