command.c 4.04 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/* VideoLAN VLANbridge: Remote administration commands
 *
 * Benoit Steiner, ECP, <benny@via.ecp.fr>
 *
 * TO DO: everything
 *
 * Note: the commands must be declared in the ascCommand variable of
 * the admin.c file in order to let the perser know about them
*/

/* ATTENTION: Il faudra absolument passer par le manager pour les requetes
parce que la base est pas lockee */


#include <pthread.h>
#include <stdio.h>
17 18
#include <string.h>
#include <errno.h>
19
#include <netinet/in.h>
20
#include <sys/sysinfo.h>
21 22

#include "debug.h"
23
#include "vlanbridge.h"
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
#include "network.h"
#include "admin.h"

extern struct s_Command ascCommand[];


/***************************************************************************/
/* */
/***************************************************************************/
int Logout(int iSockFd, int i, struct s_Argument* asaArg)
{
  return CMD_CLOSE;
}


/***************************************************************************/
/* */
/***************************************************************************/
int Help(int iSockFd, int iArgCount, struct s_Argument* asaArg)
{
  int iIndex = 0;

  if (iArgCount == 0)
  {
    /* Display a list of available command */
    while (strcmp(ascCommand[iIndex].strName, "") > 0)
    {
      SendResult(iSockFd, "%s: %s\n\r", ascCommand[iIndex].strName,
                 ascCommand[iIndex].strSummary);
      iIndex++;
    }
  }
  else
  {
    ASSERT(asaArg);
    
    /* Display help on a particular command */
    while (strcmp(ascCommand[iIndex].strName, "") > 0)
    {
      if ((!strcmp(ascCommand[iIndex].strName, asaArg[0].uVal.strValue)))
      {
        SendResult(iSockFd, "Usage: %s %s\n\r%s\n\r", ascCommand[iIndex].strName,
                   ascCommand[iIndex].strOptions, ascCommand[iIndex].strSummary);
        break;
      }
      else
        iIndex++;
    } 
    if (strcmp(ascCommand[iIndex].strName, "") == 0)
      SendResult(iSockFd, "Command '%s' does not exist\n\r",
                 asaArg[0].uVal.strValue);
  }
  
  SendResult(iSockFd, "\n\r");
  return 0;
}


82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
/***************************************************************************/
/* */
/***************************************************************************/
int ServerStatus(int iSockFd, int iArgCount, struct s_Argument* asaArg)
{
  int iRc = 0;
  struct sysinfo siStatus;  
  int iDaysUptime, iHoursUptime, iMinUptime;
  
  iRc = sysinfo(&siStatus);
  
  if(!iRc)
  {
    /* Convert the date given in seconds to days/hours/minutes */
    iDaysUptime = siStatus.uptime/86400;
    siStatus.uptime -= iDaysUptime*86400;
    iHoursUptime = siStatus.uptime/3600;
    siStatus.uptime -= iHoursUptime*3600;
    iMinUptime = siStatus.uptime/60;

    /* Extract interessting info from the siStatus struct */
    SendResult(iSockFd,
               "VLANbridge version " VERSION " (built " __DATE__ ")\n\r"
               "  Uptime: %u days, %u hours, %u min\n\r"
               "  Free mem: %lu - Load: %lu\n\r", 
               iDaysUptime, iHoursUptime, iMinUptime,
               siStatus.freeram, siStatus.loads[0]);
  }
  else
  {
    /* Return the error description */
    SendResult(iSockFd, "Could not get system stats: %s", strerror(errno));
  }

  SendResult(iSockFd, "\n\r");
  return iRc;
}



122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
/***************************************************************************/
/* */
/***************************************************************************/
int HostInfo(const char* strHostName)
{  
//  struct s_Record* psrHostInfo;
//  struct sockaddr_in saHost;
//  /* Resol DNS */

  ASSERT(strHostName);

//  psrHostInfo = FindInBase(base, &saHost);
  
//  if(psrHostInfo)
//  {
    
//  }
//  else
//  {
//    /* Not Found */
//  }
  return 0;
}


/***************************************************************************/
/* */
/***************************************************************************/
int HostReinit(const char* strHostName)
{
  return 0;
}


/***************************************************************************/
/* */
/***************************************************************************/
int BridgeReinit()
{
  return 0;
}