Marius van Witzenburg We fight for our survival, we fight!

17jul/110

How to add Base64 encoding and decoding in C

Posted by mariusvw

I found this page on the web while searching for something else but I thought this might be useful to others :-)

Overview
libb64 is a library of ANSI C routines for fast encoding/decoding data into and from a base64-encoded format. C++ wrappers are included, as well as the source code for standalone encoding and decoding executables.

Base64 uses a subset of displayable ASCII characters, and is therefore a useful encoding for storing binary data in a text file, such as XML, or sending binary data over text-only email.

Usage

#include <b64/encode.h>
#include <iostream>
int main() {
	base64::encoder E;
	E.encode(std::cin, std::cout);
	return 0;
}

You can read more info and download the package on the url below:

http://libb64.sourceforge.net/

Geëtiketeerd als: , , , , Geen reacties
2mrt/100

Shellproxy, an easy tool to run shell commands from PHP or other languages

Posted by mariusvw

This is a simple script that runs a shell command from PHP with the function system().
It sometimes happens that a command doesn't close the stdin or stdout, resulting the system() function to halt and wait for it to finish...
This causes PHP to reach the 30 second time limit and kill the script.

This script runs it in the background and you could make your commands send their output to a log file and still having full control.

Read the code below how to use it.

You can compile it by placing the code into shellproxy.c and then compile it with the following command:

gcc -o shellproxy shellproxy.c

I hope this is something useful for you as it was for me.

#include <stdio .h>
#include <stdlib .h>
#include <string .h>
 
int main(int argc, char *argv[]) {
    char command[1024];
    int t;
 
    if (argc == 1) {
        printf("nShell Proxyn");
        printf("By Marius van Witzenburg <http ://kitara.nl>nn");
        printf("You will mostly use this program from PHP or any othern");
        printf("webscripting language to background run programsnn");
        printf("Usage:n");
        printf("- CLI:n");
        printf("shellproxy "<cmd> <arg>"n");
        printf("shellproxy "<cmd> <arg> > redirect.txt"n");
        printf("- PHP:n");
        printf("system('shellproxy "<cmd> <arg> &"');n");
        printf("system('shellproxy "<cmd> <arg> > redirect.txt"');nn");
    }
 
    command[0] = 0;
 
    for (t = 1; t < argc; t++) {
        strcat(command, argv[t]);
        strcat(command, " ");
    }
 
    fclose(stdin);
    fclose(stdout);
    fclose(stderr);
 
    system(command);
}

It would be nice if you keep my name mentioned into this code if you use it.

Ps. Donations are welcome... ;-)

Geëtiketeerd als: , , , , , , , Geen reacties