Created
July 26, 2012 20:57
-
-
Save mattf/3184467 to your computer and use it in GitHub Desktop.
Condor File Transfer plugin (basically here-data://)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string.h> | |
#include <iostream> | |
#include <fstream> | |
/** | |
* This is an example file transfer plugin. It takes a uri of | |
* mef://blob/filename & a file path and writes blob the file. | |
* | |
* There are two valid invocations: | |
* 0) argv = {_, "-classad"} | |
* -> configuration information | |
* 1) argv = {_, "uri", "path"} | |
* : url is mef://blob/filename | |
* : path is the file to write to | |
* -> data from blob written to path | |
* | |
* NOTE: Filename is only a name, not a path. A ../.. attack is not possible. | |
*/ | |
using namespace std; | |
static const string HEADER = | |
"PluginVersion = \"3.1\"\n" | |
"PluginType = \"FileTransfer\"\n" | |
"SupportedMethods = \"mef\"\n"; | |
int | |
main(int argc, char *argv[]) | |
{ | |
// argv = {_, "-classad"} | |
if (argc == 2 && strcmp(argv[1], "-classad") == 0) { | |
cout << HEADER; | |
return 0; | |
} | |
// argv != {_, "mef://.../...", "path"} | |
if (argc != 3 || strncmp(argv[1], "mef://", 6)) return 1; | |
ofstream out(argv[2]); | |
if (!out.good()) return 2; | |
char *begin = argv[1] + 6; // lop off "mef://" | |
char *end = strrchr(begin, '/'); | |
if (!end) return 3; | |
*end = '\0'; // lop off the filename | |
out << begin << endl; | |
out.close(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment