Class EMG::MGP
In: mgp.rb
Parent: Object

This class is the actual protocol implementation

Methods

Constants

OP_LOGON = (1)   Operations
OP_LOGON_RESP = (101)
OP_SENDMESSAGE = (2)
OP_SENDMESSAGE_RESP = (102)
OP_LOGOFF = (3)
OP_LOGOFF_RESP = (103)
OP_BEGINBATCH = (4)
OP_BEGINBATCH_RESP = (104)
OP_ENDBATCH = (5)
OP_ENDBATCH_RESP = (105)
OP_GETCONNECTORINFO = (6)
OP_GETCONNECTORINFO_RESP = (106)
OP_REFRESH = (7)
OP_REFRESH_RESP = (107)
OP_GETCONNECTORQUEUE = (8)
OP_GETCONNECTORQUEUE_RESP = (108)
OP_GETORPHANS = (9)
OP_GETORPHANS_RESP = (109)
OP_QUERYMESSAGE = (10)
OP_QUERYMESSAGE_RESP = (110)
OP_DELETEMESSAGE = (11)
OP_DELETEMESSAGE_RESP = (111)
OP_MODIFYMESSAGE = (12)
OP_MODIFYMESSAGE_RESP = (112)
OP_KEEPALIVE = (13)
OP_KEEPALIVE_RESP = (113)
OP_GETROUTELOG = (14)
OP_GETROUTELOG_RESP = (114)
OP_PBCREATE = (20)
OP_PBCREATE_RESP = (120)
OP_PBDELETE = (21)
OP_PBDELETE_RESP = (121)
OP_PBADD = (22)
OP_PBADD_RESP = (122)
OP_PBUPDATE = (23)
OP_PBUPDATE_RESP = (123)
OP_PBREMOVE = (24)
OP_PBREMOVE_RESP = (124)
OP_PBLIST = (25)
OP_PBLIST_RESP = (125)
OP_REQUESTMESSAGE = (26)
OP_REQUESTMESSAGE_RESP = (126)
OP_CONNECTORHOLD = (27)
OP_CONNECTORHOLD_RESP = (127)
OP_DBREQUEST = (28)
OP_DBREQUEST_RESP = (128)
OP_GETFIRSTMESSAGE = (29)
OP_GETFIRSTMESSAGE_RESP = (129)
OP_CONFIRMMESSAGE = (30)
OP_CONFIRMMESSAGE_RESP = (130)
OP_GETDBINFO = (31)
OP_GETDBINFO_RESP = (131)
OP_RELOAD = (32)
OP_RELOAD_RESP = (132)
OPTION_ID = 0x0001   Options
OPTION_SOURCEADDR = 0x0002
OPTION_SOURCEADDRTON = 0x0003
OPTION_SOURCEADDRNPI = 0x0004
OPTION_SOURCESUBADDRESS = 0x0005
OPTION_SOURCEPORT = 0x0006
OPTION_SOURCEADDRSUBUNIT = 0x0007
OPTION_DESTADDR = 0x0008
OPTION_DESTADDRTON = 0x0009
OPTION_DESTADDRNPI = 0x000a
OPTION_DESTSUBADDRESS = 0x000b
OPTION_DESTPORT = 0x000c
OPTION_DESTADDRSUBUNIT = 0x000d
OPTION_UDH = 0x000e
OPTION_UDHLEN = 0x000f
OPTION_MESSAGE = 0x0010
OPTION_MESSAGELEN = 0x0011
OPTION_VP = 0x0012
OPTION_DLR = 0x0013
OPTION_DELTIME = 0x0014
OPTION_SCTS = 0x0015
OPTION_USERNAME = 0x0016
OPTION_PASSWORD = 0x0017
OPTION_NEWPASSWORD = 0x0018
OPTION_MSGTYPE = 0x0019
OPTION_MSGSUBTYPE = 0x001a
OPTION_MSGCLASS = 0x001b
OPTION_CHARCODE = 0x001c
OPTION_AUTHCODE = 0x001d
OPTION_REPLYPATH = 0x001f
OPTION_PRIORITY = 0x0020
OPTION_TARIFFCLASS = 0x0021
OPTION_REMOTEIP = 0x0022
OPTION_SYSTEMTYPE = 0x0023
OPTION_SMSCOP = 0x0024
OPTION_ROUTE = 0x0026
OPTION_ROUTEDLR = 0x0027
OPTION_RETCODE = 0x0028
OPTION_SERVICETYPE = 0x0029
OPTION_MESSAGEMODE = 0x002a
OPTION_PROTOCOLID = 0x002b
OPTION_REPLACEIFPRESENTFLAG = 0x002c
OPTION_USERMESSAGEREFERENCE = 0x002d
OPTION_USERRESPONSECODE = 0x002e
OPTION_PRIVACYINDICATOR = 0x002f
OPTION_CALLBACKNUM = 0x0030
OPTION_LANGUAGEINDICATOR = 0x0031
OPTION_TTSSESSIONINFO = 0x0032
OPTION_NETWORKERRORCODE = 0x0033
OPTION_MESSAGESTATE = 0x0034
OPTION_RECEIPTEDMESSAGEID = 0x0035
OPTION_LONGMESSAGE = 0x0036
OPTION_LONGMODE = 0x0037
OPTION_REGISTEREDDELIVERY = 0x0038
OPTION_CANCELMODE = 0x0039
OPTION_INTERFACEVERSION = 0x003a
OPTION_CONNECTOR = 0x003b
OPTION_OUTCONNECTOR = 0x003c
OPTION_STATUS = 0x003d
OPTION_SOURCENETWORKTYPE = 0x003e
OPTION_DESTNETWORKTYPE = 0x003f
OPTION_SMSCID = 0x0040
OPTION_OPSENTEXPIRES = 0x0041
OPTION_DLREXPIRES = 0x0042
OPTION_ROUTE2 = 0x0043
OPTION_TCPSOURCEPORT = 0x0044
OPTION_MAPPING = 0x0045
OPTION_DLRADDRESS = 0x0046
OPTION_DLRPID = 0x0047
OPTION_DOMAIN = 0x0048
OPTION_CONCATSMSREF = 0x0049
OPTION_CONCATSMSSEQ = 0x004a
OPTION_CONCATSMSMAX = 0x004b
OPTION_REQUIREPREFIX = 0x004c
OPTION_AUTHTON = 0x004d
OPTION_AUTHNPI = 0x004e
OPTION_BILLINGID = 0x004f
OPTION_SINGLESHOT = 0x0050
OPTION_DLRID = 0x0051
OPTION_STATE = 0x0053
OPTION_PROTOCOL = 0x0054
OPTION_INSTANCES = 0x0055
OPTION_QUEUESIZE = 0x0056
OPTION_TYPE = 0x0057
OPTION_QSTATS1 = 0x0058
OPTION_QSTATS5 = 0x0059
OPTION_QSTATS15 = 0x005a
OPTION_INSTANCE = 0x005b
OPTION_STARTSECS = 0x005d
OPTION_STARTMSECS = 0x005e
OPTION_ENDSECS = 0x005f
OPTION_ENDMSECS = 0x0060
OPTION_NOTE = 0x0061
OPTION_CLIENTCONFIG = 0x0062
OPTION_COMPANY = 0x0063
OPTION_NAME = 0x0064
OPTION_PBNAME = 0x0065
OPTION_PBTYPE = 0x0066
OPTION_REASON = 0x0067
OPTION_PBID = 0x0068
OPTION_ISADMIN = 0x0069
OPTION_UDHI = 0x006a
OPTION_REPLACEPID = 0x006b
OPTION_LRADDR = 0x006c
OPTION_LRPID = 0x006d
OPTION_HPLMNADDR = 0x006e
OPTION_SUBJECT = 0x006f
OPTION_OTOA = 0x0070
OPTION_DCS = 0x0071
OPTION_MAXMESSAGELENGTH = 0x0072
OPTION_HEADER = 0x0073
OPTION_KEYWORD = 0x0074
OPTION_REMOVEPREFIX = 0x0075
OPTION_QPRIORITY = 0x0076
OPTION_XUSERNAME = 0x0077
OPTION_MAXINSTANCES = 0x0078
OPTION_AVGINSTANCES1 = 0x0079
OPTION_STATIC = 0x007a
OPTION_MODE = 0x007b
OPTION_DBSQL = 0x007c
OPTION_DBNAME = 0x007d
OPTION_DBDATA = 0x007e
OPTION_CREDITS = 0x007f
OPTION_SOURCEADDRTYPE = 0x0080
OPTION_DESTADDRTYPE = 0x0081
OPTION_REQUIREPREFIX_SOURCEADDR = 0x0082
OPTION_REMOVEPREFIX_SOURCEADDR = 0x0083
OPTION_PDUSEQ = 0x0084
OPTION_PDUSEQMAX = 0x0085
OPTION_ORIGSOURCEADDR = 0x0086
OPTION_ORIGDESTADDR = 0x0087
OPTION_SERVICEDESCRIPTION = 0x0088
OPTION_SENDERTS = 0x0089
OPTION_IMSI = 0x008a
OPTION_VLR = 0x008b
OPTION_ORIGID = 0x008c
OPTION_SERVICEID = 0x008d
OPTION_ACLENTRYWHOID = 0x008e
OPTION_ACLENTRYWHEREID = 0x008f
OPTION_PLUGINARG = 0x0090
OPTION_MMSDESTADDR = 0x0091
OPTION_MSISDN = 0x0092
OPTION_XPRIORITY = 0x0093
OPTION_TCPSOURCEIP = 0x0094
OPTION_SENDERADDRESS = 0x0095
OPTION_ORIGIN = 0x0096
OPTION_SUBMITTS = 0x0097
OPTION_DONETS = 0x0098
OPTION_MESSAGEID = 0x0099
OPTION_INREPLYTO = 0x009a
OPTION_REFERENCES = 0x009b
OPTION_QUOTEDREPLY = 0x009c
OPTION_QUOTEDREPLY_SEPARATOR = 0x009d
OPTION_SERVICETYPEIN = 0x009e
OPTION_SOURCEFULLNAME = 0x009f
OPTION_CONTENTTYPE = 0x00a0
OPTION_CONTENTLOCATION = 0x00a1
OPTION_DESTFULLNAME = 0x00a2
OPTION_DLRBUF = 0x00a3
OPTION_ARCORMOD = 0x00a4
OPTION_ARCORFUNC = 0x00a5
OPTION_ARCORUNIT = 0x00a6
OPTION_SCAADDR = 0x00a7
OPTION_SCAADDRTON = 0x00a8
OPTION_SCAADDRNPI = 0x00a9
OPTION_REASONTEXT = 0x00aa
OPTION_ITSSESSIONINFO = 0x00ab
OPTION_LASTDLRSECS = 0x00ac
OPTION_LASTDLRMSECS = 0x00ad
OPTION_SMTP_RET = 0x00ae
OPTION_INSTANCES_INUSE = 0x00af
OPTION_DESTNETWORK = 0x00b0
OPTION_TARIFFNAME = 0x00b1
OPTION_SMPPOPTION = 0x00b2
OPTION_BUFFEREDSTATUS = 0x00b3
OPTION_LAST = 0x00b3
PBTYPE_USER = 0   Phone book types
PBTYPE_SYSTEM = 1
ERR_OK = 0   Return codes
ERR_UNKNOWN = 1
ERR_SYNTAX = 2
ERR_LOGIN = 3
ERR_BOUND = 4
ERR_INVALARG = 5
ERR_INVALCMD = 6
ERR_INVALMSGID = 7
ERR_INVALDESTADDR = 8
ERR_INVALSOURCEADDR = 9
ERR_NOACCESS = 10
ERR_MESSAGE = 11
ERR_INVALRESP = 12
ERR_COMM = 13
ERR_DB = 14
ERR_UDH = 15
ERR_CREDITS = 16
ERR_BUSY = 17
ERR_TOOLONG = 18
A_STX = 2   Misc
A_ETX = 3

