ReactOS  0.4.14-dev-49-gfb4591c
netreg.cpp File Reference
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <map>
#include <string>
#include <sstream>
#include <iomanip>
Include dependency graph for netreg.cpp:

Go to the source code of this file.

Classes

class  RequestHandler
 

Functions

SOCKET make_listening_socket (int port)
 
int main (int argc, char **argv)
 

Variables

const charroot_entries []
 
const HKEY root_handles []
 

Function Documentation

◆ main()

int main ( int argc  ,
char **  argv 
)

Definition at line 436 of file netreg.cpp.

436  {
437  WSADATA wdWinsockData;
439  fd_set pollin,pollout,pollerr;
440  SOCKET listen_socket;
441  int i;
442  int port_to_listen = 80;
443  unsigned int active_fds = 0;
444 
445  for( i = 1; i < argc; i++ ) {
446  if( string( "-p" ) == argv[i] ) {
447  i++;
448  if( i < argc ) port_to_listen = atoi( argv[i] );
449  }
450  }
451 
452  WSAStartup( 0x0101, &wdWinsockData );
453 
454  listen_socket = make_listening_socket( port_to_listen );
455  if( listen_socket == INVALID_SOCKET ) return 1;
456 
457  while( true ) {
458  FD_ZERO( &pollin );
459  FD_ZERO( &pollout );
460  FD_ZERO( &pollerr );
461  active_fds = listen_socket + 1;
462 
463  for( std::map<SOCKET,RequestHandler *>::iterator i = requests.begin();
464  i != requests.end();
465  i++ ) {
466  if( i->second->ShouldDie() ) {
467  delete i->second;
468  requests.erase( i );
469  i = requests.begin();
470  break;
471  }
472 
473  FD_SET(i->first,&pollin);
474  FD_SET(i->first,&pollerr);
475 
476  if( i->first > active_fds ) active_fds = i->first + 1;
477 
478  if( i->second->WantPollout() ) FD_SET(i->first,&pollout);
479  }
480 
481  FD_SET(listen_socket,&pollin);
482 
483  active_fds = select( active_fds, &pollin, &pollout, &pollerr, NULL );
484 
485  if( active_fds > 0 ) {
486  if( FD_ISSET(listen_socket,&pollin) ) {
487  SOCKET ns = accept( listen_socket, NULL, NULL );
488  if( ns != INVALID_SOCKET ) {
489  requests.insert( std::make_pair( ns, new RequestHandler( ns ) ) );
490  }
491  }
492 
493  for( std::map<SOCKET,RequestHandler *>::iterator i = requests.begin();
494  i != requests.end();
495  i++ ) {
496  if( FD_ISSET(i->first,&pollin) ) {
497  char inbuf[1024];
498  int rv = recv(i->first,inbuf,1024,0);
499  if( rv < 0 ) {
500  delete i->second;
501  requests.erase( i );
502  i = requests.begin();
503  break;
504  } else i->second->RecvData( string( inbuf, rv ) );
505  }
506  if( FD_ISSET(i->first,&pollout) ) {
507  i->second->OkToSend();
508  }
509  if( FD_ISSET(i->first,&pollerr) ) {
510  delete i->second;
511  requests.erase( i );
512  i = requests.begin();
513  break;
514  }
515  }
516  }
517  }
518 
519  WSACleanup();
520 }
Definition: winsock.h:66
static int argc
Definition: ServiceArgs.c:12
INT WSAAPI WSACleanup(VOID)
Definition: startup.c:60
pair< _T1, _T2 > _STLP_CALL make_pair(_T1 __x, _T2 __y)
Definition: _pair.h:124
#define FD_ZERO(set)
Definition: winsock.h:96
#define argv
Definition: mplay32.c:18
#define FD_SET(fd, set)
Definition: winsock.h:89
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define FD_ISSET(fd, set)
Definition: winsock.h:100
INT WSAAPI select(IN INT s, IN OUT LPFD_SET readfds, IN OUT LPFD_SET writefds, IN OUT LPFD_SET exceptfds, IN CONST struct timeval *timeout)
Definition: select.c:41
pair< iterator, bool > insert(const value_type &__x)
Definition: _map.h:188
INT WINAPI WSAStartup(IN WORD wVersionRequested, OUT LPWSADATA lpWSAData)
Definition: startup.c:113
smooth NULL
Definition: ftsmooth.c:416
void erase(iterator __pos)
Definition: _map.h:203
#define INVALID_SOCKET
Definition: winsock.h:332
Definition: _map.h:44
uchar inbuf[M_BLOCK]
Definition: unzcrash.c:40
Definition: mxnamespace.c:44
SOCKET WSAAPI accept(IN SOCKET s, OUT LPSOCKADDR addr, OUT INT FAR *addrlen)
Definition: socklife.c:23
SOCKET make_listening_socket(int port)
Definition: netreg.cpp:410
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
UINT_PTR SOCKET
Definition: winsock.h:47
iterator begin()
Definition: _map.h:163
INT WSAAPI recv(IN SOCKET s, OUT CHAR FAR *buf, IN INT len, IN INT flags)
Definition: recv.c:23
iterator end()
Definition: _map.h:165

◆ make_listening_socket()

SOCKET make_listening_socket ( int  port)

Definition at line 410 of file netreg.cpp.

410  {
411  struct sockaddr_in sa;
412 
413  ZeroMemory( &sa, sizeof( sa ) );
414 
415  sa.sin_family = PF_INET;
416  sa.sin_port = ntohs( port );
417 
418  fprintf( stderr, "Creating the listener\n" );
419  SOCKET l = socket( PF_INET, SOCK_STREAM, 0 );
420  fprintf( stderr, "Socket %x\n", l );
421 
422  if( l == INVALID_SOCKET ) return l;
423  if( bind( l, (struct sockaddr *)&sa, sizeof( sa ) ) < 0 ) {
424  fprintf( stderr, "Bad response from bind: %d\n", WSAGetLastError() );
425  closesocket( l ); return INVALID_SOCKET;
426  }
427  if( listen( l, 5 ) < 0 ) {
428  fprintf( stderr, "Listening: %d\n", WSAGetLastError() );
429  closesocket( l );
430  return INVALID_SOCKET;
431  }
432 
433  return l;
434 }
SOCKET WSAAPI socket(IN INT af, IN INT type, IN INT protocol)
Definition: socklife.c:143
INT WSAAPI bind(IN SOCKET s, IN CONST struct sockaddr *name, IN INT namelen)
Definition: socklife.c:36
#define ZeroMemory
Definition: winbase.h:1635
#define ntohs(x)
Definition: module.h:208
#define closesocket
Definition: main.c:39
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
#define PF_INET
Definition: winsock.h:373
r l[0]
Definition: byte_order.h:167
INT WSAAPI WSAGetLastError(VOID)
Definition: dllmain.c:112
#define INVALID_SOCKET
Definition: winsock.h:332
INT WSAAPI listen(IN SOCKET s, IN INT backlog)
Definition: sockctrl.c:123
FILE * stderr
UINT_PTR SOCKET
Definition: winsock.h:47
#define SOCK_STREAM
Definition: tcpip.h:118
USHORT port
Definition: uri.c:227
static struct sockaddr_in sa
Definition: adnsresfilter.c:69

Referenced by main().

Variable Documentation

◆ root_entries

const char* root_entries[]
Initial value:
= {
"HKEY_LOCAL_MACHINE",
"HKEY_CURRENT_USER",
"HKEY_CLASSES_ROOT",
"HKEY_CURRENT_CONFIG",
"HKEY_USERS",
0
}

Definition at line 25 of file netreg.cpp.

Referenced by alloc_rootdir_entry(), RequestHandler::process_request(), and RequestHandler::process_root_request().

◆ root_handles

const HKEY root_handles[]
Initial value:
= {
}
#define HKEY_USERS
Definition: winreg.h:13
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define HKEY_CURRENT_CONFIG
Definition: winreg.h:15
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Definition at line 34 of file netreg.cpp.

Referenced by RequestHandler::process_request().