hiredis-futureproof 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/COPYING +28 -0
  3. data/Rakefile +53 -0
  4. data/ext/hiredis_ext/connection.c +611 -0
  5. data/ext/hiredis_ext/extconf.rb +48 -0
  6. data/ext/hiredis_ext/hiredis_ext.c +15 -0
  7. data/ext/hiredis_ext/hiredis_ext.h +44 -0
  8. data/ext/hiredis_ext/reader.c +124 -0
  9. data/lib/hiredis/connection.rb +10 -0
  10. data/lib/hiredis/ext/connection.rb +29 -0
  11. data/lib/hiredis/ext/reader.rb +2 -0
  12. data/lib/hiredis/reader.rb +10 -0
  13. data/lib/hiredis/ruby/connection.rb +316 -0
  14. data/lib/hiredis/ruby/reader.rb +183 -0
  15. data/lib/hiredis/version.rb +3 -0
  16. data/lib/hiredis.rb +2 -0
  17. data/vendor/hiredis/COPYING +29 -0
  18. data/vendor/hiredis/Makefile +308 -0
  19. data/vendor/hiredis/alloc.c +86 -0
  20. data/vendor/hiredis/alloc.h +91 -0
  21. data/vendor/hiredis/async.c +892 -0
  22. data/vendor/hiredis/async.h +147 -0
  23. data/vendor/hiredis/async_private.h +75 -0
  24. data/vendor/hiredis/dict.c +352 -0
  25. data/vendor/hiredis/dict.h +126 -0
  26. data/vendor/hiredis/fmacros.h +12 -0
  27. data/vendor/hiredis/hiredis.c +1173 -0
  28. data/vendor/hiredis/hiredis.h +336 -0
  29. data/vendor/hiredis/hiredis_ssl.h +127 -0
  30. data/vendor/hiredis/net.c +612 -0
  31. data/vendor/hiredis/net.h +56 -0
  32. data/vendor/hiredis/read.c +739 -0
  33. data/vendor/hiredis/read.h +129 -0
  34. data/vendor/hiredis/sds.c +1289 -0
  35. data/vendor/hiredis/sds.h +278 -0
  36. data/vendor/hiredis/sdsalloc.h +44 -0
  37. data/vendor/hiredis/sockcompat.c +248 -0
  38. data/vendor/hiredis/sockcompat.h +92 -0
  39. data/vendor/hiredis/ssl.c +526 -0
  40. data/vendor/hiredis/test.c +1387 -0
  41. data/vendor/hiredis/win32.h +56 -0
  42. metadata +128 -0
@@ -0,0 +1,183 @@
1
+ require "hiredis/version"
2
+
3
+ module Hiredis
4
+ module Ruby
5
+ class Reader
6
+
7
+ def initialize
8
+ @buffer = Buffer.new
9
+ @task = Task.new(@buffer)
10
+ end
11
+
12
+ def feed(data)
13
+ @buffer << data
14
+ end
15
+
16
+ def gets
17
+ reply = @task.process
18
+ @buffer.discard!
19
+ reply
20
+ end
21
+
22
+ protected
23
+
24
+ class Task
25
+
26
+ # Use lookup table to map reply types to methods
27
+ method_index = {}
28
+ method_index[?-] = :process_error_reply
29
+ method_index[?+] = :process_status_reply
30
+ method_index[?:] = :process_integer_reply
31
+ method_index[?$] = :process_bulk_reply
32
+ method_index[?*] = :process_multi_bulk_reply
33
+ METHOD_INDEX = method_index.freeze
34
+
35
+ attr_reader :parent
36
+ attr_reader :depth
37
+ attr_accessor :multi_bulk
38
+
39
+ def initialize(buffer, parent = nil, depth = 0)
40
+ @buffer, @parent, @depth = buffer, parent, depth
41
+ end
42
+
43
+ # Note: task depth is not checked.
44
+ def child
45
+ @child ||= Task.new(@buffer, self, depth + 1)
46
+ end
47
+
48
+ def root
49
+ parent ? parent.root : self
50
+ end
51
+
52
+ def reset!
53
+ @line = @type = @multi_bulk = nil
54
+ end
55
+
56
+ def process_error_reply
57
+ RuntimeError.new(@line)
58
+ end
59
+
60
+ def process_status_reply
61
+ @line
62
+ end
63
+
64
+ def process_integer_reply
65
+ @line.to_i
66
+ end
67
+
68
+ def process_bulk_reply
69
+ bulk_length = @line.to_i
70
+ return nil if bulk_length < 0
71
+
72
+ # Caught by caller function when false
73
+ @buffer.read(bulk_length, 2)
74
+ end
75
+
76
+ def process_multi_bulk_reply
77
+ multi_bulk_length = @line.to_i
78
+
79
+ if multi_bulk_length > 0
80
+ @multi_bulk ||= []
81
+
82
+ # We know the multi bulk is not complete when this path is taken.
83
+ while (element = child.process) != false
84
+ @multi_bulk << element
85
+ return @multi_bulk if @multi_bulk.length == multi_bulk_length
86
+ end
87
+
88
+ false
89
+ elsif multi_bulk_length == 0
90
+ []
91
+ else
92
+ nil
93
+ end
94
+ end
95
+
96
+ def process_protocol_error
97
+ raise "Protocol error"
98
+ end
99
+
100
+ def process
101
+ @line ||= @buffer.read_line
102
+ return false if @line == false
103
+
104
+ @type ||= @line.slice!(0)
105
+ reply = send(METHOD_INDEX[@type] || :process_protocol_error)
106
+
107
+ reset! if reply != false
108
+ reply
109
+ end
110
+ end
111
+
112
+ class Buffer
113
+
114
+ CRLF = "\r\n".freeze
115
+
116
+ def initialize
117
+ @buffer = ""
118
+ @length = @pos = 0
119
+ end
120
+
121
+ def <<(data)
122
+ @length += data.length
123
+ @buffer << data
124
+ end
125
+
126
+ def length
127
+ @length
128
+ end
129
+
130
+ def empty?
131
+ @length == 0
132
+ end
133
+
134
+ def discard!
135
+ if @length == 0
136
+ @buffer = ""
137
+ @length = @pos = 0
138
+ else
139
+ if @pos >= 1024
140
+ @buffer.slice!(0, @pos)
141
+ @length -= @pos
142
+ @pos = 0
143
+ end
144
+ end
145
+ end
146
+
147
+ def read(bytes, skip = 0)
148
+ start = @pos
149
+ stop = start + bytes + skip
150
+ return false if @length < stop
151
+
152
+ @pos = stop
153
+ force_encoding @buffer[start, bytes]
154
+ end
155
+
156
+ def read_line
157
+ start = @pos
158
+ stop = @buffer.index(CRLF, @pos)
159
+ return false unless stop
160
+
161
+ @pos = stop + 2 # include CRLF
162
+ force_encoding @buffer[start, stop - start]
163
+ end
164
+
165
+ private
166
+
167
+ if "".respond_to?(:force_encoding)
168
+
169
+ def force_encoding(str)
170
+ str.force_encoding(Encoding.default_external)
171
+ end
172
+
173
+ else
174
+
175
+ def force_encoding(str)
176
+ str
177
+ end
178
+
179
+ end
180
+ end
181
+ end
182
+ end
183
+ end
@@ -0,0 +1,3 @@
1
+ module Hiredis
2
+ VERSION = "0.6.3"
3
+ end
data/lib/hiredis.rb ADDED
@@ -0,0 +1,2 @@
1
+ require "hiredis/version"
2
+ require "hiredis/connection"
@@ -0,0 +1,29 @@
1
+ Copyright (c) 2009-2011, Salvatore Sanfilippo <antirez at gmail dot com>
2
+ Copyright (c) 2010-2011, Pieter Noordhuis <pcnoordhuis at gmail dot com>
3
+
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ * Redistributions of source code must retain the above copyright notice,
10
+ this list of conditions and the following disclaimer.
11
+
12
+ * Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ * Neither the name of Redis nor the names of its contributors may be used
17
+ to endorse or promote products derived from this software without specific
18
+ prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
24
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
27
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,308 @@
1
+ # Hiredis Makefile
2
+ # Copyright (C) 2010-2011 Salvatore Sanfilippo <antirez at gmail dot com>
3
+ # Copyright (C) 2010-2011 Pieter Noordhuis <pcnoordhuis at gmail dot com>
4
+ # This file is released under the BSD license, see the COPYING file
5
+
6
+ OBJ=alloc.o net.o hiredis.o sds.o async.o read.o sockcompat.o
7
+ SSL_OBJ=ssl.o
8
+ EXAMPLES=hiredis-example hiredis-example-libevent hiredis-example-libev hiredis-example-glib hiredis-example-push
9
+ ifeq ($(USE_SSL),1)
10
+ EXAMPLES+=hiredis-example-ssl hiredis-example-libevent-ssl
11
+ endif
12
+ TESTS=hiredis-test
13
+ LIBNAME=libhiredis
14
+ PKGCONFNAME=hiredis.pc
15
+ SSL_LIBNAME=libhiredis_ssl
16
+ SSL_PKGCONFNAME=hiredis_ssl.pc
17
+
18
+ HIREDIS_MAJOR=$(shell grep HIREDIS_MAJOR hiredis.h | awk '{print $$3}')
19
+ HIREDIS_MINOR=$(shell grep HIREDIS_MINOR hiredis.h | awk '{print $$3}')
20
+ HIREDIS_PATCH=$(shell grep HIREDIS_PATCH hiredis.h | awk '{print $$3}')
21
+ HIREDIS_SONAME=$(shell grep HIREDIS_SONAME hiredis.h | awk '{print $$3}')
22
+
23
+ # Installation related variables and target
24
+ PREFIX?=/usr/local
25
+ INCLUDE_PATH?=include/hiredis
26
+ LIBRARY_PATH?=lib
27
+ PKGCONF_PATH?=pkgconfig
28
+ INSTALL_INCLUDE_PATH= $(DESTDIR)$(PREFIX)/$(INCLUDE_PATH)
29
+ INSTALL_LIBRARY_PATH= $(DESTDIR)$(PREFIX)/$(LIBRARY_PATH)
30
+ INSTALL_PKGCONF_PATH= $(INSTALL_LIBRARY_PATH)/$(PKGCONF_PATH)
31
+
32
+ # redis-server configuration used for testing
33
+ REDIS_PORT=56379
34
+ REDIS_SERVER=redis-server
35
+ define REDIS_TEST_CONFIG
36
+ daemonize yes
37
+ pidfile /tmp/hiredis-test-redis.pid
38
+ port $(REDIS_PORT)
39
+ bind 127.0.0.1
40
+ unixsocket /tmp/hiredis-test-redis.sock
41
+ endef
42
+ export REDIS_TEST_CONFIG
43
+
44
+ # Fallback to gcc when $CC is not in $PATH.
45
+ CC:=$(shell sh -c 'type $${CC%% *} >/dev/null 2>/dev/null && echo $(CC) || echo gcc')
46
+ CXX:=$(shell sh -c 'type $${CXX%% *} >/dev/null 2>/dev/null && echo $(CXX) || echo g++')
47
+ OPTIMIZATION?=-O3
48
+ WARNINGS=-Wall -W -Wstrict-prototypes -Wwrite-strings -Wno-missing-field-initializers
49
+ DEBUG_FLAGS?= -g -ggdb
50
+ REAL_CFLAGS=$(OPTIMIZATION) -fPIC $(CPPFLAGS) $(CFLAGS) $(WARNINGS) $(DEBUG_FLAGS)
51
+ REAL_LDFLAGS=$(LDFLAGS)
52
+
53
+ DYLIBSUFFIX=so
54
+ STLIBSUFFIX=a
55
+ DYLIB_MINOR_NAME=$(LIBNAME).$(DYLIBSUFFIX).$(HIREDIS_SONAME)
56
+ DYLIB_MAJOR_NAME=$(LIBNAME).$(DYLIBSUFFIX).$(HIREDIS_MAJOR)
57
+ DYLIBNAME=$(LIBNAME).$(DYLIBSUFFIX)
58
+
59
+ DYLIB_MAKE_CMD=$(CC) -shared -Wl,-soname,$(DYLIB_MINOR_NAME)
60
+ STLIBNAME=$(LIBNAME).$(STLIBSUFFIX)
61
+ STLIB_MAKE_CMD=$(AR) rcs
62
+
63
+ SSL_DYLIB_MINOR_NAME=$(SSL_LIBNAME).$(DYLIBSUFFIX).$(HIREDIS_SONAME)
64
+ SSL_DYLIB_MAJOR_NAME=$(SSL_LIBNAME).$(DYLIBSUFFIX).$(HIREDIS_MAJOR)
65
+ SSL_DYLIBNAME=$(SSL_LIBNAME).$(DYLIBSUFFIX)
66
+ SSL_STLIBNAME=$(SSL_LIBNAME).$(STLIBSUFFIX)
67
+ SSL_DYLIB_MAKE_CMD=$(CC) -shared -Wl,-soname,$(SSL_DYLIB_MINOR_NAME)
68
+
69
+ # Platform-specific overrides
70
+ uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
71
+
72
+ USE_SSL?=0
73
+
74
+ # This is required for test.c only
75
+ ifeq ($(USE_SSL),1)
76
+ CFLAGS+=-DHIREDIS_TEST_SSL
77
+ endif
78
+
79
+ ifeq ($(uname_S),Linux)
80
+ SSL_LDFLAGS=-lssl -lcrypto
81
+ else
82
+ OPENSSL_PREFIX?=/usr/local/opt/openssl
83
+ CFLAGS+=-I$(OPENSSL_PREFIX)/include
84
+ SSL_LDFLAGS+=-L$(OPENSSL_PREFIX)/lib -lssl -lcrypto
85
+ endif
86
+
87
+ ifeq ($(uname_S),SunOS)
88
+ IS_SUN_CC=$(shell sh -c '$(CC) -V 2>&1 |egrep -i -c "sun|studio"')
89
+ ifeq ($(IS_SUN_CC),1)
90
+ SUN_SHARED_FLAG=-G
91
+ else
92
+ SUN_SHARED_FLAG=-shared
93
+ endif
94
+ REAL_LDFLAGS+= -ldl -lnsl -lsocket
95
+ DYLIB_MAKE_CMD=$(CC) $(SUN_SHARED_FLAG) -o $(DYLIBNAME) -h $(DYLIB_MINOR_NAME) $(LDFLAGS)
96
+ SSL_DYLIB_MAKE_CMD=$(CC) $(SUN_SHARED_FLAG) -o $(SSL_DYLIBNAME) -h $(SSL_DYLIB_MINOR_NAME) $(LDFLAGS) $(SSL_LDFLAGS)
97
+ endif
98
+ ifeq ($(uname_S),Darwin)
99
+ DYLIBSUFFIX=dylib
100
+ DYLIB_MINOR_NAME=$(LIBNAME).$(HIREDIS_SONAME).$(DYLIBSUFFIX)
101
+ DYLIB_MAKE_CMD=$(CC) -dynamiclib -Wl,-install_name,$(PREFIX)/$(LIBRARY_PATH)/$(DYLIB_MINOR_NAME) -o $(DYLIBNAME) $(LDFLAGS)
102
+ SSL_DYLIB_MAKE_CMD=$(CC) -dynamiclib -Wl,-install_name,$(PREFIX)/$(LIBRARY_PATH)/$(SSL_DYLIB_MINOR_NAME) -o $(SSL_DYLIBNAME) $(LDFLAGS) $(SSL_LDFLAGS)
103
+ DYLIB_PLUGIN=-Wl,-undefined -Wl,dynamic_lookup
104
+ endif
105
+
106
+ all: $(DYLIBNAME) $(STLIBNAME) hiredis-test $(PKGCONFNAME)
107
+ ifeq ($(USE_SSL),1)
108
+ all: $(SSL_DYLIBNAME) $(SSL_STLIBNAME) $(SSL_PKGCONFNAME)
109
+ endif
110
+
111
+ # Deps (use make dep to generate this)
112
+ alloc.o: alloc.c fmacros.h alloc.h
113
+ async.o: async.c fmacros.h alloc.h async.h hiredis.h read.h sds.h net.h dict.c dict.h win32.h async_private.h
114
+ dict.o: dict.c fmacros.h alloc.h dict.h
115
+ hiredis.o: hiredis.c fmacros.h hiredis.h read.h sds.h alloc.h net.h async.h win32.h
116
+ net.o: net.c fmacros.h net.h hiredis.h read.h sds.h alloc.h sockcompat.h win32.h
117
+ read.o: read.c fmacros.h alloc.h read.h sds.h win32.h
118
+ sds.o: sds.c sds.h sdsalloc.h alloc.h
119
+ sockcompat.o: sockcompat.c sockcompat.h
120
+ ssl.o: ssl.c hiredis.h read.h sds.h alloc.h async.h win32.h async_private.h
121
+ test.o: test.c fmacros.h hiredis.h read.h sds.h alloc.h net.h sockcompat.h win32.h
122
+
123
+ $(DYLIBNAME): $(OBJ)
124
+ $(DYLIB_MAKE_CMD) -o $(DYLIBNAME) $(OBJ) $(REAL_LDFLAGS)
125
+
126
+ $(STLIBNAME): $(OBJ)
127
+ $(STLIB_MAKE_CMD) $(STLIBNAME) $(OBJ)
128
+
129
+ $(SSL_DYLIBNAME): $(SSL_OBJ)
130
+ $(SSL_DYLIB_MAKE_CMD) $(DYLIB_PLUGIN) -o $(SSL_DYLIBNAME) $(SSL_OBJ) $(REAL_LDFLAGS) $(LDFLAGS) $(SSL_LDFLAGS)
131
+
132
+ $(SSL_STLIBNAME): $(SSL_OBJ)
133
+ $(STLIB_MAKE_CMD) $(SSL_STLIBNAME) $(SSL_OBJ)
134
+
135
+ dynamic: $(DYLIBNAME)
136
+ static: $(STLIBNAME)
137
+ ifeq ($(USE_SSL),1)
138
+ dynamic: $(SSL_DYLIBNAME)
139
+ static: $(SSL_STLIBNAME)
140
+ endif
141
+
142
+ # Binaries:
143
+ hiredis-example-libevent: examples/example-libevent.c adapters/libevent.h $(STLIBNAME)
144
+ $(CC) -o examples/$@ $(REAL_CFLAGS) -I. $< -levent $(STLIBNAME) $(REAL_LDFLAGS)
145
+
146
+ hiredis-example-libevent-ssl: examples/example-libevent-ssl.c adapters/libevent.h $(STLIBNAME) $(SSL_STLIBNAME)
147
+ $(CC) -o examples/$@ $(REAL_CFLAGS) -I. $< -levent $(STLIBNAME) $(SSL_STLIBNAME) $(REAL_LDFLAGS) $(SSL_LDFLAGS)
148
+
149
+ hiredis-example-libev: examples/example-libev.c adapters/libev.h $(STLIBNAME)
150
+ $(CC) -o examples/$@ $(REAL_CFLAGS) -I. $< -lev $(STLIBNAME) $(REAL_LDFLAGS)
151
+
152
+ hiredis-example-glib: examples/example-glib.c adapters/glib.h $(STLIBNAME)
153
+ $(CC) -o examples/$@ $(REAL_CFLAGS) -I. $< $(shell pkg-config --cflags --libs glib-2.0) $(STLIBNAME) $(REAL_LDFLAGS)
154
+
155
+ hiredis-example-ivykis: examples/example-ivykis.c adapters/ivykis.h $(STLIBNAME)
156
+ $(CC) -o examples/$@ $(REAL_CFLAGS) -I. $< -livykis $(STLIBNAME) $(REAL_LDFLAGS)
157
+
158
+ hiredis-example-macosx: examples/example-macosx.c adapters/macosx.h $(STLIBNAME)
159
+ $(CC) -o examples/$@ $(REAL_CFLAGS) -I. $< -framework CoreFoundation $(STLIBNAME) $(REAL_LDFLAGS)
160
+
161
+ hiredis-example-ssl: examples/example-ssl.c $(STLIBNAME) $(SSL_STLIBNAME)
162
+ $(CC) -o examples/$@ $(REAL_CFLAGS) -I. $< $(STLIBNAME) $(SSL_STLIBNAME) $(REAL_LDFLAGS) $(SSL_LDFLAGS)
163
+
164
+
165
+ ifndef AE_DIR
166
+ hiredis-example-ae:
167
+ @echo "Please specify AE_DIR (e.g. <redis repository>/src)"
168
+ @false
169
+ else
170
+ hiredis-example-ae: examples/example-ae.c adapters/ae.h $(STLIBNAME)
171
+ $(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. -I$(AE_DIR) $< $(AE_DIR)/ae.o $(AE_DIR)/zmalloc.o $(AE_DIR)/../deps/jemalloc/lib/libjemalloc.a -pthread $(STLIBNAME)
172
+ endif
173
+
174
+ ifndef LIBUV_DIR
175
+ hiredis-example-libuv:
176
+ @echo "Please specify LIBUV_DIR (e.g. ../libuv/)"
177
+ @false
178
+ else
179
+ hiredis-example-libuv: examples/example-libuv.c adapters/libuv.h $(STLIBNAME)
180
+ $(CC) -o examples/$@ $(REAL_CFLAGS) -I. -I$(LIBUV_DIR)/include $< $(LIBUV_DIR)/.libs/libuv.a -lpthread -lrt $(STLIBNAME) $(REAL_LDFLAGS)
181
+ endif
182
+
183
+ ifeq ($(and $(QT_MOC),$(QT_INCLUDE_DIR),$(QT_LIBRARY_DIR)),)
184
+ hiredis-example-qt:
185
+ @echo "Please specify QT_MOC, QT_INCLUDE_DIR AND QT_LIBRARY_DIR"
186
+ @false
187
+ else
188
+ hiredis-example-qt: examples/example-qt.cpp adapters/qt.h $(STLIBNAME)
189
+ $(QT_MOC) adapters/qt.h -I. -I$(QT_INCLUDE_DIR) -I$(QT_INCLUDE_DIR)/QtCore | \
190
+ $(CXX) -x c++ -o qt-adapter-moc.o -c - $(REAL_CFLAGS) -I. -I$(QT_INCLUDE_DIR) -I$(QT_INCLUDE_DIR)/QtCore
191
+ $(QT_MOC) examples/example-qt.h -I. -I$(QT_INCLUDE_DIR) -I$(QT_INCLUDE_DIR)/QtCore | \
192
+ $(CXX) -x c++ -o qt-example-moc.o -c - $(REAL_CFLAGS) -I. -I$(QT_INCLUDE_DIR) -I$(QT_INCLUDE_DIR)/QtCore
193
+ $(CXX) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. -I$(QT_INCLUDE_DIR) -I$(QT_INCLUDE_DIR)/QtCore -L$(QT_LIBRARY_DIR) qt-adapter-moc.o qt-example-moc.o $< -pthread $(STLIBNAME) -lQtCore
194
+ endif
195
+
196
+ hiredis-example: examples/example.c $(STLIBNAME)
197
+ $(CC) -o examples/$@ $(REAL_CFLAGS) -I. $< $(STLIBNAME) $(REAL_LDFLAGS)
198
+
199
+ hiredis-example-push: examples/example-push.c $(STLIBNAME)
200
+ $(CC) -o examples/$@ $(REAL_CFLAGS) -I. $< $(STLIBNAME) $(REAL_LDFLAGS)
201
+
202
+ examples: $(EXAMPLES)
203
+
204
+ TEST_LIBS = $(STLIBNAME)
205
+ ifeq ($(USE_SSL),1)
206
+ TEST_LIBS += $(SSL_STLIBNAME)
207
+ TEST_LDFLAGS = $(SSL_LDFLAGS) -lssl -lcrypto -lpthread
208
+ endif
209
+
210
+ hiredis-test: test.o $(TEST_LIBS)
211
+ $(CC) -o $@ $(REAL_CFLAGS) -I. $^ $(REAL_LDFLAGS) $(TEST_LDFLAGS)
212
+
213
+ hiredis-%: %.o $(STLIBNAME)
214
+ $(CC) $(REAL_CFLAGS) -o $@ $< $(TEST_LIBS) $(REAL_LDFLAGS)
215
+
216
+ test: hiredis-test
217
+ ./hiredis-test
218
+
219
+ check: hiredis-test
220
+ TEST_SSL=$(USE_SSL) ./test.sh
221
+
222
+ .c.o:
223
+ $(CC) -std=c99 -pedantic -c $(REAL_CFLAGS) $<
224
+
225
+ clean:
226
+ rm -rf $(DYLIBNAME) $(STLIBNAME) $(SSL_DYLIBNAME) $(SSL_STLIBNAME) $(TESTS) $(PKGCONFNAME) examples/hiredis-example* *.o *.gcda *.gcno *.gcov
227
+
228
+ dep:
229
+ $(CC) $(CPPFLAGS) $(CFLAGS) -MM *.c
230
+
231
+ INSTALL?= cp -pPR
232
+
233
+ $(PKGCONFNAME): hiredis.h
234
+ @echo "Generating $@ for pkgconfig..."
235
+ @echo prefix=$(PREFIX) > $@
236
+ @echo exec_prefix=\$${prefix} >> $@
237
+ @echo libdir=$(PREFIX)/$(LIBRARY_PATH) >> $@
238
+ @echo includedir=$(PREFIX)/$(INCLUDE_PATH) >> $@
239
+ @echo >> $@
240
+ @echo Name: hiredis >> $@
241
+ @echo Description: Minimalistic C client library for Redis. >> $@
242
+ @echo Version: $(HIREDIS_MAJOR).$(HIREDIS_MINOR).$(HIREDIS_PATCH) >> $@
243
+ @echo Libs: -L\$${libdir} -lhiredis >> $@
244
+ @echo Cflags: -I\$${includedir} -D_FILE_OFFSET_BITS=64 >> $@
245
+
246
+ $(SSL_PKGCONFNAME): hiredis_ssl.h
247
+ @echo "Generating $@ for pkgconfig..."
248
+ @echo prefix=$(PREFIX) > $@
249
+ @echo exec_prefix=\$${prefix} >> $@
250
+ @echo libdir=$(PREFIX)/$(LIBRARY_PATH) >> $@
251
+ @echo includedir=$(PREFIX)/$(INCLUDE_PATH) >> $@
252
+ @echo >> $@
253
+ @echo Name: hiredis_ssl >> $@
254
+ @echo Description: SSL Support for hiredis. >> $@
255
+ @echo Version: $(HIREDIS_MAJOR).$(HIREDIS_MINOR).$(HIREDIS_PATCH) >> $@
256
+ @echo Requires: hiredis >> $@
257
+ @echo Libs: -L\$${libdir} -lhiredis_ssl >> $@
258
+ @echo Libs.private: -lssl -lcrypto >> $@
259
+
260
+ install: $(DYLIBNAME) $(STLIBNAME) $(PKGCONFNAME)
261
+ mkdir -p $(INSTALL_INCLUDE_PATH) $(INSTALL_INCLUDE_PATH)/adapters $(INSTALL_LIBRARY_PATH)
262
+ $(INSTALL) hiredis.h async.h read.h sds.h alloc.h $(INSTALL_INCLUDE_PATH)
263
+ $(INSTALL) adapters/*.h $(INSTALL_INCLUDE_PATH)/adapters
264
+ $(INSTALL) $(DYLIBNAME) $(INSTALL_LIBRARY_PATH)/$(DYLIB_MINOR_NAME)
265
+ cd $(INSTALL_LIBRARY_PATH) && ln -sf $(DYLIB_MINOR_NAME) $(DYLIBNAME)
266
+ $(INSTALL) $(STLIBNAME) $(INSTALL_LIBRARY_PATH)
267
+ mkdir -p $(INSTALL_PKGCONF_PATH)
268
+ $(INSTALL) $(PKGCONFNAME) $(INSTALL_PKGCONF_PATH)
269
+
270
+ ifeq ($(USE_SSL),1)
271
+ install: install-ssl
272
+
273
+ install-ssl: $(SSL_DYLIBNAME) $(SSL_STLIBNAME) $(SSL_PKGCONFNAME)
274
+ mkdir -p $(INSTALL_INCLUDE_PATH) $(INSTALL_LIBRARY_PATH)
275
+ $(INSTALL) hiredis_ssl.h $(INSTALL_INCLUDE_PATH)
276
+ $(INSTALL) $(SSL_DYLIBNAME) $(INSTALL_LIBRARY_PATH)/$(SSL_DYLIB_MINOR_NAME)
277
+ cd $(INSTALL_LIBRARY_PATH) && ln -sf $(SSL_DYLIB_MINOR_NAME) $(SSL_DYLIBNAME)
278
+ $(INSTALL) $(SSL_STLIBNAME) $(INSTALL_LIBRARY_PATH)
279
+ mkdir -p $(INSTALL_PKGCONF_PATH)
280
+ $(INSTALL) $(SSL_PKGCONFNAME) $(INSTALL_PKGCONF_PATH)
281
+ endif
282
+
283
+ 32bit:
284
+ @echo ""
285
+ @echo "WARNING: if this fails under Linux you probably need to install libc6-dev-i386"
286
+ @echo ""
287
+ $(MAKE) CFLAGS="-m32" LDFLAGS="-m32"
288
+
289
+ 32bit-vars:
290
+ $(eval CFLAGS=-m32)
291
+ $(eval LDFLAGS=-m32)
292
+
293
+ gprof:
294
+ $(MAKE) CFLAGS="-pg" LDFLAGS="-pg"
295
+
296
+ gcov:
297
+ $(MAKE) CFLAGS="-fprofile-arcs -ftest-coverage" LDFLAGS="-fprofile-arcs"
298
+
299
+ coverage: gcov
300
+ make check
301
+ mkdir -p tmp/lcov
302
+ lcov -d . -c -o tmp/lcov/hiredis.info
303
+ genhtml --legend -o tmp/lcov/report tmp/lcov/hiredis.info
304
+
305
+ noopt:
306
+ $(MAKE) OPTIMIZATION=""
307
+
308
+ .PHONY: all test check clean dep install 32bit 32bit-vars gprof gcov noopt
@@ -0,0 +1,86 @@
1
+ /*
2
+ * Copyright (c) 2020, Michael Grunder <michael dot grunder at gmail dot com>
3
+ *
4
+ * All rights reserved.
5
+ *
6
+ * Redistribution and use in source and binary forms, with or without
7
+ * modification, are permitted provided that the following conditions are met:
8
+ *
9
+ * * Redistributions of source code must retain the above copyright notice,
10
+ * this list of conditions and the following disclaimer.
11
+ * * Redistributions in binary form must reproduce the above copyright
12
+ * notice, this list of conditions and the following disclaimer in the
13
+ * documentation and/or other materials provided with the distribution.
14
+ * * Neither the name of Redis nor the names of its contributors may be used
15
+ * to endorse or promote products derived from this software without
16
+ * specific prior written permission.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
+ * POSSIBILITY OF SUCH DAMAGE.
29
+ */
30
+
31
+ #include "fmacros.h"
32
+ #include "alloc.h"
33
+ #include <string.h>
34
+ #include <stdlib.h>
35
+
36
+ hiredisAllocFuncs hiredisAllocFns = {
37
+ .mallocFn = malloc,
38
+ .callocFn = calloc,
39
+ .reallocFn = realloc,
40
+ .strdupFn = strdup,
41
+ .freeFn = free,
42
+ };
43
+
44
+ /* Override hiredis' allocators with ones supplied by the user */
45
+ hiredisAllocFuncs hiredisSetAllocators(hiredisAllocFuncs *override) {
46
+ hiredisAllocFuncs orig = hiredisAllocFns;
47
+
48
+ hiredisAllocFns = *override;
49
+
50
+ return orig;
51
+ }
52
+
53
+ /* Reset allocators to use libc defaults */
54
+ void hiredisResetAllocators(void) {
55
+ hiredisAllocFns = (hiredisAllocFuncs) {
56
+ .mallocFn = malloc,
57
+ .callocFn = calloc,
58
+ .reallocFn = realloc,
59
+ .strdupFn = strdup,
60
+ .freeFn = free,
61
+ };
62
+ }
63
+
64
+ #ifdef _WIN32
65
+
66
+ void *hi_malloc(size_t size) {
67
+ return hiredisAllocFns.mallocFn(size);
68
+ }
69
+
70
+ void *hi_calloc(size_t nmemb, size_t size) {
71
+ return hiredisAllocFns.callocFn(nmemb, size);
72
+ }
73
+
74
+ void *hi_realloc(void *ptr, size_t size) {
75
+ return hiredisAllocFns.reallocFn(ptr, size);
76
+ }
77
+
78
+ char *hi_strdup(const char *str) {
79
+ return hiredisAllocFns.strdupFn(str);
80
+ }
81
+
82
+ void hi_free(void *ptr) {
83
+ hiredisAllocFns.freeFn(ptr);
84
+ }
85
+
86
+ #endif
@@ -0,0 +1,91 @@
1
+ /*
2
+ * Copyright (c) 2020, Michael Grunder <michael dot grunder at gmail dot com>
3
+ *
4
+ * All rights reserved.
5
+ *
6
+ * Redistribution and use in source and binary forms, with or without
7
+ * modification, are permitted provided that the following conditions are met:
8
+ *
9
+ * * Redistributions of source code must retain the above copyright notice,
10
+ * this list of conditions and the following disclaimer.
11
+ * * Redistributions in binary form must reproduce the above copyright
12
+ * notice, this list of conditions and the following disclaimer in the
13
+ * documentation and/or other materials provided with the distribution.
14
+ * * Neither the name of Redis nor the names of its contributors may be used
15
+ * to endorse or promote products derived from this software without
16
+ * specific prior written permission.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
+ * POSSIBILITY OF SUCH DAMAGE.
29
+ */
30
+
31
+ #ifndef HIREDIS_ALLOC_H
32
+ #define HIREDIS_ALLOC_H
33
+
34
+ #include <stddef.h> /* for size_t */
35
+
36
+ #ifdef __cplusplus
37
+ extern "C" {
38
+ #endif
39
+
40
+ /* Structure pointing to our actually configured allocators */
41
+ typedef struct hiredisAllocFuncs {
42
+ void *(*mallocFn)(size_t);
43
+ void *(*callocFn)(size_t,size_t);
44
+ void *(*reallocFn)(void*,size_t);
45
+ char *(*strdupFn)(const char*);
46
+ void (*freeFn)(void*);
47
+ } hiredisAllocFuncs;
48
+
49
+ hiredisAllocFuncs hiredisSetAllocators(hiredisAllocFuncs *ha);
50
+ void hiredisResetAllocators(void);
51
+
52
+ #ifndef _WIN32
53
+
54
+ /* Hiredis' configured allocator function pointer struct */
55
+ extern hiredisAllocFuncs hiredisAllocFns;
56
+
57
+ static inline void *hi_malloc(size_t size) {
58
+ return hiredisAllocFns.mallocFn(size);
59
+ }
60
+
61
+ static inline void *hi_calloc(size_t nmemb, size_t size) {
62
+ return hiredisAllocFns.callocFn(nmemb, size);
63
+ }
64
+
65
+ static inline void *hi_realloc(void *ptr, size_t size) {
66
+ return hiredisAllocFns.reallocFn(ptr, size);
67
+ }
68
+
69
+ static inline char *hi_strdup(const char *str) {
70
+ return hiredisAllocFns.strdupFn(str);
71
+ }
72
+
73
+ static inline void hi_free(void *ptr) {
74
+ hiredisAllocFns.freeFn(ptr);
75
+ }
76
+
77
+ #else
78
+
79
+ void *hi_malloc(size_t size);
80
+ void *hi_calloc(size_t nmemb, size_t size);
81
+ void *hi_realloc(void *ptr, size_t size);
82
+ char *hi_strdup(const char *str);
83
+ void hi_free(void *ptr);
84
+
85
+ #endif
86
+
87
+ #ifdef __cplusplus
88
+ }
89
+ #endif
90
+
91
+ #endif /* HIREDIS_ALLOC_H */