aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server.c25
-rw-r--r--util.c9
-rw-r--r--util.h1
3 files changed, 31 insertions, 4 deletions
diff --git a/server.c b/server.c
index 8d04c1c..da503ab 100644
--- a/server.c
+++ b/server.c
@@ -60,21 +60,38 @@ void handler_refuseConnections(int signum) {
int main(int argc, char* argv[]) {
/*
+ * Get server parameters
+ */
+
+ sds host = sdsnew("127.0.0.1");
+ sds port = sdsnew("8080");
+
+ int argvOffset = 1;
+ if (charCount(argv[1], ',') == 1) {
+ argvOffset++;
+ char* sep = strchr(argv[1], ',');
+ sdsfree(host);
+ host = sdsnewlen(argv[1], sep - argv[1]);
+ sdsfree(port);
+ port = sdsnew(sep + 1);
+ }
+
+ /*
* Get hosts
*/
- int vhostsc = argc - 1;
+ int vhostsc = argc - argvOffset;
sds **vhosts = malloc(vhostsc * sizeof(sds*));
for (int i = 0, temp = 0; i < vhostsc; i++) {
- vhosts[i] = sdssplitlen(argv[i+1], strlen(argv[i+1]), ",", 1, &temp);
+ vhosts[i] = sdssplitlen(argv[i+argvOffset], strlen(argv[i+argvOffset]), ",", 1, &temp);
}
/*
* Create socket for accepting connections
*/
- int fd_socket = createCommunicationSocket("127.0.0.1", "8080");
- printf("Listening on %s:%s\n", "127.0.0.1", "8080");
+ int fd_socket = createCommunicationSocket(host, port);
+ printf("Listening on %s:%s\n", host, port);
/*
* Server command-line interface
diff --git a/util.c b/util.c
index 5f847fa..822a4d2 100644
--- a/util.c
+++ b/util.c
@@ -169,3 +169,12 @@ int isNumber(char* str) {
}
return 1;
}
+
+int charCount(char* str, char cmp) {
+ int count = 0;
+ while (*str != '\0') {
+ count += *str == cmp;
+ str++;
+ }
+ return count;
+}
diff --git a/util.h b/util.h
index e632578..b2836eb 100644
--- a/util.h
+++ b/util.h
@@ -24,5 +24,6 @@ int digits(int num);
int streq(const char* first, const char* second);
void shiftLeft(char* str, size_t size, size_t shift);
int isNumber(char* str);
+int charCount(char* str, char cmp);
#endif