Permalink
Browse files

init commit

  • Loading branch information...
cyga committed Sep 29, 2011
0 parents commit 6edfb04e0a44e9f23b8b3ff1c92a50137589f4da
Showing with 3,575 additions and 0 deletions.
  1. +31 −0 Makefile
  2. +92 −0 README.md
  3. +24 −0 examples/callback.sql
  4. +23 −0 expected/www_fdw.out
  5. +78 −0 libjson-0.8/Makefile
  6. +72 −0 libjson-0.8/README
  7. +5 −0 libjson-0.8/debian/changelog
  8. +1 −0 libjson-0.8/debian/compat
  9. +22 −0 libjson-0.8/debian/control
  10. +26 −0 libjson-0.8/debian/copyright
  11. +1 −0 libjson-0.8/debian/docs
  12. +2 −0 libjson-0.8/debian/libjson-dev.dirs
  13. +4 −0 libjson-0.8/debian/libjson-dev.install
  14. +1 −0 libjson-0.8/debian/libjson.dirs
  15. +1 −0 libjson-0.8/debian/libjson.install
  16. +57 −0 libjson-0.8/debian/rules
  17. +4 −0 libjson-0.8/debian/watch
  18. +505 −0 libjson-0.8/documentation
  19. +963 −0 libjson-0.8/json.c
  20. +207 −0 libjson-0.8/json.h
  21. +540 −0 libjson-0.8/jsonlint.c
  22. +10 −0 libjson-0.8/libjson.pc.in
  23. 0 libjson-0.8/tests/bad/empty.json
  24. +3 −0 libjson-0.8/tests/bad/esc0.json
  25. +3 −0 libjson-0.8/tests/bad/esc1.json
  26. +3 −0 libjson-0.8/tests/bad/esc2.json
  27. +3 −0 libjson-0.8/tests/bad/esc3.json
  28. +3 −0 libjson-0.8/tests/bad/esc4.json
  29. +3 −0 libjson-0.8/tests/bad/float0.json
  30. +3 −0 libjson-0.8/tests/bad/float1.json
  31. +1 −0 libjson-0.8/tests/bad/object0.json
  32. +3 −0 libjson-0.8/tests/bad/object1.json
  33. +3 −0 libjson-0.8/tests/bad/object2.json
  34. +5 −0 libjson-0.8/tests/bad/object3.json
  35. +2 −0 libjson-0.8/tests/good/1.json
  36. +3 −0 libjson-0.8/tests/good/2.json
  37. +4 −0 libjson-0.8/tests/good/2obj.json
  38. +3 −0 libjson-0.8/tests/good/3.json
  39. +3 −0 libjson-0.8/tests/good/4.json
  40. +5 −0 libjson-0.8/tests/good/5.json
  41. +4 −0 libjson-0.8/tests/good/6.json
  42. +7 −0 libjson-0.8/tests/good/7.json
  43. +13 −0 libjson-0.8/tests/good/c-comment.json
  44. +21 −0 libjson-0.8/tests/good/complex0.json
  45. +3 −0 libjson-0.8/tests/good/emptyobj.json
  46. +3 −0 libjson-0.8/tests/good/esc0.json
  47. +3 −0 libjson-0.8/tests/good/esc1.json
  48. +3 −0 libjson-0.8/tests/good/esc2.json
  49. +3 −0 libjson-0.8/tests/good/esc3.json
  50. +3 −0 libjson-0.8/tests/good/esc4.json
  51. +3 −0 libjson-0.8/tests/good/float0.json
  52. +3 −0 libjson-0.8/tests/good/float1.json
  53. +3 −0 libjson-0.8/tests/good/float2.json
  54. +13 −0 libjson-0.8/tests/good/multiobj.json
  55. +10 −0 libjson-0.8/tests/good/yaml-comment.json
  56. +27 −0 libjson-0.8/tests/runtest
  57. +12 −0 sql/www_fdw.sql
  58. +27 −0 www_fdw--1.0.0.sql
  59. +687 −0 www_fdw.c
  60. +5 −0 www_fdw.control
@@ -0,0 +1,31 @@
+# contrib/www_fdw/Makefile
+
+LIBJSON = libjson-0.8
+MODULE_big = www_fdw
+OBJS = www_fdw.o $(LIBJSON)/json.o
+EXTENSION = www_fdw
+DATA = www_fdw--1.0.0.sql
+
+REGRESS = www_fdw
+SHLIB_LINK = -lcurl
+
+all:all-libjson
+
+all-libjson:
+ $(MAKE) -C $(LIBJSON) all
+
+clean: clean-libjson
+
+clean-libjson:
+ $(MAKE) -C $(LIBJSON) clean
+
+ifdef USE_PGXS
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
+include $(PGXS)
+else
+subdir = contrib/www_fdw
+top_builddir = ../..
+include $(top_builddir)/src/Makefile.global
+include $(top_srcdir)/contrib/contrib-global.mk
+endif
@@ -0,0 +1,92 @@
+twitter\_fdw
+============
+
+This library contains a single PostgreSQL extension, a Foreign Data
+Wrapper (FDW) handler of PostgreSQL which fetches text messages from
+Twitter over the Internet and returns as a table.
+
+Installation
+------------
+
+ $ export USE_PGXS=1
+ $ make && make install
+ $ psql -c "CREATE EXTENSION www_fdw" db
+
+The CREATE EXTENSION statement creates not only FDW handlers but also
+Data Wrapper, Foreign Server, User Mapping and twitter table.
+
+Usage
+-----
+
+After installation, simply query from `twitter` table.
+
+ db=# SELECT from_user, created_at, text FROM twitter WHERE q = '#postgresql';
+
+The layout of `twitter` table is as below:
+
+ Foreign table "public.twitter"
+ Column | Type | Modifiers
+ -------------------+-----------------------------+-----------
+ id | bigint |
+ text | text |
+ from_user | text |
+ from_user_id | bigint |
+ to_user | text |
+ to_user_id | bigint |
+ iso_language_code | text |
+ source | text |
+ profile_image_url | text |
+ created_at | timestamp without time zone |
+ q | text |
+ Server: www_service
+
+The column `q` is a virtual column that is passed to API as a
+query string if the column is used with `=` operator as
+WHERE q = '#sometext'. You can put any text as defined in the API
+parameter `q`. Note the query string is percent-encoded by the module.
+The other columns are mapped to the corresponding property name of
+each tweet item in the API result. For more detail on these values,
+see the API document.
+
+Depencency
+----------
+
+This module depends on
+
+ * [libcurl](http://curl.haxx.se/libcurl/)
+ * [libjson](http://projects.snarc.org/libjson/)
+ * [Twitter API](http://apiwiki.twitter.com/w/page/22554679/Twitter-API-Documentation)
+
+The source of libjson is included this module package and linked as a
+static library, wheares libcurl is assumed installed in the system.
+You may need additional development package, as `libcurl-dev` in yum.
+Consult your system and repository owner for more detail.
+
+Author
+------
+
+Hitoshi Harada <umi.tanuki@gmail.com>
+
+Copyright and License
+---------------------
+
+Copyright (c) Hitoshi Harada
+
+This module is free software; you can redistribute it and/or modify it under
+the [PostgreSQL License](http://www.opensource.org/licenses/postgresql).
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose, without fee, and without a written agreement is
+hereby granted, provided that the above copyright notice and this paragraph
+and the following two paragraphs appear in all copies.
+
+In no event shall Hitoshi Harada be liable to any party for direct,
+indirect, special, incidental, or consequential damages, including
+lost profits, arising out of the use of this software and its documentation,
+even if Hitoshi Harada has been advised of the possibility of such damage.
+
+Hitoshi Harada specifically disclaims any warranties,
+including, but not limited to, the implied warranties of merchantability and
+fitness for a particular purpose. The software provided hereunder is on an "as
+is" basis, and Hitoshi Harada has no obligations to provide maintenance,
+support, updates, enhancements, or modifications.
@@ -0,0 +1,24 @@
+CREATE OR REPLACE FUNCTION f(e anyelement, idx bigint) RETURNS g AS $$
+DECLARE
+ r g;
+BEGIN
+ BEGIN
+ IF idx > array_length(e.items, 1) THEN
+ RETURN NULL;
+ END IF;
+ r.title := e.items[idx].title;
+ r.link := e.items[idx].link;
+ r.snippet := e.items[idx].snippet;
+ EXCEPTION
+ WHEN OTHERS THEN
+ RAISE EXCEPTION 'error occured, sqlstate: %', SQLSTATE;
+ END;
+ RETURN r;
+END; $$ LANGUAGE PLPGSQL;
+
+/*
+select f( ROW( ARRAY[ ('TITLE','LINK','SNIPPET')::t_item, ('TITLE2','LINK2','SNIPPET2')::t_item ] )::t_answer, 1);
+select f( ROW( ARRAY[ ('TITLE','LINK','SNIPPET')::t_item, ('TITLE2','LINK2','SNIPPET2')::t_item ] )::t_answer, 2);
+select f( ROW( ARRAY[ ('TITLE','LINK','SNIPPET')::t_item, ('TITLE2','LINK2','SNIPPET2')::t_item ] )::t_answer, 3);
+select f( 1, 1);
+*/
@@ -0,0 +1,23 @@
+CREATE EXTENSION www_fdw;
+SELECT count(*) FROM twitter;
+ count
+-------
+ 0
+(1 row)
+
+SELECT count(*) FROM twitter WHERE q = '#postgresql';
+ count
+-------
+ 15
+(1 row)
+
+CREATE TEMP TABLE twtest (id int, from_user text);
+INSERT INTO twtest(from_user)
+ SELECT from_user FROM twitter WHERE q = '#postgres' LIMIT 1;
+SELECT true FROM twtest INNER JOIN
+ twitter USING(from_user) WHERE q = '#postgres';
+ bool
+------
+ t
+(1 row)
+
@@ -0,0 +1,78 @@
+AR = ar
+CC = gcc
+CFLAGS ?= -Wall -Os -fPIC
+LDFLAGS = -L.
+SHLIB_CFLAGS = -shared
+
+INSTALL_EXEC = install -m 755 -o root -g root
+INSTALL_DATA = install -m 644 -o root -g root
+COPY_PRESERVELINKS = cp -d
+INSTALL_SOLINKS = $(COPY_PRESERVELINKS)
+
+MAJOR = 0
+MINOR = 8
+MICRO = 0
+
+NAME = json
+A_TARGETS = lib$(NAME).a
+BIN_TARGETS = $(NAME)lint
+PC_TARGET = lib$(NAME).pc
+SO_LINKS = lib$(NAME).so lib$(NAME).so.$(MAJOR) lib$(NAME).so.$(MAJOR).$(MINOR)
+SO_FILE = lib$(NAME).so.$(MAJOR).$(MINOR).$(MICRO)
+HEADERS = $(NAME).h
+
+PREFIX ?= /usr
+DESTDIR ?=
+INSTALLDIR ?= $(DESTDIR)$(PREFIX)
+
+TARGETS = $(A_TARGETS) $(SO_FILE) $(SO_LINKS) $(BIN_TARGETS) $(PC_TARGET)
+
+all: $(TARGETS)
+
+lib$(NAME).a: $(NAME).o
+ $(AR) rc $@ $+
+
+lib$(NAME).so: lib$(NAME).so.$(MAJOR)
+ ln -sf $< $@
+
+lib$(NAME).so.$(MAJOR): lib$(NAME).so.$(MAJOR).$(MINOR)
+ ln -sf $< $@
+
+lib$(NAME).so.$(MAJOR).$(MINOR): lib$(NAME).so.$(MAJOR).$(MINOR).$(MICRO)
+ ln -sf $< $@
+
+lib$(NAME).so.$(MAJOR).$(MINOR).$(MICRO): $(NAME).o
+ $(CC) $(CFLAGS) $(LDFLAGS) -Wl,-soname -Wl,lib$(NAME).so.$(MAJOR).$(MINOR).$(MICRO) $(SHLIB_CFLAGS) -o $@ $^
+
+$(NAME)lint: $(NAME)lint.o $(NAME).o
+ $(CC) $(CFLAGS) -o $@ $+
+
+%.o: %.c %.h
+ $(CC) $(CFLAGS) -c -o $@ $<
+
+.PHONY: lib$(NAME).pc
+lib$(NAME).pc: lib$(NAME).pc.in
+ sed -e 's;@PREFIX@;$(PREFIX);' -e 's;@LIBJSON_VER_MAJOR@;$(MAJOR);' -e 's;@LIBJSON_VER_MINOR@;$(MINOR);' < $< > $@
+
+.PHONY: tests clean install install-bin install-lib
+tests: $(NAME)lint
+ (cd tests; ./runtest)
+
+install-lib: $(SO_TARGETS) $(A_TARGETS) $(PC_TARGET)
+ mkdir -p $(INSTALLDIR)/lib/pkgconfig
+ $(INSTALL_DATA) -t $(INSTALLDIR)/lib/pkgconfig $(PC_TARGET)
+ mkdir -p $(INSTALLDIR)/include
+ $(INSTALL_DATA) -t $(INSTALLDIR)/include $(HEADERS)
+ mkdir -p $(INSTALLDIR)/lib
+ $(INSTALL_EXEC) -t $(INSTALLDIR)/lib $(SO_FILE)
+ $(INSTALL_DATA) -t $(INSTALLDIR)/lib $(A_TARGETS)
+ $(INSTALL_SOLINKS) $(SO_LINKS) $(INSTALLDIR)/lib
+
+install-bin: $(BIN_TARGETS)
+ mkdir -p $(INSTALLDIR)/bin
+ $(INSTALL_EXEC) -t $(INSTALLDIR)/bin $(BIN_TARGETS)
+
+install: install-lib install-bin
+
+clean:
+ rm -f *.o $(TARGETS)
@@ -0,0 +1,72 @@
+= libjson README =
+
+libjson is a simple library without any dependancies to parse and pretty print
+the json format (RFC4627). The JSON format is a concise and structured data
+format.
+
+libjson parser is an interruptible handcoded state parse. the parser takes
+character or string as input. Since it's interruptible, it's up to the
+user to feed the stream to the parser, which permits complete flexibility
+as to whether the data is coming from a pipe, a network socket, a file on disk,
+a serial line, or crafted by the user.
+
+The parser doesn't create an object tree for you, but each time it comes up
+with an element in this data, it just callback to the user with the type found and
+for some type, the data associated with it. it can be compared to the SAX way of XML,
+hence it's called SAJ (Simple API for JSon).
+
+The parser doesn't convert number to any native C format, but instead callback
+with a string that is a valid JSon number. JSon number can be of any size,
+so that's up to user to decide whetever or not, the number can map to native C type
+int32_t, int64_t, or a complex integer type. As well the user has a choice to
+refuse the integer at the callback stage if the length is not appropriate.
+
+The parser optionally allows YAML and/or C comments to be ignored if the config
+structure is set accordingly, otherwise a JSON_ERROR_COMMENT_NOT_ALLOWED is returned.
+
+the parser API is really simple, totaling only 5 API calls:
+
+* json_parser_init
+* json_parser_char
+* json_parser_string
+* json_parser_is_done
+* json_parser_free
+
+json_parser_init initializes a new parser context from a parser config and
+takes a callback + userdata. This callback function is used everything the
+parser need to communicate a type and value to the client side of the library.
+
+json_parser_char take one character and inject it in the parser. on parsing
+success it will return a 0 value, but on parsing error it returns a parsing
+error that represents the type of the error encounters. see JSON_ERROR_*
+for the full set of return values.
+
+json_parser_string is similar to json_parser_char except that it takes a string
+and a length. it also returns the number of character processed, which is
+useful when an parser error happened in the stream to pinpoint where.
+
+json_parser_is_done permits to test whetever or not the parser is in a
+terminated state. it involves not beeing into any structure.
+
+json_parser_free is the opposite of init, it just free the allocated structure.
+
+the printer API is simple too:
+
+* json_printer_init
+* json_printer_free
+* json_printer_pretty
+* json_printer_raw
+
+json_printer_init initialise a printing context and takes a callback + userdata
+that will be called for every character that the printer wants to output. the
+caller can have the printer callback redirect to anything it wants.
+
+json_printer_free is the opposite of init
+
+json_printer_raw takes a json type and an optional data and length value
+depending on the type. it's up to the caller to verify that the order of type
+are JSON-compliant, otherwise the generated document won't be able to be parsed
+again.
+
+json_printer_pretty works like json_printer_raw but is targetted for human
+reading by appending newlines and spaces
@@ -0,0 +1,5 @@
+libjson (0.7-1) unstable; urgency=low
+
+ * Initial release.
+
+ -- William Dauchy <wdauchy@gmail.com> Tue, 16 Mar 2010 15:45:59 +0100
@@ -0,0 +1 @@
+7
@@ -0,0 +1,22 @@
+Source: libjson
+Priority: extra
+Maintainer: William Dauchy <wdauchy@gmail.com>
+Build-Depends: debhelper (>= 7)
+Standards-Version: 3.8.4
+Section: libs
+Homepage: http://projects.snarc.org/libjson/
+
+Package: libjson-dev
+Section: libdevel
+Architecture: any
+Depends: libjson (= ${binary:Version})
+Description: Development files for libjson
+ This package contains the header files and static library needed to
+ compile applications that use confuse.
+
+Package: libjson
+Section: libs
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}
+Description: Library to parse and pretty print the json format (RFC4627).
+ The JSON format is a concise and structured data format.
@@ -0,0 +1,26 @@
+This work was packaged for Debian by:
+
+ William Dauchy <wdauchy@gmail.com> on Tue, 16 Mar 2010 15:45:59 +0100
+
+It was downloaded from:
+
+ http://projects.snarc.org/libjson/
+
+Upstream Author(s):
+
+ Vincent Hanquez <tab@snarc.org>
+
+Copyright:
+
+ Copyright (C) 2009-2010 Vincent Hanquez
+
+License:
+
+ libjson is covered by the LGPLv2 license, or at your option the LGPLv3 license
+
+The Debian packaging is:
+
+ Copyright (C) 2010 William Dauchy <wdauchy@gmail.com>
+
+and is licensed under the LGPL version 3,
+see "/usr/share/common-licenses/LGPL".
@@ -0,0 +1 @@
+README
@@ -0,0 +1,2 @@
+usr/lib
+usr/include
@@ -0,0 +1,4 @@
+usr/include/*
+usr/lib/lib*.a
+usr/lib/lib*.so
+usr/lib/pkgconfig/*
@@ -0,0 +1 @@
+usr/lib
@@ -0,0 +1 @@
+usr/lib/lib*.so.*
Oops, something went wrong.

0 comments on commit 6edfb04

Please sign in to comment.