CLI work and Makefile cleanup.

This commit is contained in:
Adam Ierymenko 2015-04-16 15:07:58 -07:00
parent 8333bf065e
commit 13d5073e5b
5 changed files with 79 additions and 3 deletions

View File

@ -72,7 +72,7 @@ selftest: $(OBJS) selftest.o
# ./buildinstaller.sh # ./buildinstaller.sh
clean: clean:
rm -rf *.o node/*.o controller/*.o osdep/*.o service/*.o ext/http-parser/*.o ext/lz4/*.o ext/json-parser/*.o build-* zerotier-one zerotier-idtool zerotier-selftest ZeroTierOneInstaller-* rm -rf *.o node/*.o controller/*.o osdep/*.o service/*.o ext/http-parser/*.o ext/lz4/*.o ext/json-parser/*.o build-* zerotier-one zerotier-idtool zerotier-selftest zerotier-cli ZeroTierOneInstaller-*
debug: FORCE debug: FORCE
make -j 4 ZT_DEBUG=1 make -j 4 ZT_DEBUG=1

View File

@ -77,7 +77,7 @@ installer: one FORCE
./buildinstaller.sh ./buildinstaller.sh
clean: clean:
rm -rf *.o node/*.o controller/*.o osdep/*.o service/*.o ext/http-parser/*.o ext/lz4/*.o ext/json-parser/*.o zerotier-one zerotier-idtool zerotier-selftest build-* ZeroTierOneInstaller-* *.deb *.rpm rm -rf *.o node/*.o controller/*.o osdep/*.o service/*.o ext/http-parser/*.o ext/lz4/*.o ext/json-parser/*.o zerotier-one zerotier-idtool zerotier-cli zerotier-selftest build-* ZeroTierOneInstaller-* *.deb *.rpm
debug: FORCE debug: FORCE
make -j 4 ZT_DEBUG=1 make -j 4 ZT_DEBUG=1

View File

@ -76,7 +76,7 @@ selftest: $(OBJS) selftest.o
# $(CODESIGN) -vvv "build-ZeroTierUI-release/ZeroTier One.app" # $(CODESIGN) -vvv "build-ZeroTierUI-release/ZeroTier One.app"
clean: clean:
rm -rf *.dSYM build-* *.pkg *.dmg *.o node/*.o controller/*.o service/*.o osdep/*.o ext/http-parser/*.o ext/lz4/*.o ext/json-parser/*.o zerotier-one zerotier-idtool zerotier-selftest ZeroTierOneInstaller-* rm -rf *.dSYM build-* *.pkg *.dmg *.o node/*.o controller/*.o service/*.o osdep/*.o ext/http-parser/*.o ext/lz4/*.o ext/json-parser/*.o zerotier-one zerotier-idtool zerotier-selftest zerotier-cli ZeroTierOneInstaller-*
# For our use -- builds official signed binary, packages in installer and download DMG # For our use -- builds official signed binary, packages in installer and download DMG
official: FORCE official: FORCE

47
one.cpp
View File

@ -298,7 +298,54 @@ static int cli(int argc,char **argv)
return 1; return 1;
} }
} else if (command == "join") { } else if (command == "join") {
if (arg1.length() != 16) {
cliPrintHelp(argv[0],stderr);
return 2;
}
unsigned int scode = Http::POST(
1024 * 1024 * 16,
60000,
(const struct sockaddr *)&addr,
(std::string("/network/") + arg1).c_str(),
requestHeaders,
"",
0,
responseHeaders,
responseBody);
if (scode == 200) {
if (json) {
printf("%s",cliFixJsonCRs(responseBody).c_str());
} else {
}
return 0;
} else {
printf("%u %s %s"ZT_EOL_S,scode,command.c_str(),responseBody.c_str());
return 1;
}
} else if (command == "leave") { } else if (command == "leave") {
if (arg1.length() != 16) {
cliPrintHelp(argv[0],stderr);
return 2;
}
unsigned int scode = Http::DELETE(
1024 * 1024 * 16,
60000,
(const struct sockaddr *)&addr,
(std::string("/network/") + arg1).c_str(),
requestHeaders,
responseHeaders,
responseBody);
if (scode == 200) {
if (json) {
printf("%s",cliFixJsonCRs(responseBody).c_str());
} else {
printf("200 leave OK"ZT_EOL_S);
}
return 0;
} else {
printf("%u %s %s"ZT_EOL_S,scode,command.c_str(),responseBody.c_str());
return 1;
}
} else { } else {
cliPrintHelp(argv[0],stderr); cliPrintHelp(argv[0],stderr);
return 0; return 0;

View File

@ -82,6 +82,35 @@ public:
responseBody); responseBody);
} }
/**
* Make HTTP DELETE request
*
* The caller must set all headers, including Host.
*
* @return HTTP status code or 0 on error (responseBody will contain error message)
*/
static inline unsigned int DELETE(
unsigned long maxResponseSize,
unsigned long timeout,
const struct sockaddr *remoteAddress,
const char *path,
const std::map<std::string,std::string> &requestHeaders,
std::map<std::string,std::string> &responseHeaders,
std::string &responseBody)
{
return _do(
"DELETE",
maxResponseSize,
timeout,
remoteAddress,
path,
requestHeaders,
(const void *)0,
0,
responseHeaders,
responseBody);
}
/** /**
* Make HTTP POST request * Make HTTP POST request
* *