Commit 7d2f649e authored by Laurent Rossier's avatar Laurent Rossier

- Fix bugs in the IF_info function in the interface :

    add DB_switchs_port_unlock
    remove segfault when you wanted to have info on a MAC
- Fix the bug when you wanted to logout and to reconnect
- Add some return values in reinit_switch.c -> TODO modified
- Remove the struct IF_telnet

Nitrox could you see if the comment in the logger.c for the VS_R_NUMBER is
good ?
parent 7514c6be
......@@ -128,7 +128,7 @@ all: dir dep $(TARGET)
dep: $(DEPS) $(LEXDEPS)
$(TARGET): $(OBJECTS) $(LEXOBJECTS)
echo "Final linking"
@echo "Final linking"
$(CC) -o $@ $(OBJECTS) $(LEXOBJECTS) $(CFLAGS) $(LDLIBS) $(LPATH) $(IPATH)
$(DEPS): deps/%.d: %.c
......
......@@ -21,7 +21,7 @@ Urgency: Important
Description: SRV: Return codes
grep return server/reinit.c
You will understand the problem !
Status: Todo
Status: Done, gunther
Task: 0x16
Difficulty: Hard
......
......@@ -3,7 +3,7 @@
* Main functions that are use by interfaces
*****************************************************************************
* Copyright (C) 1998, 1999, 2000, 2001 VideoLAN
* $Id: interface.c,v 1.11 2001/09/13 13:55:42 nitrox Exp $
* $Id: interface.c,v 1.12 2001/09/25 16:16:54 gunther Exp $
*
* Authors: Damien Lucas <nitrox@via.ecp.fr>
*
......@@ -91,14 +91,14 @@ ERR_CODE IF_start(void)
/*****************************************************************************
* IF_stop : Stops the interface module
* IF_module_stop : Stops the interface module
*****************************************************************************
* Called from the main part it will stop
* the appropriate module
*****************************************************************************/
char* IF_module_stop(struct IF_module* module, char* douze)
{
module->uDie=1;
module->uLogout=1;
return NULL;
}
......@@ -304,7 +304,7 @@ char* IF_reload(struct IF_module* module)
/*****************************************************************************
* IF_login: Log a user with a password
* IF_Auth: Log a user with a password
*****************************************************************************
* Called from any of the interface submodules
* Use MD5 encryption
......@@ -365,6 +365,7 @@ ERR_CODE IF_Auth(char* sUser, char* sPasswd)
*/
VS_log(LOGDEBUG,TELNET, "User %s, login sucessful", sUser);
return 0;
}
......@@ -375,7 +376,7 @@ ERR_CODE IF_Auth(char* sUser, char* sPasswd)
* Called from any of the interface submodules
* Return value: the answer (char *)
*****************************************************************************/
char* IF_info(struct IF_module* module,char* sMac)
char* IF_info(struct IF_module* module, char* sMac)
{
unsigned int rc;
struct DB_machines_elt* machine_elt;
......@@ -383,17 +384,36 @@ char* IF_info(struct IF_module* module,char* sMac)
struct SNMP_switch * zwitch;
struct DB_port * port;
VS_MachineId mMac;
unsigned int i1, i2, i3, i4, i5;
sMessage=malloc(256*sizeof(char));
if(sMessage==NULL)
{
VS_log(LOGERROR,IF,"Unable to allocate memory");
return "Memory error";
}
if((sMac==NULL) || (sscanf(sMac, "%x:%x:%x:%x:%x:%x", (unsigned *)&mMac,&i1,
&i2, &i3, &i4, &i5)!=6))
{
VS_log(LOGINFO,IF,"No MAC specify in db->info function");
return "You have to specify the MAC after the command\r\n";
}
mMac<<=8;
mMac|=i1;
mMac<<=8;
mMac|=i2;
mMac<<=8;
mMac|=i3;
mMac<<=8;
mMac|=i4;
mMac<<=8;
mMac|=i5;
/* 2. Looking for Mac inside db */
rc=DB_machines_lock(vs->db, mMac, &machine_elt);
if(rc)
{
sprintf(sMessage,"Mac not found in database\r\n");
......@@ -430,12 +450,10 @@ char* IF_info(struct IF_module* module,char* sMac)
(unsigned int)zwitch->ports[machine_elt->port].vlan);
}
DB_switchs_port_unlock(vs->db, port);
}
DB_machines_unlock(vs->db, machine_elt);
}
DB_machines_unlock(vs->db, machine_elt);
/* 3. Message has to send to the module */
return sMessage;
......
......@@ -3,7 +3,7 @@
* Header file for interface.c
*****************************************************************************
* Copyright (C) 1998, 1999, 2000, 2001 VideoLAN
* $Id: interface.h,v 1.7 2001/09/04 17:07:44 nitrox Exp $
* $Id: interface.h,v 1.8 2001/09/25 16:16:54 gunther Exp $
*
* Authors: Damien Lucas <nitrox@via.ecp.fr>
*
......@@ -77,6 +77,7 @@ struct IF_Command
struct IF_module
{
unsigned int uDie;
unsigned int uLogout;
};
......
......@@ -3,7 +3,7 @@
* Provide a telnet interface
*****************************************************************************
* Copyright (C) 1998, 1999, 2000, 2001 VideoLAN
* $Id: telnet.c,v 1.20 2001/09/13 13:55:42 nitrox Exp $
* $Id: telnet.c,v 1.21 2001/09/25 16:16:54 gunther Exp $
*
* Authors: Damien Lucas <nitrox@via.ecp.fr>
*
......@@ -71,7 +71,7 @@ static void Prompt_send(int iSocket, char* sUser, struct IF_Menu* mMenu);
/*****************************************************************************
* IF_telnet() Main function of the telnet interface
* IF_telnet_main() Main function of the telnet interface
*****************************************************************************/
void* IF_telnet_main(void* p_void)
{
......@@ -134,6 +134,7 @@ void* IF_telnet_main(void* p_void)
sUser=IF_telnet_login(newsock);
if(sUser!=NULL)
{
telnet->uLogout=0;
IF_telnet_commands(telnet,newsock,sUser);
}
......@@ -254,7 +255,7 @@ static void IF_telnet_commands (struct IF_module* telnet,
mMenu = IF_Menu_init();
while(!telnet->uDie)
while(!telnet->uDie && !telnet->uLogout)
{
Menu_send(iSocket,mMenu);
Prompt_send(iSocket,sUser,mMenu);
......@@ -276,7 +277,7 @@ static void IF_telnet_commands (struct IF_module* telnet,
{
sAnswer = mMenu->cCommand[z].uAction.function(
telnet,
sCmd[strlen(mMenu->cCommand[z].sName)+1]);
&sCmd[strlen(mMenu->cCommand[z].sName)+1]);
}
else
{
......@@ -461,7 +462,8 @@ static char* Catch_Word (int iSocket, struct IF_Menu* mMenu)
default:
if (((bBuff>='0')&&(bBuff<='9')) || ((bBuff>='A')&&(bBuff<='Z')) || \
((bBuff>='a')&&(bBuff<='z')) || (bBuff=='.') || (bBuff==' ') )
((bBuff>='a')&&(bBuff<='z')) || (bBuff=='.') || (bBuff==' ') || \
(bBuff==':'))
{
sData[iPos]=bBuff;
iPos++;
......
......@@ -3,7 +3,7 @@
* Header file for telnet.c
*****************************************************************************
* Copyright (C) 1998, 1999, 2000, 2001 VideoLAN
* $Id: telnet.h,v 1.6 2001/09/04 17:07:44 nitrox Exp $
* $Id: telnet.h,v 1.7 2001/09/25 16:16:54 gunther Exp $
*
* Authors: Damien Lucas <nitrox@via.ecp.fr>
*
......@@ -27,10 +27,4 @@
void* IF_telnet_main(void* telnet);
struct IF_telnet
{
unsigned int uDie;
};
#endif
......@@ -3,7 +3,7 @@
* Print a log to a file or to screen
*****************************************************************************
* Copyright (C) 1998, 1999, 2000, 2001 VideoLAN
* $Id: logger.c,v 1.20 2001/05/28 00:49:41 marcari Exp $
* $Id: logger.c,v 1.21 2001/09/25 16:16:54 gunther Exp $
*
* Authors: Damien Lucas <nitrox@via.ecp.fr>
* Marc Ariberti <marcari@via.ecp.fr>
......@@ -644,12 +644,15 @@ char * VS_log_errstr(ERR_CODE err)
"no error",
"object not found",
"trying to do a walk on a switch is currently walked by an other thread",
"the authentification failed",
"unable to bind a socket",
"unable to connect to remote host",
"unable to stop the database",
"unable to resolve the dns",
"initiatization of the switch failed",
"unable to open, read or write a file",
"unable to allocate memory",
"pb with the number",
"parse error",
"pipe creation error",
"unable to write to a pipe",
......@@ -658,6 +661,7 @@ char * VS_log_errstr(ERR_CODE err)
"unable to send data to remote host",
"unable to execute a select() operation",
"snmp error",
"unable to stop the snmp",
"unable to open a socket",
"time error",
"timeout"
......
......@@ -4,7 +4,7 @@
* Warning: header are in server.c
*****************************************************************************
* Copyright (C) 1998, 1999, 2000, 2001 VideoLAN
* $Id: reinit_switchs.c,v 1.9 2001/04/29 03:41:49 nitrox Exp $
* $Id: reinit_switchs.c,v 1.10 2001/09/25 16:16:54 gunther Exp $
*
* Authors: Laurent Rossier <gunther@via.ecp.fr>
*
......@@ -72,7 +72,7 @@ ERR_CODE VS_reinit_switchs_thread(struct VS_info_poller * info_poller)
rc=VS_reinit_switchs (info_poller);
if(rc)
{
return 12;
return VS_R_INIT_FAILED;
}
}
return 0;
......@@ -106,7 +106,7 @@ ERR_CODE VS_reinit_switchs (struct VS_info_poller * info_poller)
VS_log(LOGERROR, SERVER, "unable to stop the snmp");
VS_log(LOGFATAL, SERVER, "stop the reinit operation of the db");
VS_stop(info_poller);
return 12;
return VS_R_SNMP_STOP;
}
/* sleep for the timeout of the switches */
#ifdef DEBUG
......@@ -121,7 +121,7 @@ ERR_CODE VS_reinit_switchs (struct VS_info_poller * info_poller)
VS_log(LOGERROR, SERVER, "unable to stop the db");
VS_log(LOGFATAL, SERVER, "stop the reinit operation of the db");
VS_stop(info_poller);
return 12;
return VS_R_DB_STOP;
}
......@@ -130,7 +130,7 @@ ERR_CODE VS_reinit_switchs (struct VS_info_poller * info_poller)
if(rc)
{
VS_log(LOGERROR, SERVER, "unable to restart the snmp");
return 12;
return VS_R_SNMP;
}
/* We should not start the db_init before snmp loop started */
......
......@@ -4,7 +4,7 @@
* Provide all typedefs
*****************************************************************************
* Copyright (C) 1998, 1999, 2000, 2001 VideoLAN
* $Id: types.h,v 1.19 2001/09/04 17:07:44 nitrox Exp $
* $Id: types.h,v 1.20 2001/09/25 16:16:54 gunther Exp $
*
* Authors:
*
......@@ -61,12 +61,15 @@ typedef unsigned char VS_UNIT;
typedef enum {VS_R_OK,
VS_R_ABSENT,
VS_R_ALREADY_WALKING,
VS_R_AUTH_FAILURE,
VS_R_BIND,
VS_R_CONNECT,
VS_R_DB_STOP,
VS_R_DNS,
VS_R_INIT_FAILED,
VS_R_FILE,
VS_R_MEMORY,
VS_R_NUMBER,
VS_R_PARSE,
VS_R_PIPE,
VS_R_PIPE_WRITE,
......@@ -75,11 +78,10 @@ typedef enum {VS_R_OK,
VS_R_SEND,
VS_R_SELECT,
VS_R_SNMP,
VS_R_SNMP_STOP,
VS_R_SOCKET,
VS_R_TIME,
VS_R_TIMEOUT,
VS_R_NUMBER,
VS_R_AUTH_FAILURE} ERR_CODE;
VS_R_TIMEOUT}ERR_CODE;
/* LOG_MODULES : modules of the VLANserver */
typedef enum {SERVER,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment