Exemple #1
0
static void Imo2sproxy_Loop(IMO2SPROXY *hInst)
{
	struct sockaddr_in sock;
	int socklen;
	SOCKET new_fd;
	TYP_LIST *hConns = List_Init(32);
	CONNINST *pInst;
	IMO2SPROXY_INST *hProxy = (IMO2SPROXY_INST*)hInst;
	fd_set fdListen;

	if (hProxy->pCfg->bVerbose && hProxy->pCfg->fpLog)
		fprintf (hProxy->pCfg->fpLog, "Socksproxy:Loop(Start)\n");
	hProxy->iRunning = 1;
	LockMutex(hProxy->loopmutex);
	while (hProxy->iRunning)
	{
		FD_ZERO(&fdListen);
		FD_SET(hProxy->listen_fd, &fdListen);
		socklen = sizeof(sock);
		if (select (0, &fdListen, NULL, NULL, NULL) != SOCKET_ERROR && FD_ISSET(hProxy->listen_fd, &fdListen))
		{
			new_fd = accept(hProxy->listen_fd, (struct sockaddr *) &sock, &socklen); 
			if (hProxy->pCfg->bVerbose && hProxy->pCfg->fpLog)
			{
				fprintf (hProxy->pCfg->fpLog, "Connection from %s:%d -> Connection: %d\n", inet_ntoa(sock.sin_addr),
					ntohs(sock.sin_port), new_fd);
				fflush (hProxy->pCfg->fpLog);
			}
			if (new_fd != INVALID_SOCKET && (pInst = calloc (1, sizeof(CONNINST))))
			{
				CleanConnections (hConns);
				List_Push(hConns, pInst);
				pInst->hSock = new_fd;
				pInst->hProxy = hProxy;
				InitMutex(pInst->connected);
				LockMutex(pInst->connected);
				InitMutex(pInst->sendmutex);
				Dispatcher_Start(pInst);
			}
		}
	}
	if (hProxy->pCfg->bVerbose && hProxy->pCfg->fpLog)
		fprintf (hProxy->pCfg->fpLog, "Socksproxy:Loop(End)\n");

	CleanConnections (hConns);
	while (pInst=List_Pop(hConns))
	{
		Dispatcher_Stop(pInst);
		FreeConnection(pInst);
		free (pInst);
	}
	List_Exit(hConns);
	UnlockMutex(hProxy->loopmutex);
}
Exemple #2
0
void HandlerSIGINT(int s)
{
  Trace("Suppression des ressources");
  fflush(stdout);
  CleanConnections();
  pthread_mutex_destroy(&mutexConnections);

  Trace("Suppression des IPC");
  if (msgctl(idQ,IPC_RMID,0))
  {
    perror("Erreur de suppression de la file de messages");
    exit(1);
  }
  
  if(shmdt(pShm))
  {
    perror("Erreur de detachement de la memoire partagee");
    exit(1);
  }

  if (shmctl(idM,IPC_RMID,0)) 
  {
    perror("Erreur de suppression de la memoire partagee");
    exit(1);
  }

  Trace("Fermeture du serveur");
  exit(0); 
}
Exemple #3
0
static LONG APIENTRY WndProc(HWND hWnd, UINT message, UINT wParam, LONG lParam) 
{ 
    switch (message) 
    { 
		case WM_CREATE:
		{
			LPCREATESTRUCT lpCr = (LPCREATESTRUCT)lParam;

			SetWindowLongPtr (hWnd, GWLP_USERDATA, (LONG_PTR)lpCr->lpCreateParams);
			SetTimer (hWnd, 0, 60000, NULL);
			break;
		}
        case WM_COPYDATA: 
		{
			PCOPYDATASTRUCT pCopyData = (PCOPYDATASTRUCT)lParam;
			CONNINST *pInst;
			IMO2SPROXY_INST *hProxy = (IMO2SPROXY_INST*)GetWindowLongPtr(hWnd, GWLP_USERDATA);

			if (pInst = FindClient (hProxy, (HWND)wParam))
			{
				if (pInst->hProxy->pMyCfg->bDelayLogin && pInst->iConnectionStat < 1)
				{
					char *pszError;

					if ((pInst->iConnectionStat = Imo2S_Login (pInst->hInst, hProxy->pCfg->pszUser, hProxy->pCfg->pszPass, &pszError)) != 1)
					{
						pInst->hProxy->pCfg->logerror (stderr, "Connection %08X: Cannot login with (%s/****): %s\n", 
							pInst->hWnd, hProxy->pCfg->pszUser, pszError);
						FreeConnection(pInst);
						free (List_Pop(hProxy->hClients));
						PostMessage ((HWND)wParam, m_ControlAPIAttach, (WPARAM)hWnd, SKYPECONTROLAPI_ATTACH_REFUSED);
						return 0;
					}
				}
				LockMutex(pInst->sendmutex);
				if (pInst->hProxy->pCfg->bVerbose && pInst->hProxy->pCfg->fpLog)
				{
					fprintf (pInst->hProxy->pCfg->fpLog, "%08X< [%s]\n", pInst->hWnd, pCopyData->lpData);
					fflush (pInst->hProxy->pCfg->fpLog);
				}
				Imo2S_Send (pInst->hInst, pCopyData->lpData);
				UnlockMutex(pInst->sendmutex);
			}
			return 1;
		}
		case WM_TIMER:
			// Housekeeping timer
			CleanConnections (((IMO2SPROXY_INST*)GetWindowLongPtr(hWnd, GWLP_USERDATA))->hClients);
			break;
		case WM_DESTROY:
			KillTimer (hWnd, 0);
			break;
		default:
			if (message == m_ControlAPIDiscover)
			{
				CONNINST *pInst;
				IMO2SPROXY_INST *hProxy = (IMO2SPROXY_INST*)GetWindowLongPtr(hWnd, GWLP_USERDATA);
				char *pszError;
				
				if (!(pInst = FindClient (hProxy, (HWND)wParam)))
				{
					pInst = (CONNINST*)calloc (1, sizeof(CONNINST));
					if (!pInst) break;
					List_Push(hProxy->hClients, pInst);
					pInst->hProxy = hProxy;
					pInst->hWnd = (HWND)wParam;
					if (hProxy->pCfg->bVerbose && hProxy->pCfg->fpLog)
						fprintf (hProxy->pCfg->fpLog, "Imo2sproxy::SkypeControlAPIDiscover\n");

					if (!(pInst->hInst = Imo2S_Init(EventHandler, pInst, hProxy->pCfg->iFlags)))
					{
						hProxy->pCfg->logerror (stderr, "Connection %08X: Cannot start Imo2Skype instance.\n", pInst->hWnd);
						free (List_Pop(hProxy->hClients));
						PostMessage ((HWND)wParam, m_ControlAPIAttach, (WPARAM)hWnd, SKYPECONTROLAPI_ATTACH_REFUSED);
						return 0;
					}

					// FIXME: We should enable logging dependent on a loglevel rather than just enabling it
					if (hProxy->pCfg->bVerbose)
						Imo2S_SetLog (pInst->hInst, hProxy->pCfg->fpLog);

					InitMutex(pInst->sendmutex);
					
					if (!pInst->hProxy->pMyCfg->bDelayLogin)
					{
						PostMessage ((HWND)wParam, m_ControlAPIAttach, (WPARAM)hWnd, SKYPECONTROLAPI_ATTACH_NOT_AVAILABLE);
						if ((pInst->iConnectionStat = Imo2S_Login (pInst->hInst, hProxy->pCfg->pszUser, hProxy->pCfg->pszPass, &pszError)) != 1)
						{
							pInst->hProxy->pCfg->logerror (stderr, "Connection %08X: Cannot login with (%s/****): %s\n", 
								pInst->hWnd, hProxy->pCfg->pszUser, pszError);
							FreeConnection(pInst);
							free (List_Pop(hProxy->hClients));
							PostMessage ((HWND)wParam, m_ControlAPIAttach, (WPARAM)hWnd, SKYPECONTROLAPI_ATTACH_REFUSED);
							return 0;
						}
						PostMessage ((HWND)wParam, m_ControlAPIAttach, (WPARAM)hWnd, SKYPECONTROLAPI_ATTACH_API_AVAILABLE);
					}
					else
					{
						SendMessage ((HWND)wParam, m_ControlAPIAttach, (WPARAM)hWnd, SKYPECONTROLAPI_ATTACH_SUCCESS);
					}
					return 0;
				}
				else
					SendMessage ((HWND)wParam, m_ControlAPIAttach, (WPARAM)hWnd, SKYPECONTROLAPI_ATTACH_SUCCESS);
				return 0;
			}
			break;
	}
	return (DefWindowProc(hWnd, message, wParam, lParam)); 
}