Add edit nodes

This commit is contained in:
emdee 2022-10-04 19:44:21 +00:00
parent 3dba2557e8
commit a871c2a681
2 changed files with 58 additions and 16 deletions

View File

@ -113,12 +113,19 @@ LOG.trace = trace
global bOUT, aOUT, sENC global bOUT, aOUT, sENC
aOUT = {} aOUT = {}
bOUT = b'' bOUT = b''
sENC = 'utf-8' sENC = sys.getdefaultencoding() # 'utf-8'
lNULLS = ['', '[]', 'null']
# grep '#''#' logging_tox_savefile.py|sed -e 's/.* //' # grep '#''#' logging_tox_savefile.py|sed -e 's/.* //'
sEDIT_HELP = """ sEDIT_HELP = """
NAME,.,Nick_name,str NAME,.,Nick_name,str
STATUSMESSAGE,.,Status_message,str STATUSMESSAGE,.,Status_message,str
STATUS,.,Online_status,int STATUS,.,Online_status,int
NOSPAMKEYS,.,Nospam,hexstr
NOSPAMKEYS,.,Public_key,hexstr
NOSPAMKEYS,.,Private_key,hexstr
DHT,.,DHTnode,
TCP_RELAY,.,TCPnode,
PATH_NODE,.,PATHnode,
""" """
#messenger.c #messenger.c
@ -438,9 +445,6 @@ def process_chunk(index, state, oArgs=None):
label = dSTATE_TYPE[data_type] label = dSTATE_TYPE[data_type]
if oArgs.command == 'edit' and oArgs.edit: if oArgs.command == 'edit' and oArgs.edit:
# if ':' in oArgs.edit:
# section,num,key,val = oArgs.edit.split(':')[0].split(',',3)
# else:
section,num,key,val = oArgs.edit.split(',', 3) section,num,key,val = oArgs.edit.split(',', 3)
diff = index - len(bOUT) diff = index - len(bOUT)
@ -479,12 +483,29 @@ def process_chunk(index, state, oArgs=None):
elif data_type == MESSENGER_STATE_TYPE_DHT: elif data_type == MESSENGER_STATE_TYPE_DHT:
LOG.debug(f"process_chunk {label} length={length}") LOG.debug(f"process_chunk {label} length={length}")
lIN = lProcessDHTnodes(state, index, length, result) if length > 4:
lIN = lProcessDHTnodes(state, index, length, result, "DHTnode")
else:
lIN = []
LOG.info(f"NO {label}")
aOUT.update({label: lIN}) aOUT.update({label: lIN})
if oArgs.command == 'edit' and section == label:
## DHT,.,DHTnode,
if num == '.' and key == "DHTnode" and val in lNULLS:
# 4 uint32_t (0x159000D)
status = 0x159000D
# FixMe - dunno
result = struct.pack("<L", status)
length = 4
LOG.info(f"{label} {key} EDITED to {val}")
elif data_type == MESSENGER_STATE_TYPE_FRIENDS: elif data_type == MESSENGER_STATE_TYPE_FRIENDS:
LOG.info(f"{label} {length // 2216} FRIENDS {length % 2216}") LOG.info(f"{label} {length // 2216} FRIENDS {length % 2216}")
if length > 0:
lIN = lProcessFriends(state, index, length, result) lIN = lProcessFriends(state, index, length, result)
else:
lIN = []
LOG.info(f"NO {label}")
aOUT.update({label: lIN}) aOUT.update({label: lIN})
elif data_type == MESSENGER_STATE_TYPE_NAME: elif data_type == MESSENGER_STATE_TYPE_NAME:
@ -541,6 +562,12 @@ def process_chunk(index, state, oArgs=None):
lIN = [] lIN = []
LOG.info(f"NO {label}") LOG.info(f"NO {label}")
aOUT.update({label: lIN}) aOUT.update({label: lIN})
if oArgs.command == 'edit' and section == label:
## TCP_RELAY,.,TCPnode,
if num == '.' and key == "TCPnode" and val in lNULLS:
result = b''
length = 0
LOG.info(f"{label} {key} EDITED to {val}")
elif data_type == MESSENGER_STATE_TYPE_PATH_NODE: elif data_type == MESSENGER_STATE_TYPE_PATH_NODE:
#define NUM_SAVED_PATH_NODES 8 #define NUM_SAVED_PATH_NODES 8
@ -551,6 +578,12 @@ def process_chunk(index, state, oArgs=None):
LOG.debug(f"process_chunk {label} bytes={length}") LOG.debug(f"process_chunk {label} bytes={length}")
lIN = lProcessNodeInfo(state, index, length, result, "PATHnode") lIN = lProcessNodeInfo(state, index, length, result, "PATHnode")
aOUT.update({label: lIN}) aOUT.update({label: lIN})
if oArgs.command == 'edit' and section == label:
## PATH_NODE,.,PATHnode,
if num == '.' and key == "PATHnode" and val in lNULLS:
result = b''
length = 0
LOG.info(f"{label} {key} EDITED to {val}")
elif data_type == MESSENGER_STATE_TYPE_CONFERENCES: elif data_type == MESSENGER_STATE_TYPE_CONFERENCES:
lIN = [] lIN = []

