Commit b13aa8b6 authored by Sebastian Schinzel's avatar Sebastian Schinzel

Ändere echo_server, so dass er auch Anfragen über stdin akzeptiert und...

Ändere echo_server, so dass er auch Anfragen über stdin akzeptiert und Antworten entsprechend auf stdout ausgibt. Das ist die Vorbereitung, um das Fuzzing von Servern zu erlauben.
parent b55e7bf6
......@@ -19,7 +19,7 @@ set(CMAKE_C_FLAGS
# Ausführbare Datei: echo_server
add_executable(echo_server
echo_server.c)
echo_server.c httplib.c httplib.h httplib-test.c)
set_property(TARGET echo_server
PROPERTY C_STANDARD 11)
install(TARGETS echo_server
......
This diff is collapsed.
#include "httplib.h"
void main1() {
const char* src1 = "Hallo ";
const char* src2 = "Welt!";
string* dest = cpy_str(src1, strlen(src1));
dest = str_cat(dest, src2, strlen(src2));
print_string(dest);
free_str(dest);
}
\ No newline at end of file
#include <assert.h>
#include "httplib.h"
string* str_cat(string* dest, const char* src, size_t len) {
printf("TODO!");
return dest;
}
string* new_string(size_t len) {
string* str = calloc(sizeof(string), 1);
if(str == NULL) {
exit(2);
}
str->str = calloc(len, 2);
if(str->str == NULL) {
exit(3);
}
str->len = len * 2;
str->pos = 0;
return str;
}
void print_string(string* str) {
for(int i=0; i < str->pos; i++) {
putchar(str->str[i]);
}
}
string* cpy_str(const char* src, size_t len) {
string* dest = new_string(len);
memcpy(dest->str, src, len);
dest->pos=len-1;
return dest;
}
void free_str(string* str) {
free(str->str);
free(str);
}
size_t get_length(string* str) {
assert(str != NULL);
return str->pos + 1;
}
char* get_char_str(string* str) {
assert(str != NULL);
return str->str;
}
//
// Created by Sebastian Schinzel on 25.03.20.
//
#ifndef ECHO_SERVER_HTTPLIB_H
#define ECHO_SERVER_HTTPLIB_H
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct string {
size_t len;
size_t pos;
char* str;
};
typedef struct string string;
string* str_cat(string* dest, const char* src, size_t len);
string* new_string(size_t );
void print_string(string* str);
string* cpy_str(const char* src, size_t len);
void free_str(string* str);
size_t get_length(string* str);
char* get_char_str(string* str);
#endif //ECHO_SERVER_HTTPLIB_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment