Exemple #1
0
/**
 * Builds a valid response given some content to return
 */
char* getValidResponse(char* content) {
	int length = strlen(content);

	char* response = malloc(sizeof(char) * (512 + length));
	sprintf(response, "HTTP/1.1 200 OK\r\nDate: %s\r\nContent-Type: text/html\r\n"
		"Content-Length: %i\r\n\r\n%s\r\n", getDate(), length, content);

	return shrinkString(response);
}
Exemple #2
0
/**
 * This function builds an error HTTP response from a header and the content of the response.
 */
char* buildErrorResponse(char* header, char* content) {
	int contentLength = strlen(content);
	char* response = malloc(sizeof(char) * 512);
	sprintf(response, "HTTP/1.1 %s\r\n"
		"Date: %s\r\n"
		"Content-Type: text/html\r\n"
		"Content-Length: %i\r\n\r\n"
		"%s\r\n",
		header, getDate(), contentLength, content);
	return shrinkString(response);
}
Exemple #3
0
    bool isMatch(string s, string p) {
        if (shrinkString(s, p)) {
            dividePattern(p);
            int t = sub.size();
            for (int i = 0; i < t; i++) 
                if (!kmp(i, s))
                    return false;
            return true;
        }
		return false;
    }