Skip to content
Snippets Groups Projects
Commit f913e4cd authored by Yann Leboulanger's avatar Yann Leboulanger
Browse files

- new configuration File management

- bugfix : message from unknown personne
parent b2ec388e
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,6 @@
## Gajim Team:
## - Yann Le Boulanger <asterix@crans.org>
## - Vincent Hanquez <tab@tuxfamily.org>
## - David Ferlier <david@yazzy.org>
##
## Copyright (C) 2003 Gajim Team
##
......
......@@ -4,7 +4,6 @@
## Gajim Team:
## - Yann Le Boulanger <asterix@crans.org>
## - Vincent Hanquez <tab@tuxfamily.org>
## - David Ferlier <david@yazzy.org>
##
## Copyright (C) 2003 Gajim Team
##
......@@ -18,9 +17,7 @@
## GNU General Public License for more details.
##
import ConfigParser
import logging
import os
import ConfigParser, logging, os, string
log = logging.getLogger('common.options')
......@@ -28,6 +25,7 @@ class OptionsParser(ConfigParser.ConfigParser):
def __init__(self, fname):
ConfigParser.ConfigParser.__init__(self)
self.__fname = os.path.expanduser(fname)
self.tab = {}
# END __init__
def parseCfgFile(self):
......@@ -41,10 +39,19 @@ class OptionsParser(ConfigParser.ConfigParser):
self.__sections = self.sections()
for section in self.__sections:
self.tab[section] = {}
for option in self.options(section):
value = self.get(section, option, 1)
setattr(self, str(section) + '_' + \
str(option), value)
#convert to int options than can be
try:
i = string.atoi(value)
except ValueError:
self.tab[section][option] = value
else:
self.tab[section][option] = i
# setattr(self, str(section) + '_' + \
# str(option), value)
# END parseCfgFile
def __str__(self):
......@@ -54,14 +61,24 @@ class OptionsParser(ConfigParser.ConfigParser):
def __getattr__(self, attr):
if attr.startswith('__') and attr in self.__dict__.keys():
return self.__dict__[attr]
elif self.tab.has_key(attr):
return self.tab[attr]
else:
for key in self.__dict__.keys():
if key == attr:
return self.__dict__[attr]
# for key in self.__dict__.keys():
# if key == attr:
# return self.__dict__[attr]
return None
# END __getattr__
def writeCfgFile(self):
#Remove all sections
for s in self.sections():
self.remove_section(s)
#recreate sections
for s in self.tab.keys():
self.add_section(s)
for o in self.tab[s].keys():
self.set(s, o, self.tab[s][o])
try:
self.write(open(self.__fname, 'w'))
except:
......
......@@ -4,7 +4,6 @@
## Gajim Team:
## - Yann Le Boulanger <asterix@crans.org>
## - Vincent Hanquez <tab@tuxfamily.org>
## - David Ferlier <david@yazzy.org>
##
## Copyright (C) 2003 Gajim Team
##
......
......@@ -4,7 +4,6 @@
## Gajim Team:
## - Yann Le Boulanger <asterix@crans.org>
## - Vincent Hanquez <tab@tuxfamily.org>
## - David Ferlier <david@yazzy.org>
##
## Copyright (C) 2003 Gajim Team
##
......
......@@ -4,7 +4,6 @@
## Gajim Team:
## - Yann Le Boulanger <asterix@crans.org>
## - Vincent Hanquez <tab@tuxfamily.org>
## - David Ferlier <david@yazzy.org>
##
## Copyright (C) 2003 Gajim Team
##
......@@ -40,9 +39,16 @@ class GajimCore:
self.connected = 0
self.cfgParser = common.optparser.OptionsParser(CONFPATH)
self.hub = common.hub.GajimHub()
self.cfgParser.parseCfgFile()
self.parse()
# END __init__
def parse(self):
self.cfgParser.parseCfgFile()
self.accounts = {}
accts = self.cfgParser.tab['Profile']['accounts']
for a in string.split(accts, ' '):
self.accounts[a] = self.cfgParser.tab[a]
def messageCB(self, con, msg):
"""Called when we recieve a message"""
self.hub.sendPlugin('MSG', (msg.getFrom().getBasic(), \
......@@ -60,17 +66,20 @@ class GajimCore:
show = prs.getShow()
else:
show = 'online'
self.hub.sendPlugin('NOTIFY', \
(prs.getFrom().getBasic(), show, prs.getStatus(), prs.getFrom().getResource()))
self.hub.sendPlugin('NOTIFY', (prs.getFrom().getBasic(), \
show, prs.getStatus(), prs.getFrom().getResource()))
elif type == 'unavailable':
self.hub.sendPlugin('NOTIFY', \
(prs.getFrom().getBasic(), 'offline', prs.getStatus(), prs.getFrom().getResource()))
(prs.getFrom().getBasic(), 'offline', prs.getStatus(), \
prs.getFrom().getResource()))
elif type == 'subscribe':
log.debug("subscribe request from %s" % who)
if self.cfgParser.Core_alwaysauth == 1 or string.find(who, "@") <= 0:
if self.cfgParser.Core['alwaysauth'] == 1 or \
string.find(who, "@") <= 0:
self.con.send(common.jabber.Presence(who, 'subscribed'))
if string.find(who, "@") <= 0:
self.hub.sendPlugin('NOTIFY', (who, 'offline', 'offline', prs.getFrom().getResource()))
self.hub.sendPlugin('NOTIFY', (who, 'offline', 'offline', \
prs.getFrom().getResource()))
else:
self.hub.sendPlugin('SUBSCRIBE', who)
elif type == 'subscribed':
......@@ -79,7 +88,7 @@ class GajimCore:
'nom':jid.getNode(), 'ressource':jid.getResource()})
self.hub.queueIn.put(('UPDUSER', (jid.getBasic(), \
jid.getNode(), ['general'])))
# self.con.updateRosterItem(jid=jid.getBasic(), name=jid.getNode(), groups=['general'])
#BE CAREFUL : no self.con.updateRosterItem() in a callback
log.debug("we are now subscribed to %s" % who)
elif type == 'unsubscribe':
log.debug("unsubscribe request from %s" % who)
......@@ -87,17 +96,17 @@ class GajimCore:
log.debug("we are now unsubscribed to %s" % who)
self.hub.sendPlugin('UNSUBSCRIBED', prs.getFrom().getBasic())
elif type == 'error':
# print "\n\n******** ERROR *******"
# print "From : %s" % prs.getFrom()
# print "To : %s" % prs.getTo()
# print "Status : %s" % prs.getStatus()
# print "Show : %s" % prs.getShow()
# print "X : %s" % prs.getX()
# print "XNode : %s" % prs.getXNode()
# print "XPayload : %s" % prs.getXPayload()
# print "_node : %s" % prs._node.getData()
# print "kids : %s" % prs._node.kids[0].getData()
# print "\n\n"
print "\n\n******** ERROR *******"
#print "From : %s" % prs.getFrom()
#print "To : %s" % prs.getTo()
#print "Status : %s" % prs.getStatus()
#print "Show : %s" % prs.getShow()
#print "X : %s" % prs.getX()
#print "XNode : %s" % prs.getXNode()
#print "XPayload : %s" % prs.getXPayload()
#print "_node : %s" % prs._node.getData()
#print "kids : %s" % prs._node.kids[0].getData()
#print "\n\n"
errmsg = prs._node.kids[0].getData()
# END presenceCB
......@@ -112,14 +121,15 @@ class GajimCore:
def connect(self, account):
"""Connect and authentificate to the Jabber server"""
self.cfgParser.parseCfgFile()
hostname = self.cfgParser.__getattr__("%s" % account+"_hostname")
name = self.cfgParser.__getattr__("%s" % account+"_name")
password = self.cfgParser.__getattr__("%s" % account+"_password")
ressource = self.cfgParser.__getattr__("%s" % account+"_ressource")
self.con = common.jabber.Client(host = \
hostname, debug = [common.jabber.DBG_ALWAYS], log = sys.stderr, connection=common.xmlstream.TCP, port=5222)
# hostname, debug = [common.jabber.DBG_ALWAYS], log = sys.stderr, connection=common.xmlstream.TCP_SSL, port=5223)
hostname = self.cfgParser.tab[account]["hostname"]
name = self.cfgParser.tab[account]["name"]
password = self.cfgParser.tab[account]["password"]
ressource = self.cfgParser.tab[account]["ressource"]
self.con = common.jabber.Client(host = hostname, \
debug = [common.jabber.DBG_ALWAYS], log = sys.stderr, \
connection=common.xmlstream.TCP, port=5222)
#debug = [common.jabber.DBG_ALWAYS], log = sys.stderr, \
#connection=common.xmlstream.TCP_SSL, port=5223)
try:
self.con.connect()
except IOError, e:
......@@ -151,12 +161,14 @@ class GajimCore:
else:
log.debug("Couldn't authentificate to %s" % hostname)
self.hub.sendPlugin('STATUS', 'offline')
self.hub.sendPlugin('WARNING', 'Authentification failed, check your login and password')
self.hub.sendPlugin('WARNING', \
'Authentification failed, check your login and password')
return 0
# END connect
def mainLoop(self):
"""Main Loop : Read the incomming queue to execute commands comming from plugins and process Jabber"""
"""Main Loop : Read the incomming queue to execute commands comming from
plugins and process Jabber"""
while 1:
if not self.hub.queueIn.empty():
ev = self.hub.queueIn.get()
......@@ -166,6 +178,31 @@ class GajimCore:
self.con.disconnect()
self.hub.sendPlugin('QUIT', ())
return
#('ASK_CONFIG', section)
elif ev[0] == 'ASK_CONFIG':
if ev[1] == 'accounts':
self.hub.sendPlugin('CONFIG', self.accounts)
else:
self.hub.sendPlugin('CONFIG', \
self.cfgParser.__getattr__(ev[1]))
#('CONFIG', (section, config))
elif ev[0] == 'CONFIG':
if ev[1][0] == 'accounts':
#Remove all old accounts
accts = string.split(self.cfgParser.tab\
['Profile']['accounts'], ' ')
for a in accts:
del self.cfgParser.tab[a]
#Write all new accounts
accts = ev[1][1].keys()
self.cfgParser.tab['Profile']['accounts'] = \
string.join(accts)
for a in accts:
self.cfgParser.tab[a] = ev[1][1][a]
else:
self.cfgParser.tab[ev[1][0]] = ev[1][1]
self.cfgParser.writeCfgFile()
#TODO: tell the changes to other plugins
#('STATUS', (status, msg, account))
elif ev[0] == 'STATUS':
if (ev[1][0] != 'offline') and (self.connected == 0):
......@@ -198,17 +235,22 @@ class GajimCore:
self.con.send(common.jabber.Presence(ev[1], 'unsubscribed'))
#('UNSUB', jid)
elif ev[0] == 'UNSUB':
delauth = self.cfgParser.Core_delauth
if not delauth: delauth = 1
delroster = self.cfgParser.Core_delroster
if not delroster: delroster = 1
if self.cfgParser.Core.has_key('delauth'):
delauth = self.cfgParser.Core['delauth']
else:
delauth = 1
if self.cfgParser.Core.has_key('delroster'):
delroster = self.cfgParser.Core['delroster']
else:
delroster = 1
if delauth:
self.con.send(common.jabber.Presence(ev[1], 'unsubscribe'))
if delroster:
self.con.removeRosterItem(ev[1])
#('UPDUSER', (jid, name, groups))
elif ev[0] == 'UPDUSER':
self.con.updateRosterItem(jid=ev[1][0], name=ev[1][1], groups=ev[1][2])
self.con.updateRosterItem(jid=ev[1][0], name=ev[1][1], \
groups=ev[1][2])
elif ev[0] == 'REQ_AGENTS':
agents = self.con.requestAgents()
self.hub.sendPlugin('AGENTS', agents)
......@@ -239,7 +281,7 @@ class GajimCore:
else:
self.hub.sendPlugin('ACC_OK', ev[1])
else:
log.debug("Unknown Command")
log.debug("Unknown Command %s" % ev[0])
elif self.connected == 1:
self.con.process(1)
time.sleep(0.1)
......@@ -247,8 +289,9 @@ class GajimCore:
# END GajimCore
def loadPlugins(gc):
"""Load defaults plugins : 'modules' option in section Core in ConfFile and register then to the hub"""
modStr = gc.cfgParser.Core_modules
"""Load defaults plugins : plugins in 'modules' option of Core section
in ConfFile and register them to the hub"""
modStr = gc.cfgParser.Core['modules']
if modStr:
mods = string.split (modStr, ' ')
......@@ -266,6 +309,7 @@ def loadPlugins(gc):
gc.hub.register(mod, 'AGENT_INFO')
gc.hub.register(mod, 'QUIT')
gc.hub.register(mod, 'ACC_OK')
gc.hub.register(mod, 'CONFIG')
modObj.load()
# END loadPLugins
......@@ -273,6 +317,10 @@ def start():
"""Start the Core"""
gc = GajimCore()
loadPlugins(gc)
################ pr des tests ###########
gc.hub.sendPlugin('NOTIFY', ('aste@lagaule.org', 'online', 'online', 'oleron'))
# gc.hub.sendPlugin('MSG', ('ate@lagaule.org', 'msg'))
#########################################
try:
gc.mainLoop()
except KeyboardInterrupt:
......
......@@ -2,7 +2,6 @@
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
<glade-interface>
<requires lib="gnome"/>
<widget class="GtkWindow" id="Gajim">
<property name="visible">True</property>
......@@ -340,7 +339,6 @@
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<signal name="destroy" handler="gtk_widget_destroy" last_modification_time="Sun, 12 Oct 2003 18:17:05 GMT"/>
<signal name="check_resize" handler="on_check_resize" last_modification_time="Tue, 20 Jan 2004 16:57:47 GMT"/>
<child>
<widget class="GtkVBox" id="vbox2">
......
This diff is collapsed.
......@@ -4,7 +4,6 @@
## Gajim Team:
## - Yann Le Boulanger <asterix@crans.org>
## - Vincent Hanquez <tab@tuxfamily.org>
## - David Ferlier <david@yazzy.org>
##
## Copyright (C) 2003 Gajim Team
##
......@@ -29,17 +28,13 @@ class plugin:
def read_queue(self):
while 1:
while self.queueIN.empty() == 0:
lognotsep = self.cfgParser.Logger_lognotsep
if lognotsep:
lognotsep = string.atoi(lognotsep)
if self.config.has_key('lognotsep'):
lognotsep = self.config['lognotsep']
else:
#default
lognotsep = 1
lognotusr = self.cfgParser.Logger_lognotusr
if lognotusr:
lognotusr = string.atoi(lognotusr)
if self.config.has_key('lognotusr'):
lognotusr = self.config['lognotusr']
else:
#default
lognotusr = 1
# tim = time.strftime("%d%m%y%H%M%S")
tim = "%d" % time.time()
......@@ -74,12 +69,22 @@ class plugin:
fic.close()
time.sleep(0.5)
def wait(self, what):
"""Wait for a message from Core"""
#TODO: timeout, save messages that don't fit
while 1:
if not self.queueIN.empty():
ev = self.queueIN.get()
if ev[0] == what:
return ev[1]
time.sleep(0.1)
def __init__(self, quIN, quOUT):
self.cfgParser = common.optparser.OptionsParser(CONFPATH)
self.cfgParser.parseCfgFile()
self.queueIN = quIN
self.queueOUT = quOUT
#create ~/.gajim/logs if it doesn't exist
quOUT.put(('ASK_CONFIG', 'Logger'))
self.config = self.wait('CONFIG')
#create ~/.gajim/logs/ if it doesn't exist
try:
os.stat(os.path.expanduser("~/.gajim"))
except OSError:
......
......@@ -4,7 +4,6 @@
## Gajim Team:
## - Yann Le Boulanger <asterix@crans.org>
## - Vincent Hanquez <tab@tuxfamily.org>
## - David Ferlier <david@yazzy.org>
##
## Copyright (C) 2003 Gajim Team
##
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment