oversip 1.4.1 → 2.0.0

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.
@@ -1,67 +0,0 @@
1
- # Ruby built-in libraries.
2
-
3
- require "base64"
4
- require "digest/md5"
5
- require "digest/sha1"
6
- require "securerandom"
7
- require "fiber"
8
- require "openssl"
9
-
10
-
11
- # Ruby external gems.
12
-
13
- gem "iobuffer", ">= 1.1.2"
14
- require "iobuffer"
15
- gem "em-udns", ">= 0.3.6"
16
- require "em-udns"
17
- gem "escape_utils", ">= 0.2.4"
18
- require "escape_utils"
19
- gem "posix-spawn", ">= 0.3.6"
20
- require "posix-spawn"
21
- gem "em-synchrony", ">=1.0.2"
22
- require "em-synchrony"
23
-
24
-
25
- # OverSIP files.
26
-
27
- require "oversip/sip/sip.rb"
28
- require "oversip/sip/sip_parser.so"
29
- require "oversip/sip/constants.rb"
30
- require "oversip/sip/core.rb"
31
- require "oversip/sip/message.rb"
32
- require "oversip/sip/request.rb"
33
- require "oversip/sip/response.rb"
34
- require "oversip/sip/uri.rb"
35
- require "oversip/sip/name_addr.rb"
36
- require "oversip/sip/message_processor.rb"
37
- require "oversip/sip/listeners.rb"
38
- require "oversip/sip/launcher.rb"
39
- require "oversip/sip/server_transaction.rb"
40
- require "oversip/sip/client_transaction.rb"
41
- require "oversip/sip/transport_manager.rb"
42
- require "oversip/sip/timers.rb"
43
- require "oversip/sip/tags.rb"
44
- require "oversip/sip/rfc3263.rb"
45
- require "oversip/sip/client.rb"
46
- require "oversip/sip/proxy.rb"
47
- require "oversip/sip/uac.rb"
48
- require "oversip/sip/uac_request.rb"
49
-
50
- require "oversip/websocket/websocket.rb"
51
- require "oversip/websocket/ws_http_parser.so"
52
- require "oversip/websocket/constants.rb"
53
- require "oversip/websocket/http_request.rb"
54
- require "oversip/websocket/listeners.rb"
55
- require "oversip/websocket/launcher.rb"
56
- require "oversip/websocket/ws_framing_utils.so"
57
- require "oversip/websocket/ws_framing.rb"
58
- require "oversip/websocket/ws_sip_app.rb"
59
-
60
- require "oversip/fiber_pool.rb"
61
- require "oversip/tls.rb"
62
- require "oversip/stun.so"
63
-
64
- require "oversip/modules/user_assertion.rb"
65
- require "oversip/modules/outbound_mangling.rb"
66
-
67
- require "oversip/ruby_ext/eventmachine.rb"
@@ -1,126 +0,0 @@
1
- module OverSIP
2
-
3
- class PosixMQ
4
-
5
- extend ::OverSIP::Logger
6
-
7
- def self.create_queue options={}
8
- @log_id = "PosixMQ #{options[:name]}"
9
-
10
- # Queue attributes.
11
- mq_name = options[:name]
12
- mq_mode = case options[:mode]
13
- when :read then ::IO::RDONLY
14
- when :write then ::IO::WRONLY
15
- when :read_write then ::IO::RDWR
16
- end
17
- mq_group = options[:group]
18
- mq_attr = ::POSIX_MQ::Attr.new
19
- # NOTE: maximun value for maxmsg is 65536.
20
- mq_attr.maxmsg = options[:maxmsg]
21
- mq_attr.msgsize = options[:msgsize]
22
- mq_attr.flags = 0
23
- mq_attr.curmsgs = 0
24
-
25
- # Delete the queue if it exists.
26
- begin
27
- ::POSIX_MQ.unlink mq_name
28
- rescue ::Errno::ENOENT
29
- rescue ::Errno::EACCES => e
30
- ::OverSIP::Launcher.fatal "queue already exists and cannot remove it due file permissions"
31
- # Kernel has no support for posix message queues.
32
- rescue ::Errno::ENOSYS => e
33
- ::OverSIP::Launcher.fatal "the kernel has no support for posix messages queues, enable it (#{e.class}: #{e.message})"
34
- end
35
-
36
- # Set the UMASK in a way that the group has permission to delete the queue.
37
- orig_umask = ::File.umask(0007)
38
-
39
- # Change the effective group for the Posix queue. Keep the original
40
- # group.
41
- orig_gid = ::Process::GID.eid
42
- if mq_group
43
- gid = ::Etc.getgrnam(mq_group).gid
44
- ::Process::GID.change_privilege(gid)
45
- end
46
-
47
- # System limits required size (ulimit -q).
48
- mq_size = case 1.size
49
- # 32 bits OS.
50
- when 4 then mq_attr.maxmsg * 4 + mq_attr.maxmsg * mq_attr.msgsize
51
- # 64 bits OS.
52
- when 8 then mq_attr.maxmsg * 8 + mq_attr.maxmsg * mq_attr.msgsize
53
- end
54
-
55
- log_system_info "queue requires #{mq_size} bytes"
56
-
57
- # Set RLIMIT_MSGQUEUE (ulimit) in order to create the queue with required
58
- # ammount of memory.
59
- if ( current_rlimit = ::Process.getrlimit(::Process::RLIMIT_MSGQUEUE)[1] ) < mq_size
60
- log_system_info "incrementing rlimits for 'msgqueue' Posix Message Queues (currently #{current_rlimit} bytes) to #{mq_size} bytes (ulimit -q)"
61
- begin
62
- ::Process.setrlimit(::Process::RLIMIT_MSGQUEUE, mq_size, mq_size)
63
- rescue ::Errno::EPERM
64
- ::OverSIP::Launcher.fatal "current user has no permissions to increase 'msgqueue' rlimits to #{mq_size} bytes"
65
- rescue => e
66
- ::OverSIP::Launcher.fatal e
67
- end
68
- else
69
- log_system_info "rlimits for 'msgqueue' is #{current_rlimit} bytes (>= #{mq_size}), no need to increase it"
70
- end
71
-
72
- # Create the Posix message queue to write into it.
73
- # - IO::WRONLY => Just write.
74
- # - IO::CREAT => Create if it doesn't exist.
75
- # - IO::EXCL => Raise if the queue already exists.
76
- # - IO::NONBLOCK => Don't block when sending (instead raise Errno::EAGAIN).
77
- # - mode: 00660 => User and group can write and read.
78
- # - mq_attr => Set maxmsg and msgsize.
79
- begin
80
- mq = ::POSIX_MQ.new mq_name, mq_mode | ::IO::CREAT | ::IO::EXCL | ::IO::NONBLOCK, 00660, mq_attr
81
-
82
- # Kernel has no support for posix message queues.
83
- rescue ::Errno::ENOSYS => e
84
- ::OverSIP::Launcher.fatal "the kernel has no support for Posix Messages Queues, enable it (#{e.class}: #{e.message})"
85
-
86
- # http://linux.die.net/man/3/mq_open
87
- #
88
- # IO_CREAT was specified in oflag, and attr was not NULL, but attr->mq_maxmsg or attr->mq_msqsize was
89
- # invalid. Both of these fields must be greater than zero. In a process that is unprivileged (does not
90
- # have the CAP_SYS_RESOURCE capability), attr->mq_maxmsg must be less than or equal to the msg_max
91
- # limit, and attr->mq_msgsize must be less than or equal to the msgsize_max limit. In addition, even
92
- # in a privileged process, attr->mq_maxmsg cannot exceed the HARD_MAX limit. (See mq_overview(7) for
93
- # details of these limits.)
94
- rescue ::Errno::EINVAL
95
- log_system_warn "cannot set queue attributes due to user permissions, using system default values"
96
- mq = ::POSIX_MQ.new mq_name, mq_mode | ::IO::CREAT | ::IO::NONBLOCK, 00660
97
- rescue ::Errno::ENOMEM => e
98
- ::OverSIP::Launcher.fatal "insufficient memory (#{e.class}: #{e.message})"
99
- rescue ::Errno::EMFILE => e
100
- ::OverSIP::Launcher.fatal "the process already has the maximum number of files and message queues open (#{e.class}: #{e.message})"
101
- rescue Errno::ENFILE => e
102
- ::OverSIP::Launcher.fatal "the system limit on the total number of open files and message queues has been reached (#{e.class}: #{e.message})"
103
- rescue ::Errno::ENOSPC => e
104
- ::OverSIP::Launcher.fatal "insufficient space for the creation of a new message queue, probably occurred because the 'queues_max' limit was encountered (#{e.class}: #{e.message})"
105
-
106
- end
107
-
108
- # Recover the original Umask settings.
109
- ::File.umask(orig_umask)
110
-
111
- # Recover the original effective group.
112
- ::Process::GID.change_privilege(orig_gid) if mq_group
113
-
114
- if mq.attr.maxmsg == mq_attr.maxmsg and mq.attr.msgsize == mq_attr.msgsize
115
- log_system_info "maxmsg=#{mq.attr.maxmsg}, msgsize=#{mq.attr.msgsize}"
116
- else
117
- log_system_warn "maxmsg=#{mq.attr.maxmsg}, msgsize=#{mq.attr.msgsize}, " \
118
- "but recommended values are maxmsg=#{mq_attr.maxmsg}, msgsize=#{mq_attr.msgsize}"
119
- end
120
-
121
- mq
122
- end # self.create_queue
123
-
124
- end # class PosixMQ
125
-
126
- end
@@ -1,9 +0,0 @@
1
- module Process
2
-
3
- # Ruby 1.9.2 has not defined the constant Process::RLIMIT_MSGQUEUE (Ruby 1.9.3 has it).
4
- # Gives it value 12 if not defined.
5
- unless defined? ::Process::RLIMIT_MSGQUEUE
6
- Process.const_set :RLIMIT_MSGQUEUE, 12
7
- end
8
-
9
- end
@@ -1,80 +0,0 @@
1
- # Ruby external gems.
2
-
3
- gem "em-posixmq", ">= 0.2.3"
4
- require "em-posixmq"
5
-
6
-
7
- # OverSIP libraries.
8
- # (not required to be loaded as needed ones have been already
9
- # loaded before forking).
10
-
11
-
12
-
13
- module OverSIP
14
-
15
- module SysLoggerProcess
16
-
17
- class SysLoggerWatcher < ::EM::PosixMQ::Watcher
18
-
19
- def receive_message string, priority
20
- ::OverSIP::Syslog.log string
21
- end
22
-
23
- end # class SysLoggerWatcher
24
-
25
- def self.run options={}
26
- $0 = ::OverSIP.master_name + "_syslogger"
27
-
28
- # Close Ruby Syslog open in the main process before forking.
29
- ::Syslog.close
30
-
31
- # Run a new Ruby Syslog.
32
- syslog_options = ::Syslog::LOG_PID | ::Syslog::LOG_NDELAY
33
- syslog_facility = ::OverSIP::Syslog::SYSLOG_FACILITY_MAPPING[::OverSIP.configuration[:core][:syslog_facility]]
34
- ::Syslog.open(::OverSIP.master_name, syslog_options, syslog_facility)
35
-
36
- ppid = ::Process.ppid
37
-
38
- at_exit do
39
- ::Syslog.notice sprintf("%7s %s", "INFO:", "<syslogger> syslogger process terminated")
40
- exit!
41
- end
42
-
43
- EM.run do
44
- begin
45
- syslogger_mq = ::POSIX_MQ.new ::OverSIP.syslogger_mq_name, ::IO::RDONLY | ::IO::NONBLOCK
46
- ::EM::PosixMQ.run syslogger_mq, SysLoggerWatcher
47
-
48
- # Change process permissions if requested.
49
- ::OverSIP::Launcher.set_user_group(options[:user], options[:group])
50
-
51
- rescue ::Exception => e
52
- ::Syslog.crit sprintf("%7s %s", "CRIT:", "<syslogger> #{e.class}: #{e}")
53
- ::Syslog.crit sprintf("%7s %s", "CRIT:", "<syslogger> syslogger process terminated")
54
- exit! 1
55
- end
56
-
57
- # Periodically check that master process remains alive and
58
- # die otherwise.
59
- ::EM.add_periodic_timer(1) do
60
- if ::Process.ppid != ppid
61
- # Wait 0.5 seconds. Maybe the master process has been killed properly and just now
62
- # it's sending us the QUIT signal.
63
- ::EM.add_timer(0.5) do
64
- ::Syslog.crit sprintf("%7s %s", "CRIT:", "<syslogger> master process died, syslogger process terminated")
65
- exit! 1
66
- end
67
- end
68
- end
69
-
70
- ::EM.error_handler do |e|
71
- ::Syslog.crit sprintf("%7s %s", "CRIT:", "<syslogger> error raised during event loop and rescued by EM.error_handler: #{e.message} (#{e.class})\n#{(e.backtrace || [])[0..3].join("\n")}")
72
- end
73
-
74
- ::Syslog.info sprintf("%7s %s", "INFO:", "<syslogger> syslogger process (PID #{$$}) ready")
75
- end
76
- end
77
-
78
- end # module SysLoggerProcess
79
-
80
- end