Attributes

admin  [R] 
charcode  [R] 
clientconfig  [R] 
credits  [R] 
host  [R] 
name  [R] 
perms  [R] 
port  [R] 
remoteip  [R] 
socket  [R] 
systemtype  [R] 

Public Class methods

Public Instance methods

Test if the currently logged in user has administration privileges.

Close the connection to server.

Confirm that the given message has been succesfully received.

If this function isn‘t called, the same message will be delivered again after the next login.

The parameter id should be the value from SMS.messageid, and the result code ERR_OK or any of the other ERR_* values.

Connect to the EMG server on the specified host and port. The EMG server must have an incoming MGP connector listening on the specified IP address/hostname and port.

Valid options:

:ssl => true :Use SSL.
:username => ‘user‘ :Login with this username.
:password => ‘pw‘ :Login with this password.

The :username and :password options are only used if a function block is used.

The yield block is optional. If given, the session is closed and the socket disconnected when the yield block returns.

Set the "hold" status of the connector identified by "name".

The "status" should either be true to pause outgoing traffic on the connector or false to reenable traffic again.

Returns the result code and the current status.

Delete the message with the specified message id.

Fetch information about one or all connectors.

Returns the result code, and a hash table.

The hash table keys are the connector names, and the values are a separate hash table with the values for that connector. In this second level has, the used keys are these:

