Ejemplo n.º 1
0
static PyObject *print_printer_base64(PyObject *self, PyObject *args) {
    /* allocates space for the decoded data buffer and for
    the storage of the length (size) of it */
    char *data;
    char *printer;
    char *input;
    size_t data_length;

    /* tries to parse the privided sequence of arguments
    as a single string value that is going to be used as
    the input value for the printing of the page */
    if(PyArg_ParseTuple(args, "ss", &printer, &input) == FALSE) {
        return NULL;
    }

    /* decodes the data value from the base 64 encoding
    and then uses it to print the data */
    decode_base64(
        (unsigned char *) input,
        strlen(input),
        (unsigned char **) &data, &data_length
    );
    print_printer(FALSE, printer, data, data_length);

    /* releases the decoded buffer (avoids memory leak)
    and then returns in success */
    _free_base64((unsigned char *) data);

    /* returns an invalid value to the caller method/function
    as this function should not return anything */
    Py_RETURN_NONE;
}
Ejemplo n.º 2
0
void print_hello() {
    /* allocates space for the decoded data buffer and for
    the storage of the length (size) of it */
    char *data;
    size_t data_length;

    /* decodes the data value from the base 64 encoding
    and then uses it to print the data */
    decode_base64((unsigned char *) HELLO_WORLD_B64, strlen(HELLO_WORLD_B64), (unsigned char **) &data, &data_length);
    print(FALSE, data, data_length);

    /* releases the decoded buffer (avoids memory leak)
    and then returns in success */
    _free_base64((unsigned char *) data);
}
Ejemplo n.º 3
0
void print_base64(char *file_path) {
    /* allocates space for both the "resolved" data
    buffer and for the buffer that will hold the file
    contents */
    char *data;
    unsigned char *buffer;

    /* allocates space for the value of the size of the
    file and the data buffer */
    size_t file_size;
    size_t data_length;

    /* allocates space for the pointer to the file object
    to be used in the reading */
    FILE *file;

    /* opens the target file for read operations in
    the binary form */
    fopen_s(&file, file_path, "rb");

    /* seeks to the final position in the file and
    checks the current offset (this value should be
    the size of the file in bytes) */
    fseek(file, 0, SEEK_END);
    file_size = ftell(file);
    fseek(file, 0, SEEK_SET);

    /* allocates enought space for the buffer to hold
    the complete set of contents of the file */
    buffer = (unsigned char *) malloc(file_size);

    /* reads the complete set of contents from the file
    and then sends then decodes them as base 64 */
    fread(buffer, sizeof(char), file_size, file);
    decode_base64(buffer, file_size, (unsigned char **) &data, &data_length);
    print(FALSE, data, data_length);

    /* releases the decoded buffer (avoids memory leak)
    and then returns in success */
    _free_base64((unsigned char *) data);

    /* releases the buffer holding the contents of the just
    read file (avoids leaking of memory) */
    free(buffer);
}
Ejemplo n.º 4
0
static PyObject *print_hello(PyObject *self, PyObject *args) {
    /* allocates space for the decoded data buffer and for
    the storage of the length (size) of it */
    char *data;
    size_t data_length;

    /* decodes the data value from the base 64 encoding
    and then uses it to print the data */
    decode_base64(
        (unsigned char *) HELLO_WORLD_B64,
        strlen(HELLO_WORLD_B64),
        (unsigned char **) &data, &data_length
    );
    print(FALSE, data, data_length);

    /* releases the decoded buffer (avoids memory leak)
    and then returns in success */
    _free_base64((unsigned char *) data);

    /* returns an invalid value to the caller method/function
    as this function should not return anything */
    Py_RETURN_NONE;
}