Beispiel #1
0
ERROR_CODE log_http_request(char *host, char *identity, char *user, char *method, char *uri, enum http_version_e version, int error_code, size_t content_length) {
    /* allocates space for the buffer to hild the date and time
    information to be logged */
    char date_buffer[1024];

    /* allocates space for the internal date structures to be used
    for the retrieval of the time information and retrieves the
    current time to be used converting it then to the local time*/
    struct tm *_local_time;
    time_t _time = time(NULL);
    LOCAL_TIME(_local_time, &_time);

    /* checks if the converted local time is invalid and in case it
    is raises the apropriate runtime error to be caught */
    if(_local_time == NULL) {
        RAISE_ERROR_M(
            RUNTIME_EXCEPTION_ERROR_CODE,
            (unsigned char *) "Problem retrieving local time"
        );
    }

    /* formats the local time into the data buffer and then uses it and
    the other (sent) variables to format the output buffer */
    strftime(date_buffer, 1024, "%d/%b/%Y %H:%M:%S", _local_time);
    PRINTF_F(
        "%s %s %s [%s] \"%s %s %s\" %d %lu\n",
        host,
        identity,
        user,
        date_buffer,
        method,
        uri,
        http_version_codes[version - 1],
        error_code,
        (long unsigned int) content_length
    );

    /* raises no error */
    RAISE_NO_ERROR;
}
Beispiel #2
0
ERROR_CODE print_type(struct type_t *type) {
    /* allocates space for the current type for the
    type to handler the key values for map for the
    possible iterator, for the hash map element and
    for the is first (loop) flag */
    struct type_t *current;
    struct type_t key;
    struct iterator_t *iterator;
    struct hash_map_element_t *element;
    unsigned char is_first = 1;

    /* switches over the type's type in order to
    execute the proper print operation */
    switch(type->type) {
        case INTEGER_TYPE:
            PRINTF_F("%d", type->value.value_int);

            /* breaks the switch */
            break;

        case FLOAT_TYPE:
            PRINTF_F("%f", type->value.value_float);

            /* breaks the switch */
            break;

        case STRING_TYPE:
            PRINTF_F("'%s'", type->value.value_string);

            /* breaks the switch */
            break;

        case LIST_TYPE:
            PRINTF("[");

            create_iterator_linked_list(type->value.value_list, &iterator);

            while(TRUE) {
                get_next_iterator(iterator, (void **) &current);
                if(current == NULL) { break; }
                if(is_first == 0) { PRINTF(", "); };
                print_type(current);
                is_first = 0;
            }

            delete_iterator_linked_list(type->value.value_list, iterator);

            PRINTF("]");

            /* breaks the switch */
            break;

        case MAP_TYPE:
            PRINTF("{");

            create_element_iterator_hash_map(type->value.value_map, &iterator);

            while(TRUE) {
                get_next_iterator(iterator, (void **) &element);
                if(element == NULL) { break; }
                if(is_first == 0) { PRINTF(", "); };
                key = string_type((char *) element->key_string);
                print_type(&key);
                PRINTF(" : ");
                print_type((struct type_t *) element->value);
                is_first = 0;
            }

            delete_iterator_hash_map(type->value.value_map, iterator);

            PRINTF("}");

            /* breaks the switch */
            break;

        case SORT_MAP_TYPE:
            PRINTF("{");

            create_element_iterator_sort_map(type->value.value_sort_map, &iterator);

            while(TRUE) {
                get_next_iterator(iterator, (void **) &element);
                if(element == NULL) { break; }
                if(is_first == 0) { PRINTF(", "); };
                key = string_type((char *) element->key_string);
                print_type(&key);
                PRINTF(" : ");
                print_type((struct type_t *) element->value);
                is_first = 0;
            }

            delete_iterator_sort_map(type->value.value_sort_map, iterator);

            PRINTF("}");

            /* breaks the switch */
            break;

        default:
            PRINTF("undefined");

            /* breaks the switch */
            break;
    }

    /* raises no error */
    RAISE_NO_ERROR;
}