View File

@ -104,17 +104,26 @@ for the_tox in $tox /tmp/toxic_profile.save ; do
$EXE $target --command edit --edit help $the_tox 2>/dev/null || exit ${i}2 $EXE $target --command edit --edit help $the_tox 2>/dev/null || exit ${i}2
INFO $i $the_base.edit1 'STATUSMESSAGE,.,Status_message,Toxxed on Toxic' # edit the status message
INFO $i $the_base.Status_message 'STATUSMESSAGE,.,Status_message,Toxxed on Toxic'
$EXE $target --command edit --edit 'STATUSMESSAGE,.,Status_message,Toxxed on Toxic' \ $EXE $target --command edit --edit 'STATUSMESSAGE,.,Status_message,Toxxed on Toxic' \
--output $the_base.edit1.tox $the_tox 2>&1|grep EDIT --output $the_base.Status_message.tox $the_tox 2>&1|grep EDIT || exit ${i}3
[ -s $the_base.edit1.tox ] || exit ${i}3 [ -s $the_base.Status_message.tox ] || exit ${i}3
$EXE $target --command info $the_base.edit1.tox 2>&1|grep Toxxed || exit ${i}4 $EXE $target --command info $the_base.Status_message.tox 2>&1|grep Toxxed || exit ${i}4
INFO $i $the_base.edit2 'NAME,.,Nick_name,FooBar' # edit the nick_name
INFO $i $the_base.Nick_name 'NAME,.,Nick_name,FooBar'
$EXE $target --command edit --edit 'NAME,.,Nick_name,FooBar' \ $EXE $target --command edit --edit 'NAME,.,Nick_name,FooBar' \
--output $the_base.edit2.tox $the_tox 2>&1|grep EDIT --output $the_base.Nick_name.tox $the_tox 2>&1|grep EDIT || exit ${i}5
[ -s $the_base.edit2.tox ] || exit ${i}5 [ -s $the_base.Nick_name.tox ] || exit ${i}5
$EXE $target --command info $the_base.edit2.tox 2>&1|grep FooBar || exit ${i}6 $EXE $target --command info $the_base.Nick_name.tox 2>&1|grep FooBar || exit ${i}6
# set the DHTnodes to empty
INFO $i $the_base.noDHT 'DHT,.,DHTnode,'
$EXE $target --command edit --edit 'DHT,.,DHTnode,' \
--output $the_base.noDHT.tox $the_tox 2>&1|grep EDIT || exit ${i}7
[ -s $the_base.noDHT.tox ] || exit ${i}7
$EXE $target --command info $the_base.noDHT.tox 2>&1|grep 'NO DHT' || exit ${i}8
done done