yong-stropheruby 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/ext/thread.c ADDED
@@ -0,0 +1,119 @@
1
+ /* thread.c
2
+ ** strophe XMPP client library -- thread abstraction
3
+ **
4
+ ** Copyright (C) 2005-2008 OGG, LLC. All rights reserved.
5
+ **
6
+ ** This software is provided AS-IS with no warranty, either express
7
+ ** or implied.
8
+ **
9
+ ** This software is distributed under license and may not be copied,
10
+ ** modified or distributed except as expressly authorized under the
11
+ ** terms of the license contained in the file LICENSE.txt in this
12
+ ** distribution.
13
+ */
14
+
15
+ /** @file
16
+ * Thread absraction.
17
+ */
18
+
19
+ #include <stdio.h>
20
+ #include <stdlib.h>
21
+
22
+ #ifdef _WIN32
23
+ #define WIN32_LEAN_AND_MEAN
24
+ #include <windows.h>
25
+ #else
26
+ #include <pthread.h>
27
+ #endif
28
+
29
+ #include "strophe.h"
30
+ #include "common.h"
31
+ #include "thread.h"
32
+
33
+ struct _mutex_t {
34
+ const xmpp_ctx_t *ctx;
35
+
36
+ #ifdef _WIN32
37
+ HANDLE mutex;
38
+ #else
39
+ pthread_mutex_t *mutex;
40
+ #endif
41
+ };
42
+
43
+ /* mutex functions */
44
+
45
+ mutex_t *mutex_create(const xmpp_ctx_t * ctx)
46
+ {
47
+ mutex_t *mutex;
48
+
49
+ mutex = xmpp_alloc(ctx, sizeof(mutex_t));
50
+ if (mutex) {
51
+ mutex->ctx = ctx;
52
+ #ifdef _WIN32
53
+ mutex->mutex = CreateMutex(NULL, FALSE, NULL);
54
+ #else
55
+ mutex->mutex = xmpp_alloc(ctx, sizeof(pthread_mutex_t));
56
+ if (mutex->mutex)
57
+ if (pthread_mutex_init(mutex->mutex, NULL) != 0) {
58
+ xmpp_free(ctx, mutex->mutex);
59
+ mutex->mutex = NULL;
60
+ }
61
+ #endif
62
+ if (!mutex->mutex) {
63
+ xmpp_free(ctx, mutex);
64
+ mutex = NULL;
65
+ }
66
+ }
67
+
68
+ return mutex;
69
+ }
70
+
71
+ int mutex_destroy(mutex_t *mutex)
72
+ {
73
+ int ret = 1;
74
+ const xmpp_ctx_t *ctx;
75
+
76
+ #ifdef _WIN32
77
+ if (mutex->mutex)
78
+ ret = CloseHandle(mutex->mutex);
79
+ #else
80
+ if (mutex->mutex)
81
+ ret = pthread_mutex_destroy(mutex->mutex) == 0;
82
+ #endif
83
+ ctx = mutex->ctx;
84
+ xmpp_free(ctx, mutex);
85
+
86
+ return ret;
87
+ }
88
+
89
+ int mutex_lock(mutex_t *mutex)
90
+ {
91
+ int ret;
92
+
93
+ #ifdef _WIN32
94
+ ret = WaitForSingleObject(mutex->mutex, INFINITE) == 0;
95
+ #else
96
+ ret = pthread_mutex_lock(mutex->mutex) == 0;
97
+ #endif
98
+
99
+ return ret;
100
+ }
101
+
102
+ int mutex_trylock(mutex_t *mutex)
103
+ {
104
+ /* TODO */
105
+ return 0;
106
+ }
107
+
108
+ int mutex_unlock(mutex_t *mutex)
109
+ {
110
+ int ret;
111
+
112
+ #ifdef _WIN32
113
+ ret = ReleaseMutex(mutex->mutex);
114
+ #else
115
+ ret = pthread_mutex_unlock(mutex->mutex) == 0;
116
+ #endif
117
+
118
+ return ret;
119
+ }
data/ext/thread.h ADDED
@@ -0,0 +1,43 @@
1
+ /* thread.h
2
+ ** strophe XMPP client library -- thread abstraction header
3
+ **
4
+ ** Copyright (C) 2005-2008 OGG, LLC. All rights reserved.
5
+ **
6
+ ** This software is provided AS-IS with no warranty, either express
7
+ ** or implied.
8
+ **
9
+ ** This software is distributed under license and may not be copied,
10
+ ** modified or distributed except as expressly authorized under the
11
+ ** terms of the license contained in the file LICENSE.txt in this
12
+ ** distribution.
13
+ */
14
+
15
+ /** @file
16
+ * Threading abstraction API.
17
+ */
18
+
19
+ #ifndef __LIBSTROPHE_THREAD_H__
20
+ #define __LIBSTROPHE_THREAD_H__
21
+
22
+ #include <stdio.h>
23
+ #include <stdlib.h>
24
+
25
+ #ifdef _WIN32
26
+ #include <windows.h>
27
+ #else
28
+ #include <pthread.h>
29
+ #endif
30
+
31
+ #include "strophe.h"
32
+
33
+ typedef struct _mutex_t mutex_t;
34
+
35
+ /* mutex functions */
36
+
37
+ mutex_t *mutex_create(const xmpp_ctx_t *ctx);
38
+ int mutex_destroy(mutex_t *mutex);
39
+ int mutex_lock(mutex_t *mutex);
40
+ int mutex_trylock(mutex_t *mutex);
41
+ int mutex_unlock(mutex_t *mutex);
42
+
43
+ #endif /* __LIBSTROPHE_THREAD_H__ */
data/ext/tls.h ADDED
@@ -0,0 +1,46 @@
1
+ /* tls.h
2
+ ** strophe XMPP client library -- TLS abstraction header
3
+ **
4
+ ** Copyright (C) 2005-2008 OGG, LLC. All rights reserved.
5
+ **
6
+ ** This software is provided AS-IS with no warranty, either express
7
+ ** or implied.
8
+ **
9
+ ** This software is distributed under license and may not be copied,
10
+ ** modified or distributed except as expressly authorized under the
11
+ ** terms of the license contained in the file LICENSE.txt in this
12
+ ** distribution.
13
+ */
14
+
15
+ /** @file
16
+ * TLS abstraction API.
17
+ */
18
+
19
+ #ifndef __LIBSTROPHE_TLS_H__
20
+ #define __LIBSTROPHE_TLS_H__
21
+
22
+ #include "common.h"
23
+ #include "sock.h"
24
+
25
+ typedef struct _tls tls_t;
26
+
27
+ void tls_initialize(void);
28
+ void tls_shutdown(void);
29
+
30
+ tls_t *tls_new(xmpp_ctx_t *ctx, sock_t sock);
31
+ void tls_free(tls_t *tls);
32
+
33
+ int tls_set_credentials(tls_t *tls, const char *cafilename);
34
+
35
+ int tls_start(tls_t *tls);
36
+ int tls_stop(tls_t *tls);
37
+
38
+ int tls_error(tls_t *tls);
39
+
40
+ int tls_read(tls_t *tls, void * const buff, const size_t len);
41
+ int tls_write(tls_t *tls, const void * const buff, const size_t len);
42
+
43
+ int tls_clear_pending_write(tls_t *tls);
44
+ int tls_is_recoverable(int error);
45
+
46
+ #endif /* __LIBSTROPHE_TLS_H__ */
data/ext/tls_dummy.c ADDED
@@ -0,0 +1,89 @@
1
+ /* tls_dummy.c
2
+ ** strophe XMPP client library -- TLS abstraction dummy impl.
3
+ **
4
+ ** Copyright (C) 2005-2008 OGG, LLC. All rights reserved.
5
+ **
6
+ ** This software is provided AS-IS with no warranty, either express
7
+ ** or implied.
8
+ **
9
+ ** This software is distributed under license and may not be copied,
10
+ ** modified or distributed except as expressly authorized under the
11
+ ** terms of the license contained in the file LICENSE.txt in this
12
+ ** distribution.
13
+ */
14
+
15
+ /** @file
16
+ * TLS dummy implementation.
17
+ */
18
+
19
+ #include "common.h"
20
+ #include "tls.h"
21
+ #include "sock.h"
22
+
23
+ struct _tls {
24
+ xmpp_ctx_t *ctx; /* do we need this? */
25
+ sock_t sock;
26
+ /* we don't implement anything */
27
+ };
28
+
29
+ void tls_initialize(void)
30
+ {
31
+ return;
32
+ }
33
+
34
+ void tls_shutdown(void)
35
+ {
36
+ return;
37
+ }
38
+
39
+ tls_t *tls_new(xmpp_ctx_t *ctx, sock_t sock)
40
+ {
41
+ /* always fail */
42
+ return NULL;
43
+ }
44
+
45
+ void tls_free(tls_t *tls)
46
+ {
47
+ return;
48
+ }
49
+
50
+ int tls_set_credentials(tls_t *tls, const char *cafilename)
51
+ {
52
+ return -1;
53
+ }
54
+
55
+ int tls_start(tls_t *tls)
56
+ {
57
+ return -1;
58
+ }
59
+
60
+ int tls_stop(tls_t *tls)
61
+ {
62
+ return -1;
63
+ }
64
+
65
+ int tls_error(tls_t *tls)
66
+ {
67
+ /* todo: some kind of error polling/dump */
68
+ return 0;
69
+ }
70
+
71
+ int tls_read(tls_t *tls, void * const buff, const size_t len)
72
+ {
73
+ return -1;
74
+ }
75
+
76
+ int tls_write(tls_t *tls, const void * const buff, const size_t len)
77
+ {
78
+ return -1;
79
+ }
80
+
81
+ int tls_clear_pending_write(tls_t *tls)
82
+ {
83
+ return -1;
84
+ }
85
+
86
+ int tls_is_recoverable(int error)
87
+ {
88
+ return 0;
89
+ }
data/ext/util.c ADDED
@@ -0,0 +1,107 @@
1
+ /* util.c
2
+ ** strophe XMPP client library -- various utility functions
3
+ **
4
+ ** Copyright (C) 2005-2008 OGG, LLC. All rights reserved.
5
+ **
6
+ ** This software is provided AS-IS with no warranty, either express
7
+ ** or implied.
8
+ **
9
+ ** This software is distributed under license and may not be copied,
10
+ ** modified or distributed except as expressly authorized under the
11
+ ** terms of the license contained in the file LICENSE.txt in this
12
+ ** distribution.
13
+ */
14
+
15
+ /** @file
16
+ * Utility functions.
17
+ */
18
+
19
+ #include <stdio.h>
20
+ #include <string.h>
21
+
22
+ #ifdef _WIN32
23
+ #include <winsock2.h>
24
+ #else
25
+ #include <sys/time.h>
26
+ #include <time.h>
27
+ #include <stdint.h>
28
+ #endif
29
+
30
+ #include "strophe.h"
31
+ #include "common.h"
32
+ #include "util.h"
33
+
34
+ /** implement our own strdup that uses the ctx allocator */
35
+ /** Duplicate a string.
36
+ * This function replaces the standard strdup library call with a version
37
+ * that uses the Strophe context object's allocator.
38
+ *
39
+ * @param ctx a Strophe context object
40
+ * @param s a string
41
+ *
42
+ * @return a new allocates string with the same data as s or NULL on error
43
+ */
44
+ char *xmpp_strdup(const xmpp_ctx_t * const ctx, const char * const s)
45
+ {
46
+ size_t len;
47
+ char *copy;
48
+
49
+ len = strlen(s);
50
+ copy = xmpp_alloc(ctx, len + 1);
51
+ if (!copy) {
52
+ xmpp_error(ctx, "xmpp", "failed to allocate required memory");
53
+ return NULL;
54
+ }
55
+
56
+ memcpy(copy, s, len + 1);
57
+
58
+ return copy;
59
+ }
60
+
61
+ /** Return an integer based time stamp.
62
+ * This function uses gettimeofday or timeGetTime (on Win32 platforms) to
63
+ * compute an integer based time stamp. This is used internally by the
64
+ * event loop and timed handlers.
65
+ *
66
+ * @return an integer time stamp
67
+ */
68
+ uint64_t time_stamp(void)
69
+ {
70
+ #ifdef _WIN32
71
+ return timeGetTime();
72
+ #else
73
+ struct timeval tv;
74
+
75
+ gettimeofday(&tv, NULL);
76
+
77
+ return (uint64_t)tv.tv_sec * 1000 + (uint64_t)tv.tv_usec / 1000;
78
+ #endif
79
+ }
80
+
81
+ /** Get the time elapsed between two time stamps.
82
+ * This function returns the time elapsed between t1 and t2 by subtracting
83
+ * t1 from t2. If t2 happened before t1, the result will be negative. This
84
+ * function is used internally by the event loop and timed handlers.
85
+ *
86
+ * @param t1 first time stamp
87
+ * @param t2 second time stamp
88
+ *
89
+ * @return number of milliseconds between the stamps
90
+ */
91
+ uint64_t time_elapsed(uint64_t t1, uint64_t t2)
92
+ {
93
+ return (uint64_t)(t2 - t1);
94
+ }
95
+
96
+ /** Disconnect the stream with a memory error.
97
+ * This is a convenience function used internally by various parts of
98
+ * the Strophe library for terminating the connection because of a
99
+ * memory error.
100
+ *
101
+ * @param conn a Strophe connection object
102
+ */
103
+ void disconnect_mem_error(xmpp_conn_t * const conn)
104
+ {
105
+ xmpp_error(conn->ctx, "xmpp", "Memory allocation error");
106
+ xmpp_disconnect(conn);
107
+ }
data/ext/util.h ADDED
@@ -0,0 +1,32 @@
1
+ /* util.h
2
+ ** strophe XMPP client library -- various utility functions
3
+ **
4
+ ** Copyright (C) 2005-2008 OGG, LLC. All rights reserved.
5
+ **
6
+ ** This software is provided AS-IS with no warranty, either express
7
+ ** or implied.
8
+ **
9
+ ** This software is distributed under license and may not be copied,
10
+ ** modified or distributed except as expressly authorized under the
11
+ ** terms of the license contained in the file LICENSE.txt in this
12
+ ** distribution.
13
+ */
14
+
15
+ /** @file
16
+ * Internally used utility functions.
17
+ */
18
+
19
+ #ifndef __LIBSTROPHE_UTIL_H__
20
+ #define __LIBSTROPHE_UTIL_H__
21
+
22
+ #ifndef _WIN32
23
+ #include <stdint.h>
24
+ #else
25
+ #include "ostypes.h"
26
+ #endif
27
+
28
+ /* timing functions */
29
+ uint64_t time_stamp(void);
30
+ uint64_t time_elapsed(uint64_t t1, uint64_t t2);
31
+
32
+ #endif /* __LIBSTROPHE_UTIL_H__ */
@@ -0,0 +1,6 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+
3
+ require 'strophe_ruby.so'
4
+ module StropheRuby
5
+ VERSION = '0.0.1'
6
+ end
@@ -0,0 +1,3 @@
1
+ require 'stringio'
2
+ require 'test/unit'
3
+ require File.dirname(__FILE__) + '/../lib/strophe_ruby'
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestStropheRuby < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def test_truth
9
+ assert true
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ require "test/unit"
2
+
3
+ $:.unshift File.dirname(__FILE__) + "/../ext/strophe_ruby"
4
+
5
+ class TestStropheRubyExtn < Test::Unit::TestCase
6
+ def test_truth
7
+ assert true
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yong-stropheruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ platform: ruby
6
+ authors:
7
+ - "Fran\xC3\xA7ois Lamontagne"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-06 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.8.3
24
+ version:
25
+ description:
26
+ email:
27
+ - flamontagne@gmail.com
28
+ executables: []
29
+
30
+ extensions:
31
+ - ext/extconf.rb
32
+ extra_rdoc_files:
33
+ - History.txt
34
+ - Manifest.txt
35
+ - PostInstall.txt
36
+ files:
37
+ - .autotest
38
+ - History.txt
39
+ - Manifest.txt
40
+ - PostInstall.txt
41
+ - README.rdoc
42
+ - Rakefile
43
+ - ext/md5.c
44
+ - ext/parser.c
45
+ - ext/util.c
46
+ - ext/strophe_ruby.c
47
+ - ext/conn.c
48
+ - ext/ctx.c
49
+ - ext/jid.c
50
+ - ext/handler.c
51
+ - ext/hash.c
52
+ - ext/sasl.c
53
+ - ext/event.c
54
+ - ext/auth.c
55
+ - ext/thread.c
56
+ - ext/stanza.c
57
+ - ext/tls_dummy.c
58
+ - ext/sha1.c
59
+ - ext/snprintf.c
60
+ - ext/sock.c
61
+ - ext/tls.h
62
+ - ext/sasl.h
63
+ - ext/thread.h
64
+ - ext/util.h
65
+ - ext/common.h
66
+ - ext/md5.h
67
+ - ext/hash.h
68
+ - ext/sha1.h
69
+ - ext/sock.h
70
+ - ext/strophe.h
71
+ - ext/ostypes.h
72
+ - lib/strophe_ruby.rb
73
+ - test/test_helper.rb
74
+ - test/test_strophe_ruby.rb
75
+ - test/test_strophe_ruby_extn.rb
76
+ - ext/extconf.rb
77
+ has_rdoc: true
78
+ homepage:
79
+ post_install_message:
80
+ rdoc_options:
81
+ - --main
82
+ - README.txt
83
+ require_paths:
84
+ - lib
85
+ - ext
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: "0"
91
+ version:
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: "0"
97
+ version:
98
+ requirements: []
99
+
100
+ rubyforge_project: strophe_ruby
101
+ rubygems_version: 1.2.0
102
+ signing_key:
103
+ specification_version: 2
104
+ summary: strophe_ruby
105
+ test_files:
106
+ - test/test_strophe_ruby_extn.rb
107
+ - test/test_strophe_ruby.rb
108
+ - test/test_helper.rb