int InitializeTooltalk(void) { char * procid; Tt_status status; int fd; procid = tt_default_procid(); status = tt_ptr_error(procid); if ((status == TT_ERR_NOMP) || (status == TT_ERR_PROCID)) { /* * We need to try to establish a connection */ procid = tt_open(); status = tt_ptr_error(procid); if (status != TT_OK) { ToolTalkError("Could not connect to ToolTalk:\n%s\n", status); return (False); } tt_free(procid); /* * Determine the Tooltalk fildes. */ fd = tt_fd(); status = tt_int_error(fd); if (status != TT_OK) { ToolTalkError("Could not connect to ToolTalk:\n%s\n", status); tt_close(); ttfdG = -1; return(False); } else { ttfdG = fd; } #ifdef DtActUseXtOverSelect /* * Add the ToolTalk file descriptor to the set monitored by Xt */ XtAddInput(fd, (XtPointer)XtInputReadMask, input_handler, 0); #endif /* DtActUseXtOverSelect */ } return (True); }
// // Parse Get_Locale reply and pass it to user callback. // Also used to parse Set_Locale request and pass it to _ttDtApplyLocale(). // Tt_message _ttDtGetLocaleCB( Tt_message msg, Tt_pattern , void *clientCB, void *clientData ) { _TttkItem2Free fuse = msg; int numArgs = tt_message_args_count( msg ); Tt_status status = tt_int_error( numArgs ); if (status != TT_OK) { return (Tt_message)tt_error_pointer( status ); } _TttkList2Free fuses( numArgs + 2 ); int n = numArgs / 2; char **categories = (char **)tt_malloc( (n + 1) * sizeof(char *) ); char **locales = (char **)tt_malloc( (n + 1) * sizeof(char *) ); categories[ n ] = 0; locales[ n ] = 0; // // We only need these guys until after we call clientCB // fuses += (caddr_t)categories; fuses += (caddr_t)locales; for (int i = 0; i < n; i++) { categories[i] = tt_message_arg_val( msg, 2 * i ); status = tt_ptr_error( categories[i] ); if (status != TT_OK) { return (Tt_message)tt_error_pointer( status ); } fuses += categories[i]; locales[i] = tt_message_arg_val( msg, 2 * i + 1 ); status = tt_ptr_error( locales[i] ); if (status != TT_OK) { return (Tt_message)tt_error_pointer( status ); } fuses += locales[i]; } fuse = (caddr_t)0; // aborts message destruction Ttdt_Get_Locale_msg_cb _cb = (Ttdt_Get_Locale_msg_cb)clientCB; return (*_cb)( msg, clientData, (const char **)categories, (const char **)locales ); }
// // Handle a POSIX-related Desktop request // Tt_message _ttdt_posix_cb( Tt_message msg, Tt_pattern pat, void *, void * ) { char *opString = tt_message_op( msg ); Tttk_op op = tttk_string_op( opString ); tt_free( opString ); int numArgs = tt_message_args_count( msg ); Tt_status status = tt_int_error( numArgs ); if (status != TT_OK) { return (Tt_message)tt_error_pointer( status ); } switch (op) { char *categoryName, *variable, *value; int category, i; struct utsname names; #if defined(OPT_SYSINFO) char buf[ SYS_NMLN ]; #endif case TTDT_SET_LOCALE: return _ttDtGetLocaleCB( msg, pat, (void *)_ttDtApplyLocale, 0 ); case TTDT_GET_LOCALE: for (i = 0; i < numArgs/2; i++) { categoryName = _tttk_message_arg_val( msg, 2 * i, 0 ); if (categoryName == 0) { continue; } category = _ttDtCategory( categoryName ); if (category > 0) { tt_message_arg_val_set( msg, 2 * i + 1, setlocale( category, 0 )); } tt_free( categoryName ); } tt_message_reply( msg ); tttk_message_destroy( msg ); return 0; case TTDT_SET_ENVIRONMENT: case TTDT_GET_ENVIRONMENT: for (i = 0; i < numArgs/2; i++) { variable = _tttk_message_arg_val( msg, 2 * i, 0 ); if (variable == 0) { continue; } if (op == TTDT_GET_ENVIRONMENT) { tt_message_arg_val_set( msg, 2 * i + 1, getenv( variable )); } else if (_tttk_message_arg_is_set( msg, 2*i+1 )) { value = _tttk_message_arg_val( msg, 2*i+1, 0 ); _tt_putenv( variable, value ); tt_free( value ); } else { _tt_putenv( variable, 0 ); } tt_free( variable ); } tt_message_reply( msg ); tttk_message_destroy( msg ); return 0; case TTDT_SET_SITUATION: value = _tttk_message_arg_val( msg, 0, 0 ); if (value == 0) { value = tt_message_file( msg ); if (tt_ptr_error( value ) != TT_OK) { value = 0; } } if (value == 0) { tttk_message_fail( msg, TT_DESKTOP_EPROTO, 0, 1 ); return 0; } if (chdir( value ) != 0) { tt_free( value ); tttk_message_fail( msg, _tt_errno_status( errno ), 0, 1 ); return 0; } tt_free( value ); tt_message_reply( msg ); tttk_message_destroy( msg ); return 0; case TTDT_GET_SITUATION: value = getcwd( 0, MAXPATHLEN ); if (value == 0) { tttk_message_fail( msg, _tt_errno_status( errno ), 0, 1 ); return 0; } status = tt_message_arg_val_set( msg, 0, value ); free( value ); if (status != TT_OK) { tttk_message_fail( msg, status, 0, 1 ); return 0; } tt_message_reply( msg ); tttk_message_destroy( msg ); return 0; case TTDT_SIGNAL: i = _tttk_message_arg_ival( msg, 0, 0 ); if (i <= 0) { tttk_message_fail( msg, TT_DESKTOP_EINVAL, 0, 1 ); return 0; } // Reply before actually signalling, in case we die tt_message_reply( msg ); tttk_message_destroy( msg ); kill( getpid(), i ); return 0; case TTDT_GET_SYSINFO: if (uname( &names ) < 0) { tttk_message_fail( msg, _tt_errno_status( errno ), 0, 1 ); return 0; } // The first 5 values are from uname and seem pretty standard tt_message_arg_val_set( msg, 0, names.sysname ); tt_message_arg_val_set( msg, 1, names.nodename ); tt_message_arg_val_set( msg, 2, names.release ); tt_message_arg_val_set( msg, 3, names.version ); tt_message_arg_val_set( msg, 4, names.machine ); // The last 3 are from sysinfo which seems to be SVR4 only. // For platforms without the sysinfo call, we just leave // the values unset for now, except for the serial // number which is available from utsname onHPUX. #if defined(OPT_SYSINFO) if (sysinfo( SI_ARCHITECTURE, buf, SYS_NMLN ) >= 0) { tt_message_arg_val_set( msg, 5, buf ); } if (sysinfo( SI_HW_PROVIDER, buf, SYS_NMLN ) >= 0) { tt_message_arg_val_set( msg, 6, buf ); } if (sysinfo( SI_HW_SERIAL, buf, SYS_NMLN ) >= 0) { tt_message_arg_val_set( msg, 7, buf ); } #elif defined(__hpux) || defined(hpux) tt_message_arg_val_set( msg, 7, names.idnumber); #endif tt_message_reply( msg ); tttk_message_destroy( msg ); return 0; } return msg; }