implement main method

update protobuf to spectrum 2.0.5
This commit is contained in:
Nicolas 2017-09-09 20:34:23 +02:00
parent 0c199a8231
commit d88d13d1e3
3 changed files with 330 additions and 182 deletions

View file

@ -89,6 +89,7 @@ message Room {
message RoomList {
repeated string room = 1;
repeated string name = 2;
optional string user = 3;
}
enum ParticipantFlag {
@ -111,6 +112,7 @@ message Participant {
optional string statusMessage = 6;
optional string newname = 7;
optional string iconHash = 8;
optional string alias = 9;
}
message VCard {
@ -152,6 +154,10 @@ message BackendConfig {
required string config = 1;
}
message APIVersion {
required int32 version = 1;
}
message WrapperMessage {
enum Type {
TYPE_CONNECTED = 1;
@ -188,8 +194,10 @@ message WrapperMessage {
TYPE_CONV_MESSAGE_ACK = 33;
TYPE_RAW_XML = 34;
TYPE_BUDDIES = 35;
TYPE_API_VERSION = 36;
}
required Type type = 1;
optional bytes payload = 2;
}
;

File diff suppressed because one or more lines are too long

View file

@ -58,36 +58,36 @@ args, unknown = parser.parse_known_args()
YowConstants.PATH_STORAGE='/var/lib/spectrum2/' + args.j
if args.log is None:
args.log = '/var/log/spectrum2/' + args.j + '/backends/backend.log'
args.log = '/var/log/spectrum2/' + args.j + '/backends/backend.log'
# Logging
logging.basicConfig(
filename = args.log,
format = "%(asctime)-15s %(levelname)s %(name)s: %(message)s",
level = logging.DEBUG if args.debug else logging.INFO
filename = args.log,
format = "%(asctime)-15s %(levelname)s %(name)s: %(message)s",
level = logging.DEBUG if args.debug else logging.INFO
)
if args.config is not None:
specConf = SpectrumConfig(args.config)
specConf = SpectrumConfig(args.config)
else:
specConf = None
specConf = None
# Handler
def handleTransportData(data):
try:
plugin.handleDataRead(data)
except SystemExit as e:
raise e
except:
logger = logging.getLogger('transwhat')
logger.error(traceback.format_exc())
try:
plugin.handleDataRead(data)
except SystemExit as e:
raise e
except:
logger = logging.getLogger('transwhat')
logger.error(traceback.format_exc())
e4u.load()
closed = False
def connectionClosed():
global closed
closed = True
global closed
closed = True
# Main
io = IOChannel(args.host, args.port, handleTransportData, connectionClosed)
@ -95,34 +95,34 @@ io = IOChannel(args.host, args.port, handleTransportData, connectionClosed)
plugin = WhatsAppBackend(io, args.j, specConf)
plugin.handleBackendConfig({
'features': [
('send_buddies_on_login', 1),
('muc', 'true'),
],
'features': [
('send_buddies_on_login', 1),
('muc', 'true'),
],
})
while True:
try:
asyncore.loop(timeout=1.0, count=10, use_poll = True)
try:
callback = YowStack._YowStack__detachedQueue.get(False) #doesn't block
callback()
except Queue.Empty:
pass
else:
break
if closed:
break
while True:
try:
callback = threadutils.eventQueue.get_nowait()
except Queue.Empty:
break
else:
callback()
except SystemExit:
break
except:
logger = logging.getLogger('transwhat')
logger.error(traceback.format_exc())
def main():
while True:
try:
asyncore.loop(timeout=1.0, count=10, use_poll = True)
try:
callback = YowStack._YowStack__detachedQueue.get(False) #doesn't block
callback()
except Queue.Empty:
pass
else:
break
if closed:
break
while True:
try:
callback = threadutils.eventQueue.get_nowait()
except Queue.Empty:
break
else:
callback()
except SystemExit:
break
except:
logger = logging.getLogger('transwhat')
logger.error(traceback.format_exc())