Skip to content

Commit bee5e6c

Browse files
authored
Add files via upload
Under construction
1 parent 4e79005 commit bee5e6c

File tree

5 files changed

+134
-0
lines changed

5 files changed

+134
-0
lines changed

hidalgo/conf/http.conf

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
$ ===================================================== $
2+
$ Welcome to Hidalgo Server Configuration $
3+
$ '$' represent comment in hidalgo Configuration files $
4+
$ $
5+
$ # # # #### # # ##### ##### | @------@ $
6+
$ # # # # ## # # # # # # | | | | | $
7+
$ #### # # # # # # # ## # # | | +--+ | $
8+
$ # # # # ## ##### # # # # # | | | | | $
9+
$ # # # #### # # ##### ##### ##### | @------@ $
10+
$ $
11+
$ Hidalga is Multi-threaded Server build on Unix-C. $
12+
$ Server useing TCP/IP and Network Programming $
13+
$ This Configuration file contain GET, HEAD, POST conf $
14+
$ Supporting Html, Css, js and much more.. $
15+
$ ===================================================== $
16+
17+
$ IP Address is used to identify the Host PC.
18+
$ e.g IP:xxx.xxx.xxx.xxx
19+
20+
IP:127.0.0.1
21+
22+
$ Port Number is used to identify the Running Service.
23+
$ (NOTE :: only less then or equal 4 digit for Port)
24+
$ e.g PORT:xxxx
25+
26+
PORT:1500
27+

hidalgo/config.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#define CHUNK 50
2+
3+
int get_http_(char match){
4+
5+
char port[CHUNK], read, *line=NULL;
6+
FILE *http_port_fd;
7+
size_t len;
8+
int xport;
9+
10+
http_port_fd = fopen("conf/http.conf", "r");
11+
if (http_port_fd) {
12+
while ((read = getline(&line, &len, http_port_fd)) != -1){
13+
if(line[0] != '$'){
14+
if(line[0] == match){
15+
xport = get_integerFs(line);
16+
printf("SET :: %s", line);
17+
return xport;
18+
}
19+
}
20+
}
21+
22+
if (ferror(http_port_fd)){
23+
printf("\n$ Configuration file error\n");
24+
}
25+
fclose(http_port_fd);
26+
}
27+
}
28+
int get_integerFs(char *line){
29+
int num=0;
30+
int count=0;
31+
int i=0;
32+
33+
while (sscanf(line, "%*[^0-9]%d%n", &num, &i)==1){
34+
line+=i;
35+
count++;
36+
}
37+
return num;
38+
}

hidalgo/hidalga.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include<netinet/in.h>
2+
#include<stdio.h>
3+
#include<stdlib.h>
4+
#include<sys/socket.h>
5+
#include<sys/stat.h>
6+
#include<sys/types.h>
7+
#include<unistd.h>
8+
#include<string.h>
9+

hidalgo/httpserver

13.5 KB
Binary file not shown.

hidalgo/httpserver.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include "hidalga.h"
2+
#include "config.c"
3+
//Hidalga Server Socket MainStream
4+
//(c) - 2018 | ALL RIGHT RESERVED
5+
6+
int main() {
7+
int port = get_http_('P');
8+
int ip = get_http_('I');
9+
int create_socket, new_socket;
10+
socklen_t addrlen;
11+
int bufsize = 1024;
12+
char *buffer = malloc(bufsize);
13+
struct sockaddr_in address;
14+
static char* page =
15+
"HTTP/1.1 200 OK\n"
16+
"Content-type: text/html\n"
17+
"\n"
18+
"<html>\n"
19+
" <body>\n"
20+
" <h1>WebPAge</h1>\n"
21+
" <p>The requested URL was <?php echo'disk'; ?> on this server.</p>\n"
22+
" </body>\n"
23+
"</html>\n";
24+
25+
if ((create_socket = socket(AF_INET, SOCK_STREAM, 0)) > 0){
26+
printf("The socket was created\n");
27+
}
28+
29+
address.sin_family = AF_INET;
30+
address.sin_addr.s_addr = INADDR_ANY;
31+
address.sin_port = htons(port);
32+
33+
if (bind(create_socket, (struct sockaddr *) &address, sizeof(address)) == 0){
34+
printf("Binding Socket\n");
35+
}
36+
37+
38+
while (1) {
39+
if (listen(create_socket, 10) < 0) {
40+
perror("server: listen");
41+
exit(1);
42+
}
43+
44+
if ((new_socket = accept(create_socket, (struct sockaddr *) &address, &addrlen)) < 0) {
45+
perror("server: accept");
46+
exit(1);
47+
}
48+
49+
if (new_socket > 0){
50+
printf("The Client is connected...\n");
51+
}
52+
53+
recv(new_socket, buffer, bufsize, 0);
54+
printf("%s\n", buffer);
55+
write(new_socket, page, strlen(page));
56+
close(new_socket);
57+
}
58+
close(create_socket);
59+
return 0;
60+
}

0 commit comments

Comments
 (0)