forked from lda/telodendria
Misc changes.
This commit is contained in:
parent
7fa982a16f
commit
62cd1cdc98
4 changed files with 54 additions and 17 deletions
14
TODO.txt
14
TODO.txt
|
@ -17,24 +17,24 @@ Milestone: v0.3.0
|
|||
[ ] Multi-output
|
||||
[ ] Move UtilStreamCopy()
|
||||
[~] HTTP Client API
|
||||
[ ] Document HttpParseHeaders()
|
||||
[x] Document HttpParseHeaders()
|
||||
[ ] HttpClient man page
|
||||
[ ] Uri man page
|
||||
[x] Test on other platforms
|
||||
[~] Option to pretty-print Json
|
||||
[ ] Document JsonEncode() and JsonEncodeValue()
|
||||
[x] Option to pretty-print Json
|
||||
[x] Document JsonEncode() and JsonEncodeValue()
|
||||
[ ] Update man page for td
|
||||
[ ] Document Telodendria and Main
|
||||
[x] Document Telodendria and Main
|
||||
[ ] Document tt and http-debug-server
|
||||
|
||||
[~] Simple command line tool to make matrix requests
|
||||
[x] Simple command line tool to make matrix requests
|
||||
[x] Built on HTTP client API
|
||||
[ ] http man page
|
||||
[x] http man page
|
||||
[~] Simple command line tool for working with JSON
|
||||
[x] Pretty-print Json
|
||||
[x] Query fields for use in shell scripts.
|
||||
[x] Encode user-provided JSON strings
|
||||
[ ] json man page
|
||||
[x] json man page
|
||||
[ ] Update man pages for tp and send-patch
|
||||
|
||||
[ ] Move configuration to database
|
||||
|
|
|
@ -49,6 +49,6 @@ extern void
|
|||
TelodendriaMemoryIterator(MemoryInfo *, void *);
|
||||
|
||||
extern void
|
||||
TelodendriaPrintHeader(LogConfig * lc);
|
||||
TelodendriaPrintHeader(LogConfig *);
|
||||
|
||||
#endif
|
||||
|
|
12
tools/bin/tt
12
tools/bin/tt
|
@ -6,6 +6,8 @@ PASSWORD=$(json -e 'p@s$w0rd')
|
|||
|
||||
ENDPOINT="$1"
|
||||
|
||||
: "${METH:=GET}"
|
||||
|
||||
# Check if user is available. If it is, register it.
|
||||
user_available=$(http "$BASE/_matrix/client/v3/register/available?username=$USERNAME" | json -s "available")
|
||||
if [ "$user_available" = "true" ]; then
|
||||
|
@ -20,7 +22,7 @@ if [ "$user_available" = "true" ]; then
|
|||
printf ' "password": %s,' "$PASSWORD"
|
||||
printf ' "inhibit_login": true '
|
||||
printf '}'
|
||||
) | http -X POST "$BASE/_matrix/client/v3/register" > /dev/null
|
||||
) | http -X POST -d @- "$BASE/_matrix/client/v3/register" > /dev/null
|
||||
fi
|
||||
|
||||
# Log in
|
||||
|
@ -33,7 +35,7 @@ ACCESS_TOKEN=$((
|
|||
printf ' "type": "m.login.password",'
|
||||
printf ' "password": %s' "$PASSWORD"
|
||||
printf '}'
|
||||
) | http -X POST "$BASE/_matrix/client/v3/login" | json -s "access_token->@decode")
|
||||
) | http -X POST -d @- "$BASE/_matrix/client/v3/login" | json -s "access_token->@decode")
|
||||
|
||||
if [ -z "$ACCESS_TOKEN" ]; then
|
||||
echo "Unable to log in."
|
||||
|
@ -41,7 +43,11 @@ if [ -z "$ACCESS_TOKEN" ]; then
|
|||
fi
|
||||
|
||||
# Make request
|
||||
http -X POST -H "Authorization: Bearer $ACCESS_TOKEN" "$BASE$ENDPOINT" | json
|
||||
if [ -n "$DATA" ]; then
|
||||
http -X "$METH" -d "$DATA" -H "Authorization: Bearer $ACCESS_TOKEN" "${BASE}${ENDPOINT}" | json
|
||||
else
|
||||
http -X "$METH" -H "Authorization: Bearer $ACCESS_TOKEN" "${BASE}${ENDPOINT}" | json
|
||||
fi
|
||||
|
||||
# Log out
|
||||
http -X POST -H "Authorization: Bearer $ACCESS_TOKEN" \
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <ctype.h>
|
||||
#include <getopt.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <Memory.h>
|
||||
#include <Str.h>
|
||||
|
@ -39,7 +40,7 @@
|
|||
static void
|
||||
usage(char *prog)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s [-i -X method -H header] url\n", prog);
|
||||
fprintf(stderr, "Usage: %s [-i -X method -H header -d data] url\n", prog);
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -49,6 +50,7 @@ main(int argc, char **argv)
|
|||
HttpStatus res;
|
||||
HttpRequestMethod method = HTTP_GET;
|
||||
Uri *uri;
|
||||
char *data = NULL;
|
||||
|
||||
HashMap *requestHeaders = HashMapCreate();
|
||||
char *key;
|
||||
|
@ -59,7 +61,7 @@ main(int argc, char **argv)
|
|||
|
||||
int ch;
|
||||
|
||||
while ((ch = getopt(argc, argv, "iH:X:")) != -1)
|
||||
while ((ch = getopt(argc, argv, "iH:X:d:")) != -1)
|
||||
{
|
||||
switch (ch)
|
||||
{
|
||||
|
@ -93,6 +95,9 @@ main(int argc, char **argv)
|
|||
|
||||
HashMapSet(requestHeaders, key, StrDuplicate(val));
|
||||
break;
|
||||
case 'd':
|
||||
data = optarg;
|
||||
break;
|
||||
default:
|
||||
usage(argv[0]);
|
||||
return 1;
|
||||
|
@ -154,11 +159,37 @@ main(int argc, char **argv)
|
|||
HttpRequestSendHeaders(cx);
|
||||
HashMapFree(requestHeaders);
|
||||
|
||||
/* Only send stdin if it's not attached to a TTY. This prevents us
|
||||
* from blocking if no pipe is provided */
|
||||
if (!isatty(fileno(stdin)))
|
||||
if (data)
|
||||
{
|
||||
UtilStreamCopy(stdin, HttpClientStream(cx));
|
||||
if (*data == '@')
|
||||
{
|
||||
FILE *in;
|
||||
|
||||
data++;
|
||||
|
||||
if (strcmp(data, "-") == 0)
|
||||
{
|
||||
in = stdin;
|
||||
}
|
||||
else
|
||||
{
|
||||
in = fopen(data, "r");
|
||||
}
|
||||
|
||||
if (!in)
|
||||
{
|
||||
fprintf(stderr, "%s: %s\n", data, strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
UtilStreamCopy(in, HttpClientStream(cx));
|
||||
|
||||
fclose(in);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(HttpClientStream(cx), "%s", data);
|
||||
}
|
||||
}
|
||||
|
||||
res = HttpRequestSend(cx);
|
||||
|
|
Loading…
Reference in a new issue