fixed coresendmsg after testing
This commit is contained in:
parent
138b2fcc4a
commit
b74d3488f7
1 changed files with 6 additions and 93 deletions
|
@ -22,90 +22,12 @@ from core.enumerations import MessageTypes
|
||||||
from core.enumerations import SessionTlvs
|
from core.enumerations import SessionTlvs
|
||||||
|
|
||||||
|
|
||||||
# def msgtypenum_to_str(num):
|
def print_available_tlvs(t, tlv_class):
|
||||||
# """
|
|
||||||
# Convert the message type number into a string, such as
|
|
||||||
# 1 = "CORE_API_NODE_MSG" = "node"
|
|
||||||
# """
|
|
||||||
# fulltypestr = str(MessageTypes(num))
|
|
||||||
# r = fulltypestr.split("_")[2]
|
|
||||||
# return r.lower()
|
|
||||||
|
|
||||||
|
|
||||||
# def str_to_msgtypenum(message_string):
|
|
||||||
# """
|
|
||||||
# Convert a shorthand string into a message type number.
|
|
||||||
# """
|
|
||||||
# fulltypestr = str_to_msgtypename(message_string)
|
|
||||||
# for k, v in coreapi.message_types.iteritems():
|
|
||||||
# if v == fulltypestr:
|
|
||||||
# return k
|
|
||||||
# return None
|
|
||||||
|
|
||||||
|
|
||||||
# def str_to_msgtypename(s):
|
|
||||||
# """
|
|
||||||
# Convert a shorthand string into a message type name.
|
|
||||||
# """
|
|
||||||
# return "CORE_API_%s_MSG" % s.upper()
|
|
||||||
|
|
||||||
|
|
||||||
# def msgflagnum_to_str(num):
|
|
||||||
# """
|
|
||||||
# Convert the message flag number into a string, such as
|
|
||||||
# 1 = "CORE_API_ADD_FLAG" = add
|
|
||||||
# """
|
|
||||||
# fullflagstr = coreapi.message_flags[num]
|
|
||||||
# r = fullflagstr.split("_")[2]
|
|
||||||
# return r.lower()
|
|
||||||
|
|
||||||
|
|
||||||
# def str_to_msgflagname(s):
|
|
||||||
# """
|
|
||||||
# Convert a shorthand string into a message flag name.
|
|
||||||
# """
|
|
||||||
# return "CORE_API_%s_FLAG" % s.upper()
|
|
||||||
|
|
||||||
|
|
||||||
# def str_to_msgflagnum(s):
|
|
||||||
# flagname = str_to_msgflagname(s)
|
|
||||||
# for (k, v) in coreapi.message_flags.iteritems():
|
|
||||||
# if v == flagname:
|
|
||||||
# return k
|
|
||||||
# return None
|
|
||||||
|
|
||||||
|
|
||||||
# def tlvname_to_str(name):
|
|
||||||
# """
|
|
||||||
# Convert a TLV name such as CORE_TLV_CONF_NODE to a short sring "node".
|
|
||||||
# """
|
|
||||||
# items = name.split("_")[3:]
|
|
||||||
# return "_".join(items).lower()
|
|
||||||
|
|
||||||
|
|
||||||
# def tlvname_to_num(tlv_cls, name):
|
|
||||||
# """
|
|
||||||
# Convert the given TLV Type class and TLV name to the TLV number.
|
|
||||||
# """
|
|
||||||
# for k, v in tlv_cls.tlv_type_map.iteritems():
|
|
||||||
# if v == name:
|
|
||||||
# return k
|
|
||||||
# return None
|
|
||||||
|
|
||||||
|
|
||||||
# def str_to_tlvname(t, s):
|
|
||||||
# """
|
|
||||||
# Convert the given TLV type t and string s to a TLV name.
|
|
||||||
# """
|
|
||||||
# return "CORE_TLV_%s_%s" % (t.upper(), s.upper())
|
|
||||||
|
|
||||||
|
|
||||||
def print_available_tlvs(t, tlv_cls):
|
|
||||||
"""
|
"""
|
||||||
Print a TLV list.
|
Print a TLV list.
|
||||||
"""
|
"""
|
||||||
print "TLVs available for %s message:" % t
|
print "TLVs available for %s message:" % t
|
||||||
for tlv in sorted([tlv for tlv in tlv_cls], key=lambda x: x.name):
|
for tlv in sorted([tlv for tlv in tlv_class.tlv_type_map], key=lambda x: x.name):
|
||||||
print "%s:%s" % (tlv.value, tlv.name)
|
print "%s:%s" % (tlv.value, tlv.name)
|
||||||
|
|
||||||
|
|
||||||
|
@ -194,7 +116,7 @@ def connect_to_session(sock, requested):
|
||||||
print "disconnected"
|
print "disconnected"
|
||||||
return False
|
return False
|
||||||
|
|
||||||
sessstr = smsgreply.gettlv(SessionTlvs.NUMBER.value)
|
sessstr = smsgreply.get_tlv(SessionTlvs.NUMBER.value)
|
||||||
if sessstr is None:
|
if sessstr is None:
|
||||||
print "missing session numbers"
|
print "missing session numbers"
|
||||||
return False
|
return False
|
||||||
|
@ -271,9 +193,6 @@ def main():
|
||||||
help="Listen for a response message and print it.")
|
help="Listen for a response message and print it.")
|
||||||
parser.add_option("-t", "--list-tlvs", dest="tlvs", action="store_true",
|
parser.add_option("-t", "--list-tlvs", dest="tlvs", action="store_true",
|
||||||
help="List TLVs for the specified message type.")
|
help="List TLVs for the specified message type.")
|
||||||
parser.add_option("-T", "--tcp", dest="tcp", action="store_true",
|
|
||||||
help="Use TCP instead of UDP and connect to a session" \
|
|
||||||
", default: %s" % parser.defaults["tcp"])
|
|
||||||
|
|
||||||
def usage(msg=None, err=0):
|
def usage(msg=None, err=0):
|
||||||
sys.stdout.write("\n")
|
sys.stdout.write("\n")
|
||||||
|
@ -296,7 +215,7 @@ def main():
|
||||||
usage("Unknown message type requested: %s" % t)
|
usage("Unknown message type requested: %s" % t)
|
||||||
message_type = MessageTypes[t]
|
message_type = MessageTypes[t]
|
||||||
msg_cls = coreapi.CLASS_MAP[message_type.value]
|
msg_cls = coreapi.CLASS_MAP[message_type.value]
|
||||||
tlv_cls = msg_cls.tlv_cls
|
tlv_cls = msg_cls.tlv_class
|
||||||
|
|
||||||
# list TLV types for this message type
|
# list TLV types for this message type
|
||||||
if opt.tlvs:
|
if opt.tlvs:
|
||||||
|
@ -338,13 +257,7 @@ def main():
|
||||||
|
|
||||||
msg = msg_cls.pack(flags, tlvdata)
|
msg = msg_cls.pack(flags, tlvdata)
|
||||||
|
|
||||||
# send the message
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
if opt.tcp:
|
|
||||||
protocol = socket.SOCK_STREAM
|
|
||||||
else:
|
|
||||||
protocol = socket.SOCK_DGRAM
|
|
||||||
|
|
||||||
sock = socket.socket(socket.AF_INET, protocol)
|
|
||||||
sock.setblocking(True)
|
sock.setblocking(True)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -353,7 +266,7 @@ def main():
|
||||||
print "Error connecting to %s:%s:\n\t%s" % (opt.address, opt.port, e)
|
print "Error connecting to %s:%s:\n\t%s" % (opt.address, opt.port, e)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if opt.tcp and not connect_to_session(sock, opt.session):
|
if not connect_to_session(sock, opt.session):
|
||||||
print "warning: continuing without joining a session!"
|
print "warning: continuing without joining a session!"
|
||||||
|
|
||||||
sock.sendall(msg)
|
sock.sendall(msg)
|
||||||
|
|
Loading…
Add table
Reference in a new issue