ReactOS 0.4.16-dev-297-gc569aee
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}
static int argc
Definition: ServiceArgs.c:12
static int inbuf
Definition: adnsresfilter.c:73
Definition: _map.h:48
pair< iterator, bool > insert(const value_type &__x)
Definition: _map.h:188
iterator end()
Definition: _map.h:165
iterator begin()
Definition: _map.h:163
void erase(iterator __pos)
Definition: _map.h:203
#define NULL
Definition: types.h:112
INT WSAAPI recv(IN SOCKET s, OUT CHAR FAR *buf, IN INT len, IN INT flags)
Definition: recv.c:23
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
INT WINAPI WSAStartup(IN WORD wVersionRequested, OUT LPWSADATA lpWSAData)
Definition: startup.c:113
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
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
#define argv
Definition: mplay32.c:18
SOCKET make_listening_socket(int port)
Definition: netreg.cpp:410
SOCKET WSAAPI accept(IN SOCKET s, OUT LPSOCKADDR addr, OUT INT FAR *addrlen)
Definition: socklife.c:23
Definition: winsock.h:66
Definition: mxnamespace.c:45
#define FD_ISSET(fd, set)
Definition: winsock.h:100
#define FD_ZERO(set)
Definition: winsock.h:96
int PASCAL FAR WSACleanup(void)
Definition: startup.c:60
#define INVALID_SOCKET
Definition: winsock.h:332
UINT_PTR SOCKET
Definition: winsock.h:47
#define FD_SET(fd, set)
Definition: winsock.h:89

◆ 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" );
420 fprintf( stderr, "Socket %Ix\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}
static struct sockaddr_in sa
Definition: adnsresfilter.c:69
r l[0]
Definition: byte_order.h:168
USHORT port
Definition: uri.c:228
#define SOCK_STREAM
Definition: tcpip.h:118
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
#define ntohs(x)
Definition: module.h:210
#define closesocket
Definition: ncftp.h:477
INT WSAAPI listen(IN SOCKET s, IN INT backlog)
Definition: sockctrl.c:123
INT WSAAPI bind(IN SOCKET s, IN CONST struct sockaddr *name, IN INT namelen)
Definition: socklife.c:36
SOCKET WSAAPI socket(IN INT af, IN INT type, IN INT protocol)
Definition: socklife.c:143
#define ZeroMemory
Definition: winbase.h:1737
int PASCAL FAR WSAGetLastError(void)
Definition: dllmain.c:112
#define PF_INET
Definition: winsock.h:373

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_LOCAL_MACHINE
Definition: winreg.h:12
#define HKEY_CURRENT_CONFIG
Definition: winreg.h:15
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10
#define HKEY_USERS
Definition: winreg.h:13

Definition at line 34 of file netreg.cpp.

Referenced by RequestHandler::process_request().