Permalink
Browse files

Squashed commit of the following:

commit dea94a63db23aa85aa9e4b8aa7ec8dfe3d67f16b
Author: Thomas Mayer <thomas@residuum.org>
Date:   Mon Sep 24 20:46:08 2012 +0200

    Added another object [urlparams].

commit b960a26d0cdc9ef1405eddfddd504a4f86802816
Author: Thomas Mayer <thomas@residuum.org>
Date:   Mon Sep 24 18:24:44 2012 +0200

    OAUTH implementation.
  • Loading branch information...
1 parent c636dd0 commit 89c90de5aa11398917d82e6be5e9f099e8ea2eeb @residuum committed Sep 24, 2012
Showing with 444 additions and 110 deletions.
  1. +1 −0 .gitignore
  2. +11 −9 Makefile
  3. +3 −0 README.txt
  4. +20 −19 json-help.pd
  5. +2 −1 purest_json.c
  6. +41 −7 purest_json.h
  7. +182 −74 rest-json.c
  8. +34 −0 urlparams-help.pd
  9. +150 −0 urlparams.c
View
@@ -5,3 +5,4 @@
libpurest_json.so
libpurest_json.dylib
libpurest_json.dll
+*-my.pd
View
@@ -6,7 +6,7 @@ LIBRARY_NAME = purest_json
# add your .c source files, one object per file, to the SOURCES
# variable, help files will be included automatically, and for GUI
# objects, the matching .tcl file too
-SOURCES = rest-json.c json-decode.c json-encode.c
+SOURCES = rest-json.c json-decode.c json-encode.c urlparams.c
# list all pd objects (i.e. myobject.pd) files here, and their helpfiles will
# be included automatically
@@ -27,7 +27,7 @@ EXTRA_DIST = Changelog.txt
# unit tests and related files here, in the 'unittests' subfolder
UNITTESTS =
-HELPPATCHES = json-help.pd rest-json-help.pd
+HELPPATCHES = json-help.pd rest-json-help.pd urlparams-help.pd
#------------------------------------------------------------------------------#
@@ -39,8 +39,8 @@ HELPPATCHES = json-help.pd rest-json-help.pd
ALL_CFLAGS = -I"$(PD_INCLUDE)" -std=c99
ALL_LDFLAGS =
SHARED_LDFLAGS =
-ALL_LIBS = -lcurl -ljson
-LIBS_windows = -lpthread -lrtmp -lidn -lssl -lssh2 -lcrypto -lz -lws2_32 -lwldap32 -lwinmm -lgdi32
+ALL_LIBS = -lcurl -ljson -loauth
+LIBS_windows = -lpthread
CFLAGS_windows = -mthreads -DCURL_STATICLIB
@@ -221,20 +221,22 @@ ifeq (MINGW,$(findstring MINGW,$(UNAME)))
EXTENSION = dll
SHARED_EXTENSION = dll
OS = windows
- PD_PATH = $(shell cd "$$PROGRAMFILES/pd" && pwd)
+ ifeq ($(strip $(PD_PATH)),)
+ PD_PATH = $(shell cd "$$PROGRAMFILES/pd" && pwd)
+ endif
# MinGW doesn't seem to include cc so force gcc
CC=gcc
ifneq ($(strip $(CROSS)),)
CC = $(CROSS)-gcc
LD = $(CROSS)-ld
AR = $(CROSS)-ar
PKG_CONFIG = $(CROSS)-pkg-config
- CFLAGS += -I$(CROSS_PATH)/$(CROSS)/include -I../../pd/src
- LIBS += -L$(CROSS_PATH)/$(CROSS)/bin -L$(CROSS_PATH)/$(CROSS)/lib -L/../../pd/bin
- PATH := $(CROSS_PATH)/bin:$(PATH)
+ CFLAGS += -I$(CROSS_PATH)/$(CROSS)/include
+ LDFLAGS += -L$(CROSS_PATH)/$(CROSS)/bin -L$(CROSS_PATH)/$(CROSS)/lib
+ PATH := ${PATH}:$(CROSS_PATH)/bin
endif
OPT_CFLAGS = -O3 -funroll-loops -fomit-frame-pointer
- ALL_CFLAGS += -mms-bitfields $(CFLAGS_windows)
+ ALL_CFLAGS += -mms-bitfields -I"$(PD_PATH)/src" $(CFLAGS_windows)
ALL_LDFLAGS += -s -shared -Wl,--enable-auto-import -L"$(PD_PATH)/src" -L"$(PD_PATH)/bin" -L"$(PD_PATH)/obj"
SHARED_LDFLAGS += -shared -L"$(PD_PATH)/src" -L"$(PD_PATH)/bin" -L"$(PD_PATH)/obj"
ALL_LIBS += -lpd -lwsock32 -lkernel32 -luser32 -lgdi32 $(LIBS_windows)
View
@@ -38,6 +38,9 @@ Object for encoding data to JSON.
[json-decode]
Object for decoding JSON data.
+[urlparams]
+Object for url encoding and contatenating url parameters.
+
For the usage of the externals see the help patches for the objects.
View
@@ -6,11 +6,6 @@
#X obj 47 14 json-decode;
#X text 127 -13 - encodes data into a JSON string.;
#X text 127 13 - decodes a JSON string to lists.;
-#X text 47 46 [json-encode] has three methods: add \, clear and bang.
-add adds a new key/value pair to the internally stored object. clear
-clears the internally stored object. bang outputs the stored object
-as a JSON string. If you call add with a value that is already a JSON
-string \, then the object will be added as a nested object.;
#X msg 548 57 add id 1;
#X text 545 24 Will add key id and value of 1 to object;
#X msg 590 87 add name Residuum;
@@ -21,8 +16,8 @@ JSON object;
#X msg 654 229 add id 2;
#X text 651 202 adding a different value will overwrite the previously
stored one;
-#X msg 363 271 clear;
-#X text 359 252 This will clear the object;
+#X msg 407 271 clear;
+#X text 403 252 This will clear the object;
#X text 696 263 output the value;
#X msg 697 282 bang;
#N canvas 89 51 453 402 nested-objects 0;
@@ -126,7 +121,7 @@ the store \, with the right outlet of [json-decode] or [rest-json].
#X connect 23 0 24 0;
#X connect 24 0 13 0;
#X restore 173 430 pd about-decoded-json-strings;
-#X text 46 114 [json-decode] will accept a JSON string at its input
+#X text 46 130 [json-decode] will accept a JSON string at its input
and will output the decoded object as a series of lists of key/value
pairs. Boolean values of TRUE/FALSE will be translated to 1 or 0 \,
float and integer values will be output as floats. Json-decode will
@@ -164,21 +159,27 @@ objects. The messages will come as list key value.;
#X connect 9 0 8 0;
#X connect 9 1 12 0;
#X restore 364 430 pd json-arrays;
-#X text 46 232 [json-decode] treats json arrays as a series of objects.
+#X text 45 259 [json-decode] treats json arrays as a series of objects.
;
#X obj 566 427 print decoded_values;
#X obj 697 427 print decoding_done;
#X obj 656 391 print JSON_string;
#X obj 841 425 import purest_json;
-#X connect 0 0 20 0;
-#X connect 1 0 25 0;
-#X connect 1 1 26 0;
-#X connect 7 0 0 0;
+#X text 47 46 [json-encode] has four methods: add \, array \, clear
+and bang. add adds a new key/value pair to the internally stored object.
+array adds a new value to an array. clear clears the internally stored
+object. bang outputs the stored object as a JSON string. If you call
+add with a value that is already a JSON string \, then the object will
+be added as a nested object.;
+#X connect 0 0 19 0;
+#X connect 1 0 24 0;
+#X connect 1 1 25 0;
+#X connect 6 0 0 0;
+#X connect 8 0 0 0;
#X connect 9 0 0 0;
-#X connect 10 0 0 0;
+#X connect 11 0 0 0;
#X connect 12 0 0 0;
-#X connect 13 0 0 0;
-#X connect 15 0 0 0;
-#X connect 18 0 0 0;
-#X connect 20 0 1 0;
-#X connect 20 1 27 0;
+#X connect 14 0 0 0;
+#X connect 17 0 0 0;
+#X connect 19 0 1 0;
+#X connect 19 1 26 0;
View
@@ -2,9 +2,10 @@
void purest_json_setup(void) {
post("PuREST JSON version %s: A library for executing HTTP queries and encoding and decoding JSON data from Puredata.", LIBRARY_VERSION);
- post("(c) Thomas Mayer (Residuum) 2011");
+ post("(c) Thomas Mayer (Residuum) 2012");
post("Get the latest source from https://github.com/residuum/PuRestJson");
setup_rest0x2djson();
setup_json0x2dencode();
setup_json0x2ddecode();
+ urlparams_setup();
}
View
@@ -6,9 +6,15 @@
#include <curl/curl.h>
#include <json/json.h>
#include <pthread.h>
+#include <oauth.h>
#define LIBRARY_VERSION "0.7.1"
+typedef enum {
+ COOKIE,
+ OAUTH
+} AuthType;
+
/* reading / writing data in HTTP requests */
typedef struct memory_struct {
char *memory;
@@ -30,12 +36,23 @@ typedef struct rest {
t_outlet *status_info_outlet;
int out_count;
char base_url[MAXPDSTRING];
- /* cookie authentication */
- char login_path[MAXPDSTRING];
- char username[MAXPDSTRING];
- char password[MAXPDSTRING];
- char auth_token[MAXPDSTRING];
- /* end cookie authentication */
+ /* authentication: cookie / oauth */
+ AuthType auth_type;
+ union {
+ struct {
+ char login_path[MAXPDSTRING];
+ char username[MAXPDSTRING];
+ char password[MAXPDSTRING];
+ char auth_token[MAXPDSTRING];
+ } cookie;
+ struct {
+ char request_type[5]; /*GET or POST*/
+ char client_key[MAXPDSTRING];
+ char client_secret[MAXPDSTRING];
+ char token_key[MAXPDSTRING];
+ char token_secret[MAXPDSTRING];
+ } oauth;
+ } auth;
t_atom *out;
/* threading */
char request_type[7]; /*One of GET, PUT, POST; DELETE*/
@@ -58,7 +75,15 @@ typedef struct json_decode {
t_object x_ob;
t_outlet *done_outlet;
} t_json_decode;
-
+
+/* [urlparams] */
+typedef struct urlparams {
+ t_object x_ob;
+ t_key_value_pair *first_data;
+ t_key_value_pair *last_data;
+ int data_count;
+} t_urlparams;
+
/* [rest-json] */
void setup_rest0x2djson(void);
void *rest_new(t_symbol *selector, int argcount, t_atom *argvec);
@@ -86,6 +111,15 @@ void json_decode_list(t_json_decode *x, t_symbol *selector, int argcount, t_atom
void output_json(json_object *jobj, t_outlet *data_outlet, t_outlet *done_outlet);
void output_json_string(char *json_string, t_outlet *data_outlet, t_outlet *done_outlet);
+/* [urlparams] */
+void urlparams_setup(void);
+void *urlparams_new(t_symbol *selector, int argcount, t_atom *argvec);
+void urlparams_free(t_urlparams *x, t_symbol *selector, int argcount, t_atom *argvec);
+
+void urlparams_bang(t_urlparams *x);
+void urlparams_add(t_urlparams *x, t_symbol *selector, int argcount, t_atom *argvec);
+void urlparams_clear(t_urlparams *x, t_symbol *selector, int argcount, t_atom *argvec);
+
/* general */
void purest_json_setup(void);
char *remove_backslashes(char *source_string, size_t memsize);
Oops, something went wrong.

0 comments on commit 89c90de

Please sign in to comment.