OPTION_TYPE :1 for incoming, 2 for outgoing.
OPTION_PROTOCOL :Protocol number.
OPTION_INSTANCES :The value of the INSTANCES parameter in the server.cfg file.
OPTION_INSTANCES_INUSE :How many instances that are currently in use.
OPTION_MAXINSTANCES :The maximum number of used instances.
OPTION_STATE :Current connector state.
OPTION_QUEUESIZE :Number of messages in the outgoing queue.
OPTION_QSTAT1 :Average message throughput for the past minute.
OPTION_QSTAT5 :Average message throughput for the past five minutes.
OPTION_QSTAT15 :Average message throughput for the past fifteen minutes.

It also has a key OPTION_INSTANCE. The value for this key is a third hash table, containing information about each connector instance. The keys used here are these:

OPTION_STATE :State for this instance.
OPTION_REMOTEIP :If connected, the remote IP address.
OPTION_USERNAME :If connected, the name of the logged in user.

Fetch the list of pending messages on a connector.

The maxsize parameter can be given to limit the size of the result set.

Fetch information about one or all database profiles.

Returns the result code, and a hash table.

The hash table keys are the profile names, and the values are a separate hash table with the values for that profile. In this second level has, the used keys are these:

OPTION_NAME :The database profile name.
OPTION_DBNAME :The database name.
OPTION_TYPE :MYSQL for MySQL, PGSQL for PostgreSQL.
OPTION_INSTANCES :The value of the INSTANCES parameter in the server.cfg file.

