- Timestamp:
- 2005-11-07T16:32:40Z (18 years ago)
- Branches:
- master
- Children:
- abe53d3
- Parents:
- d1d6776
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
win32.c
rd1d6776 r99318ad 5 5 \********************************************************************/ 6 6 7 /* Main file ( Unix specific part)*/7 /* Main file (Windows specific part) */ 8 8 9 9 /* … … 24 24 */ 25 25 26 #define BITLBEE_CORE 26 27 #include "bitlbee.h" 27 28 #include "commands.h" … … 30 31 #include "help.h" 31 32 #include <signal.h> 32 #include <unistd.h> 33 #include <sys/time.h> 34 #include <winreg.h> 35 #include <winbase.h> 33 #include <windows.h> 36 34 37 35 global_t global; /* Against global namespace pollution */ 38 36 39 int main( int argc, char *argv[] ) 37 static void WINAPI service_ctrl (DWORD dwControl) 38 { 39 switch (dwControl) 40 { 41 case SERVICE_CONTROL_STOP: 42 /* FIXME */ 43 break; 44 45 case SERVICE_CONTROL_INTERROGATE: 46 break; 47 48 default: 49 break; 50 51 } 52 } 53 54 void service_main (DWORD argc, LPTSTR *argv) 40 55 { 41 56 int i = -1; 57 SERVICE_STATUS_HANDLE handle; 58 SERVICE_STATUS status; 59 60 handle = RegisterServiceCtrlHandler("bitlbee", service_ctrl); 61 62 if (!handle) 63 return; 64 65 status.dwServiceType = SERVICE_WIN32_OWN_PROCESS; 66 status.dwServiceSpecificExitCode = 0; 67 42 68 memset( &global, 0, sizeof( global_t ) ); 43 69 44 70 global.loop = g_main_new( FALSE ); 45 46 log_init( );47 nogaim_init( );48 71 49 72 global.conf = conf_load( argc, argv ); 50 73 if( global.conf == NULL ) 51 return ( 1 );74 return; 52 75 53 76 if( global.conf->runmode == RUNMODE_INETD ) … … 68 91 69 92 if( i != 0 ) 70 return ( i );93 return; 71 94 72 95 if( access( global.conf->configdir, F_OK ) != 0 ) 73 96 log_message( LOGLVL_WARNING, "The configuration directory %s does not exist. Configuration won't be saved.", global.conf->configdir ); 74 else if( access( global.conf->configdir, R_OK ) != 0 || access( global.conf->configdir, W_OK) != 0 )97 else if( access( global.conf->configdir, 06 ) != 0 ) 75 98 log_message( LOGLVL_WARNING, "Permission problem: Can't read/write from/to %s.", global.conf->configdir ); 76 99 if( help_init( &(global.help) ) == NULL ) 77 100 log_message( LOGLVL_WARNING, "Error opening helpfile %s.", global.helpfile ); 101 102 SetServiceStatus(handle, &status); 78 103 79 104 g_main_run( global.loop ); 80 81 return( 0 ); 105 } 106 107 int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) 108 { 109 SERVICE_TABLE_ENTRY dispatch_table[] = 110 { 111 { TEXT("bitlbee"), (LPSERVICE_MAIN_FUNCTION)service_main }, 112 { NULL, NULL } 113 }; 114 115 nogaim_init( ); 116 117 if (!StartServiceCtrlDispatcher(dispatch_table)) 118 log_message( LOGLVL_ERROR, "StartServiceCtrlDispatcher failed."); 119 120 return 0; 82 121 } 83 122 … … 119 158 HKEY key, key_main, key_proxy; 120 159 char *tmp; 121 RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Bitlbee", &key); 122 RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Bitlbee\\main", &key_main); 123 RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Bitlbee\\proxy", &key_proxy); 160 161 RegOpenKey(HKEY_CURRENT_USER, "SOFTWARE\\Bitlbee", &key); 162 RegOpenKey(key, "main", &key_main); 163 RegOpenKey(key, "proxy", &key_proxy); 124 164 125 165 memset( &global, 0, sizeof( global_t ) ); … … 190 230 return (addr->s_addr == INADDR_NONE) ? 0 : 1; 191 231 } 232 233 void log_error(char *msg) 234 { 235 log_message(LOGLVL_ERROR, "%s", msg); 236 } 237 238 void log_message(int level, char *message, ...) 239 { 240 HANDLE hEventSource; 241 LPTSTR lpszStrings[2]; 242 WORD elevel; 243 va_list ap; 244 245 va_start(ap, message); 246 247 hEventSource = RegisterEventSource(NULL, TEXT("bitlbee")); 248 249 lpszStrings[0] = TEXT("bitlbee"); 250 lpszStrings[1] = g_strdup_vprintf(message, ap); 251 va_end(ap); 252 253 switch (level) { 254 case LOGLVL_ERROR: elevel = EVENTLOG_ERROR_TYPE; break; 255 case LOGLVL_WARNING: elevel = EVENTLOG_WARNING_TYPE; break; 256 case LOGLVL_INFO: elevel = EVENTLOG_INFORMATION_TYPE; break; 257 #ifdef DEBUG 258 case LOGLVL_DEBUG: elevel = EVENTLOG_AUDIT_SUCCESS; break; 259 #endif 260 } 261 262 if (hEventSource != NULL) { 263 ReportEvent(hEventSource, 264 elevel, 265 0, 266 0, 267 NULL, 268 2, 269 0, 270 lpszStrings, 271 NULL); 272 273 DeregisterEventSource(hEventSource); 274 } 275 276 g_free(lpszStrings[1]); 277 }
Note: See TracChangeset
for help on using the changeset viewer.