Beispiel #1
0
void
Log::Register(const char *signature) const
{
    std::string sign(signature);

    if(!signature || !signature[0])
    {
        defaultSignature.reset(sign, m_Prefix, Level(), Service());
        return;
    }

    std::list<struct SavedSignature>::iterator it, end;

    it = signList.begin();
    end = signList.end();
    for(; it != end; ++it)
    {
        if(sign == it->m_Signature)
        {
            (*it).reset(sign, m_Prefix, Level(), Service());
            return;
        }
    }
    signList.push_back(SavedSignature(sign, m_Prefix, Level(), Service()));
}
bool GPlayerAccess::ProcessMessage(GNetMsg & msg,int message)
{
	switch(message)
	{
	case IGM_ACCESS:
		{
			if(Valid())
			{
				GSocketAccess * sa=static_cast<GSocketAccess*>(socket);
				GTicketConnectionClient t_connection_client;
				msg.R(t_connection_client);
				if (*t_connection_client.access.target_location_ID == 0)
				{
					if (t_connection_client.access.target_gamestate_ID > 0)
					{
						strcpy(t_connection_client.access.target_location_ID, location_ID_from_gamestate_ID(t_connection_client.access.target_gamestate_ID).c_str());
					}
				}
				else
				{
					t_connection_client.access.target_gamestate_ID = gamestate_ID_from_location_ID(t_connection_client.access.target_location_ID);
				}

				sockaddr_in addr;
				socklen_t len=sizeof(addr);
				getpeername(socket->GetSocket(),(sockaddr*)&addr,&len);
				memcpy(&t_connection_client.client_host.addr_detected_by_server,&addr.sin_addr,4);

				t_connection_client.access.RID=GetRID();

				if (Service(ESTClientAccess)->GetOutQueueSize() >= global_serverconfig->net.ticket_queue_busy_limit ||
					Service(ESTClientAccess)->GetWaitQueueSize() >= global_serverconfig->net.ticket_queue_busy_limit)
				{
					MsgExt(IGM_CONNECTION_CLOSE).WT("server busy").A();
					return true;
				}

				GTicketConnectionPtr ticket(new GTicketConnection());
				Coerce(*ticket,t_connection_client);

				TicketInt(ESTClientAccess,IGMITIC_ACCESS,ticket);
				Coerce(sa->player_info,t_connection_client);
				sa->group_id = t_connection_client.access.group_ID;
			}
		}
		return true;
	}
	return false;
};
Beispiel #3
0
void
Log::WriteString(const char* str, int strLen)
{
    const char *ptr;

    if(strLen < 0)
    {
        strLen = strlen(str);
    }

    for(;strLen > 0;)
    {
        if(!m_String.length())
        {
            m_String = m_Prefix.c_str();
        }

        ptr = (const char*)memchr(str, '\n', strLen);
        if(!ptr)
        {
            m_String.append(str, strLen);
            return;
        }

        m_String.append(str, ++ptr - str);
        Multiplexor().WriteString(Level(), Service(), m_String.c_str(), m_String.length());
        m_String.resize(0);
        strLen -= ptr - str;
        str = ptr;
    }
}
Beispiel #4
0
/*--------------------------------------------------------------------*/
void Servlet(int sd, int timeout)
{   int hasAlarm=0;

    if ( timeout > 0 )
    {
        bzero(&act, sizeof(act));
        act.sa_handler = sig_handler;
        hasAlarm = ( sigaction(SIGALRM, &act, 0) == 0 );
    }
    for (;;)
    {   int client, addlen=sizeof(addr);

        if ( hasAlarm  &&  timeout > 0 )
            alarm(timeout);
        client = accept(sd, (struct sockaddr*)&addr, &addlen);
        if ( client > 0 )
            Service(client);
        else
        {
            perror("accept");
            if ( client == EINTR )
                exit(0);
        }
    }
}
void CAknWsService::Delete(CAknWsServiceCRP* aSrv) 
	{
	CAknWsService* srv = Service();
	if(srv != NULL)
		{
		if(aSrv == srv->iService)
			{
			srv->iEnv->UnregisterEventHandler(aSrv);
			if(aSrv->iNext != NULL)
				{
				srv->iEnv->RegisterEventHandler(aSrv->iNext, srv, KMonitoredEvents);
				}
			else  
				{
				srv->iService = NULL;	
				delete srv;
				Dll::SetTls(NULL);
				return;
				}
			}
			
		CAknWsServiceCRP* s = srv->iService;
		while(s->iNext != aSrv)
			{
			s = s->iNext;
			ASSERT(s != NULL);
			}
		s->iNext = aSrv->iNext;	
		}
	}
void CAknWsService::CreateL(MWsGraphicDrawerEnvironment& aEnv, CAknWsServiceCRP* aSrv)
	{
	CAknWsService* srv = Service();
	if(srv == NULL)
		{
		srv = new (ELeave) CAknWsService(aEnv);
		CleanupStack::PushL(srv);
		srv->ConstructL();
		CleanupStack::Pop();
		Dll::SetTls(srv);
		}
	else
		{
		CAknWsServiceCRP* s = srv->iService;
		if(s != NULL)
			{
			while(s->iNext != NULL)
				s = s->iNext;
			s->iNext = aSrv;
			return;
			}
		}
	srv->iService = aSrv;
	aEnv.RegisterEventHandler(aSrv, srv, KMonitoredEvents);	
	}
Beispiel #7
0
    void Browser::resolve_callback(AvahiServiceResolver *r,
				   AvahiIfIndex,
				   AvahiProtocol,
				   AvahiResolverEvent event,
				   const char *name,
				   const char *type,
				   const char *,
				   const char *host_name,
				   const AvahiAddress *address,
				   uint16_t port,
				   AvahiStringList *txt,
				   AvahiLookupResultFlags,
				   void *data)
    {
	assert(data);
	Browser *browser = static_cast<Browser *>(data);
	assert(r);

	switch (event) {
	case AVAHI_RESOLVER_FAILURE:
	    //cerr << "[Resolver] Failed to resolve service '" << name << "' of type '" << type << "' in domain '" << domain
	    //	 << "': " << avahi_strerror(avahi_client_errno(avahi_service_resolver_get_client(r))) << endl;
	    break;

	case AVAHI_RESOLVER_FOUND:
	    //cerr << "[Resolver] Service '" << name << " (" << host_name << ":" << port << ")"
	    //     << "' of type '" << type <<"' in domain '" << domain << "'" << endl;

	    //cout << a->browse_services_.size() << endl;
	    browser->add_service(name, Service(type, host_name, address, port, txt));
	    // XXX cache service, broadcast

#if 0
            avahi_address_snprint(a, sizeof(a), address);
            t = avahi_string_list_to_string(txt);
            fprintf(stderr,
                    "\t%s:%u (%s)\n"
                    "\tTXT=%s\n"
                    "\tcookie is %u\n"
                    "\tis_local: %i\n"
                    "\tour_own: %i\n"
                    "\twide_area: %i\n"
                    "\tmulticast: %i\n"
                    "\tcached: %i\n",
                    host_name, port, a,
                    t,
                    avahi_string_list_get_service_cookie(txt),
                    !!(flags & AVAHI_LOOKUP_RESULT_LOCAL),
                    !!(flags & AVAHI_LOOKUP_RESULT_OUR_OWN),
                    !!(flags & AVAHI_LOOKUP_RESULT_WIDE_AREA),
                    !!(flags & AVAHI_LOOKUP_RESULT_MULTICAST),
                    !!(flags & AVAHI_LOOKUP_RESULT_CACHED));

            avahi_free(t);
#endif
	}

	avahi_service_resolver_free(r);
    }
Beispiel #8
0
void WiredPage::disconnect()
{
    QString service = Connman::instance()->ethernetService();
    if (service.isEmpty())
        return;

    Service(service, this).disconnect();
}
Beispiel #9
0
void
Log::flush()
{
    if(m_String.length())
    {
        Multiplexor().WriteString(Level(), Service(), m_String.c_str(), m_String.length());
        m_String.resize(0);
    }
}
Beispiel #10
0
Log::~Log()
{
    if(m_String.length())
    {
        m_String.append("\n");
        Multiplexor().WriteString(Level(), Service(), m_String.c_str(), m_String.length());
    }
    Multiplexor().DetachLogger(this, m_iInMultiplexor);
}
void Restart()
{
    FILE * fp = fopen( PID_FILE, "rb" );
    if( fp )
	{
		pid_t pid;
		fread( &pid, 1, sizeof( pid ), fp );
		kill( pid, SIGTERM );
	}
	Service();
}
void cDBusMessagePlugin::Process(void)
{
  switch (_action) {
    case dmpSVDRPCommand:
      SVDRPCommand();
      break;
    case dmpService:
      Service();
      break;
    }
}
Beispiel #13
0
void WiredPage::updateButtonsVisibility()
{
    bool enabled = Connman::instance()->isTechnologyEnabled("ethernet");
    bool connected = Connman::instance()->isTechnologyConnected("ethernet");

    ui.enableCheck->setChecked(enabled);

    ui.connectButton->setEnabled(enabled);
    ui.disconnectButton->setEnabled(enabled);
    ui.configFrame->setEnabled(enabled && !connected);

    if (!enabled)
    {
        ui.status->setText(tr("Disabled"));
        ui.info->setText("");
    }

    QString state = Technology(Connman::instance()->technologyPath("ethernet"), this).state();
    if (state == "connected" || connected)
    {
        ui.connectButton->setEnabled(false);
        ui.disconnectButton->setEnabled(true);
        ui.status->setText(tr("Connected"));
        ui.info->setText(tr("Wired device is connected and has the IP Address %1")
                         .arg(Service(Connman::instance()->ethernetService(), this).ipv4Settings()["Address"].toString()));
    }
    else if (enabled && (state == "offline" || !connected))
    {
        ui.connectButton->setEnabled(true);
        ui.disconnectButton->setEnabled(false);
        ui.status->setText(tr("Disconnected"));
        ui.info->setText("");
    }

    QString servicePath = Connman::instance()->ethernetService();
    if (!servicePath.isEmpty())
        ui.ipv4Widget->setSettings(Service(servicePath, this).ipv4Settings());
}
Beispiel #14
0
int Loop()
{
	pid_t pid;
	int  status;

	while(link_count > 0)
	{
		pid = Receive(0, &msg, sizeof(msg));

		if(pid == -1) {
			if(errno != EINTR) {
				Log("Receive() failed: [%d] %s", ERR(errno));
			}
			continue;
		}
		if(pid == IrqProxy()) {
			while(Creceive(pid, 0, 0) == pid)
				; // clear out any proxy overruns

			add_interrupt_randomness(options.irq);

//			Log("Irq: random size %d\n", get_random_size());

			// now that we have more entropy...
			SelectTrigger();
			DoReadQueue();

			continue;
		}

		status = Service(pid, &msg);

		Log("Service() returned status %d (%s), link_count %d",
			status, status == -1 ? "none" : strerror(status), link_count);

		if(status >= EOK) {
			msg.status = status;
			ReplyMsg(pid, &msg, sizeof(msg.status));
		}
	}
	return 0;
}
void Start()
{
  FILE * fp = fopen( PID_FILE, "rb" );
	if( fp )
	{
		pid_t pid;
		fread( &pid, 1, sizeof( pid ), fp );
		fclose( fp );
		if( kill( pid, 0 ) )
		{
			remove( PID_FILE );
		}
		else
		{
			printf( "[Info] 数据库服务已在运行,无法再次启动!\n" );
			return ;
		}
	}
	Service();
}
Beispiel #16
0
int MyServer::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: updateTextBrowser((*reinterpret_cast< QString(*)>(_a[1]))); break;
        case 1: updateTextBrowserDlg((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break;
        case 2: addtoListWidget((*reinterpret_cast< QString(*)>(_a[1]))); break;
        case 3: deletefromListWidget((*reinterpret_cast< QString(*)>(_a[1]))); break;
        case 4: Service(); break;
        case 5: Accept(); break;
        case 6: DisplayError((*reinterpret_cast< QAbstractSocket::SocketError(*)>(_a[1]))); break;
        case 7: OnDisconnected(); break;
        default: ;
        }
        _id -= 8;
    }
    return _id;
}
cString cPluginXinelibOutput::SVDRPCommand(const char *Command, const char *Option, int &ReplyCode)
{
  if(strcasecmp(Command, "PMDA") == 0) {
    if(*Option) {
      LOGMSG("SVDRP(%s, %s)", Command, Option);
      cPlayerFactory::Launch(m_Dev, pmAudioVideo, Option);
      return cString("Playing video file");
    } else {
      ReplyCode = 550; // Requested action not taken
      return cString("File name missing");
    }
  }

  else if(strcasecmp(Command, "PDVD") == 0) {
    if(*Option) {
      LOGMSG("SVDRP(%s, %s)", Command, Option);
      cPlayerFactory::Launch(m_Dev, pmNone, Option);
    } else {
      cPlayerFactory::Launch(m_Dev, pmNone, "dvd:/");
    }
    return cString("Playing DVD disc");
  }

  else if(strcasecmp(Command, "PMSC") == 0) {
    if(*Option) {
      LOGMSG("SVDRP(%s, %s)", Command, Option);
      cPlayerFactory::Launch(m_Dev, pmAudioOnly, Option);
      return cString("Playing music file");
    } else {
      ReplyCode = 550; // Requested action not taken
      return cString("Music file name missing");
    }
  }

  else if(strcasecmp(Command, "PIMG") == 0) {
    if(*Option) {
      LOGMSG("SVDRP(%s, %s)", Command, Option);
      cPlayerFactory::Launch(m_Dev, pmVideoOnly, Option);
      return cString("Showing image file");
    } else {
      ReplyCode = 550; // Requested action not taken
      return cString("Image file name missing");
    }
  }

  else if(strcasecmp(Command, "QMSC") == 0) {
    if(*Option) {
      LOGMSG("SVDRP(%s, %s)", Command, Option);
      cPlayerFactory::Queue(m_Dev, Option);
      return cString("Queueing music file");
    } else {
      ReplyCode = 550; // Requested action not taken
      return cString("Music file name missing");
    }
  }

  else if(strcasecmp(Command, "LFRO") == 0) {
    if(*Option) {
      LOGMSG("SVDRP(%s, %s)", Command, Option);
      Service("StartFrontend-1.0", (void*)Option);
      return cString::sprintf("Local frontend: %s", xc.local_frontend);
    } else {
      ReplyCode = 550; // Requested action not taken
      return cString("Local frontend name missing");
    }
  }

  else if(strcasecmp(Command, "PRIM") == 0) {
    int primary = 0;
    if(*Option) {
      LOGMSG("SVDRP(%s, %s)", Command, Option);
      primary = strtol(Option, NULL, 0);
    } else {
      LOGMSG("SVDRP(%s)", Command);
    }
    if(!primary && m_Dev)
        primary = m_Dev->DeviceNumber() + 1;
    m_MakePrimary = primary;
    return cString::sprintf("Switching primary device to %d", primary);
  }

  return NULL;
}
Beispiel #18
0
bool wxIPaddress::operator==(const wxIPaddress& addr) const
{
    return Hostname().Cmp(addr.Hostname()) == 0 &&
           Service() == addr.Service();
}
Beispiel #19
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
    {
      CORBA::ORB_var orb =
        CORBA::ORB_init (argc, argv);

      CORBA::Object_var poa_object =
        orb->resolve_initial_references("RootPOA");

      PortableServer::POA_var root_poa =
        PortableServer::POA::_narrow (poa_object.in ());

      if (CORBA::is_nil (root_poa.in ()))
        ACE_ERROR_RETURN ((LM_ERROR,
                           " (%P|%t) Panic: nil RootPOA\n"),
                          1);

      PortableServer::POAManager_var poa_manager =
        root_poa->the_POAManager ();

      // Make all oneways "reliable."
      {
        CORBA::Object_var manager_object =
          orb->resolve_initial_references("ORBPolicyManager");
        CORBA::PolicyManager_var policy_manager =
          CORBA::PolicyManager::_narrow(manager_object.in());

        if (CORBA::is_nil (policy_manager.in ()))
          ACE_ERROR_RETURN ((LM_ERROR,
                             " (%P|%t) Panic: nil PolicyManager\n"),
                            1);
        CORBA::Any policy_value;
        policy_value <<= Messaging::SYNC_WITH_SERVER;
        CORBA::PolicyList policies(1); policies.length(1);
        policies[0] =
          orb->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE,
                              policy_value);

        policy_manager->set_policy_overrides (policies,
                                              CORBA::ADD_OVERRIDE);

        policies[0]->destroy ();
      }

      if (parse_args (argc, argv) != 0)
        return 1;

      Service *service_impl;
      ACE_NEW_RETURN (service_impl,
                      Service(orb.in ()),
                      1);
      PortableServer::ServantBase_var owner_transfer(service_impl);

      PortableServer::ObjectId_var id =
        root_poa->activate_object (service_impl);

      CORBA::Object_var object = root_poa->id_to_reference (id.in ());

      Test::Service_var service =
        Test::Service::_narrow (object.in ());

      CORBA::String_var ior =
        orb->object_to_string (service.in ());

      // If the ior_output_file exists, output the ior to it
      FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
      if (output_file == 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "Cannot open output file for writing IOR: %s",
                           ior_output_file),
                              1);
      ACE_OS::fprintf (output_file, "%s", ior.in ());
      ACE_OS::fclose (output_file);

      poa_manager->activate ();

      orb->run ();

      ACE_DEBUG ((LM_DEBUG, "Event loop finished\n"));

      root_poa->destroy (1, 1);

      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception caught:");
      return 1;
    }

  return 0;
}
Beispiel #20
0
#include <map>
#include <vector>

#define __MODULE

#include "../../src/helpers.h"
#include "../../src/server.h"

typedef struct serv {
	std::string daemonName;
	std::string serviceName;
	serv(std::string _daemonName, std::string _serviceName) : daemonName(_daemonName), serviceName(_serviceName) {}
} Service;

static std::vector<Service> services = { 
	Service("quagga", "Quagga Router"),
	Service("iptables", "iptables firewall"),
	Service("adaptativefirewall", "Adaptative Firewall")
};

extern "C" bool checkIfServiceIsRunning(const std::string & name)
{
	char buf[256];
	memset(buf, 0, sizeof(buf));
	FILE *p;
	p = popen(std::string("service " + name + " status").c_str(), "r");
	fgets(buf, 256, p);
	fclose(p);
	if(std::string(buf).find("start/running") != std::string::npos || std::string(buf).find("is running") != std::string::npos)
	{
		return true;