It also has a key OPTION_INSTANCE. The value for this key is a third hash table, containing information about each profile instance. The keys used here are these:

OPTION_STATE :State for this instance.

Fetch the first message on the current connector.

Returns the result code, the current queue size on the connector, and the fetched message.

Afterwards, a call to confirm_message must be done to remove it from the server. Otherwise the same message will be returned again on the next connection.

Fetch the list of the most recent messages that couldn‘t be routed.

The supported optional parameters are:

:username => ‘user‘ :Only fetch messages for this user.
:maxsize => n :Limit the size of the result set.

Fetch the list of the most recent messages, including their routing and delivery status.

The supported optional parameters are:

:username => ‘user‘ :Only fetch messages for this user.
:maxsize => n :Limit the size of the result set.

Log out from the EMG server.

This also closes the socket.

Log on to the server using the specified username and password.

The connector must have a USERS file with the user credentials or reference a databaseprofile (USERDB) with the user specified.

If a yield block is given, the session and socket is automatically closed when the block returns.

Add an entry to a phonebook.

Only a user with administration privileges can add entries to a system phonebook.

Returns the result code.

Create a new phonebook.

The parameter pbtype should be 0 to create a user phonebook, and 1 to create a system phonebook. Only a user with administration privileges can create a system phonebook.

Returns the result code.

Delete a phonebook.

Only a user with administration privileges can delete a system phonebook.

Returns the result code.

Fetch a phonebook list.

If the parameter is absent, the list of available phonebooks is returned.

The list is a hash table, with the phonebook id as the key, and a hash table with options as the value. In this second hash table, the following keys are used:

OPTION_PBNAME :The name of the phonebook. This can be any printable string.
OPTION_PBTYPE :0 for a user phonebook, 1 for a system phonebook.

If the optional pbid is given, the list of entries in that phonebook is returned.

The list is a hash table, with the phonebook entry id as the key, and a hash table with options as the value. In this second hash table, the following keys are used:

OPTION_COMPANY :Company name.
OPTION_NAME :Personal name.
OPTION_DESTADDR :Phone number or email adress.

Delete a phonebook entry.

Only a user with administration privileges can delete entries in a system phonebook.

Update a phonebook entry.

Only a user with administration privileges can update entries in a system phonebook.

Supported keys for the params hash:

  • :company => ‘company name‘
  • :name => ‘personal name‘
  • :destaddr => ‘phone number‘

Returns the result code.

Query the status of a message.

Returns the result code and an SMS object containing the available fields.

Reload or refresh the EMG server.

When the closeall parameter is true all connections will be closed and the current MGP connection will also be lost. This corresponds to running "emgd -refresh" from the command-line.

When the closeall parameter is false connections will be kept. This corresponds to running "emgd -reload" from the command-line.

Send a message.

Returns the result code and (if successful) the message id.

[Validate]