void crWordsToString( char *string, int nstring, void *data, int ndata ) { int i, offset, ellipsis; unsigned int *udata; /* turn byte count into word count */ ndata /= 4; /* we need an ellipsis if all the words won't fit in the string */ ellipsis = ( ndata * 9 > nstring ); if ( ellipsis ) { ndata = nstring / 9; /* if the ellipsis won't fit then print one less word */ if ( ndata * 9 + 3 > nstring ) ndata--; } offset = 0; udata = (unsigned int *) data; for ( i = 0; i < ndata; i++ ) { offset += sprintf( string + offset, "%08x ", udata[i] ); } if ( ellipsis ) crStrcpy( string + offset, "..." ); else if ( offset > 0 ) string[offset-1] = 0; }
static void GetWindowTitle( const WindowInfo *window, char *title ) { char *t = GetWindowTitleHelper(window->dpy, window->drawable, GL_TRUE); if (t) { crStrcpy(title, t); XFree(t); } else { title[0] = 0; } }
static void start_hndl(void *data, const char *el, const char **attr) { static int topMenu = 0; static int button = 0; char* name; int value, i; apiMenu* newMenu; if ( strcmp( el, "button" ) == 0 ) { button = crStrToInt( attr[1] ); } else if ( strcmp( el, "menu") == 0 ) { if ( !topMenu ) { crut_server.stack = crut_server.endStack = crAlloc( sizeof(apiMenu) ); crut_server.stack->subMenus = 0; crut_server.stack->sLast = crut_server.stack->sNext = NULL; crut_server.stack->att_button = button; crut_server.stack->menuID = crStrToInt( attr[1] ); topMenu = 1; } else { newMenu = crAlloc( sizeof(apiMenu) ); newMenu->name = crAlloc( strlen( attr[1] ) ); crStrcpy( newMenu->name, attr[1] ); newMenu->menuID = crStrToInt( attr[3] ); pushMenu( newMenu ); } } else if ( strcmp( el, "item" ) == 0 ) { for ( i=0; i<=4; i+=2 ) { if ( strcmp( attr[i], "value" ) == 0 ) value = crStrToInt( attr[i+1] ); if ( strcmp( attr[i], "name" ) == 0 ) name = (char*) attr[i+1]; } addItem( name, value); } }
static void set_display_string( RenderSPU *render_spu, const char *response ) { if (!crStrcmp(response, "DEFAULT")) { const char *display = crGetenv("DISPLAY"); if (display) crStrncpy(render_spu->display_string, display, sizeof(render_spu->display_string)); else crStrcpy(render_spu->display_string, ""); /* empty string */ } else { crStrncpy(render_spu->display_string, response, sizeof(render_spu->display_string)); } }
void crBytesToString( char *string, int nstring, void *data, int ndata ) { int i, offset; unsigned char *udata; offset = 0; udata = (unsigned char *) data; for ( i = 0; i < ndata && ( offset + 4 <= nstring ); i++ ) { offset += sprintf( string + offset, "%02x ", udata[i] ); } if ( i == ndata && offset > 0 ) string[offset-1] = '\0'; else crStrcpy( string + offset - 3, "..." ); }
static void addItem( char* name, int value ) { if ( !crut_server.endStack->beginItems ) { crut_server.endStack->beginItems = crut_server.endStack->lastItem = crAlloc( sizeof( apiMenuItem ) ); } else { crut_server.endStack->lastItem->next = crAlloc( sizeof( apiMenuItem ) ); crut_server.endStack->lastItem = crut_server.endStack->lastItem->next; } crut_server.endStack->lastItem->name = crAlloc( sizeof( strlen(name) ) ); crStrcpy( crut_server.endStack->lastItem->name, name ); crut_server.endStack->lastItem->value = value; }
/** * Establish a connection with a server. * \param server the server to connect to, in the form * "protocol://servername:port" where the port specifier * is optional and if the protocol is missing it is assumed * to be "tcpip". * \param default_port the port to connect to, if port not specified in the * server URL string. * \param mtu desired maximum transmission unit size (in bytes) * \param broker either 1 or 0 to indicate if connection is brokered through * the mothership */ CRConnection * crNetConnectToServer( const char *server, unsigned short default_port, int mtu, int broker #if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST) , struct VBOXUHGSMI *pHgsmi #endif ) { char hostname[4096], protocol[4096]; unsigned short port; CRConnection *conn; crDebug( "In crNetConnectToServer( \"%s\", port=%d, mtu=%d, broker=%d )", server, default_port, mtu, broker ); CRASSERT( cr_net.initialized ); if (mtu < CR_MINIMUM_MTU) { crError( "You tried to connect to server \"%s\" with an mtu of %d, " "but the minimum MTU is %d", server, mtu, CR_MINIMUM_MTU ); } /* Tear the URL apart into relevant portions. */ if ( !crParseURL( server, protocol, hostname, &port, default_port ) ) { crError( "Malformed URL: \"%s\"", server ); } /* If the host name is "localhost" replace it with the _real_ name * of the localhost. If we don't do this, there seems to be * confusion in the mothership as to whether or not "localhost" and * "foo.bar.com" are the same machine. */ if (crStrcmp(hostname, "localhost") == 0) { int rv = crGetHostname(hostname, 4096); CRASSERT(rv == 0); (void) rv; } /* XXX why is this here??? I think it could be moved into the * crTeacConnection() function with no problem. I.e. change the * connection's port, teac_rank and tcscomm_rank there. (BrianP) */ if ( !crStrcmp( protocol, "quadrics" ) || !crStrcmp( protocol, "quadrics-tcscomm" ) ) { /* For Quadrics protocols, treat "port" as "rank" */ if ( port > CR_QUADRICS_HIGHEST_RANK ) { crWarning( "Invalid crserver rank, %d, defaulting to %d\n", port, CR_QUADRICS_LOWEST_RANK ); port = CR_QUADRICS_LOWEST_RANK; } } crDebug( "Connecting to %s on port %d, with protocol %s", hostname, port, protocol ); #ifdef SDP_SUPPORT /* This makes me ill, but we need to "fix" the hostname for sdp. MCH */ if (!crStrcmp(protocol, "sdp")) { char* temp; temp = strtok(hostname, "."); crStrcat(temp, crGetSDPHostnameSuffix()); crStrcpy(hostname, temp); crDebug("SDP rename hostname: %s", hostname); } #endif conn = (CRConnection *) crCalloc( sizeof(*conn) ); if (!conn) return NULL; /* init the non-zero fields */ conn->type = CR_NO_CONNECTION; /* we don't know yet */ conn->recv_credits = CR_INITIAL_RECV_CREDITS; conn->hostname = crStrdup( hostname ); conn->port = port; conn->mtu = mtu; conn->buffer_size = mtu; conn->broker = broker; conn->endianness = crDetermineEndianness(); /* XXX why are these here??? Move them into the crTeacConnection() * and crTcscommConnection() functions. */ conn->teac_id = -1; conn->teac_rank = port; conn->tcscomm_id = -1; conn->tcscomm_rank = port; crInitMessageList(&conn->messageList); /* now, just dispatch to the appropriate protocol's initialization functions. */ InitConnection(conn, protocol, mtu #if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST) , pHgsmi #endif ); if (!crNetConnect( conn )) { crDebug("crNetConnectToServer() failed, freeing the connection"); #ifdef CHROMIUM_THREADSAFE crFreeMutex( &conn->messageList.lock ); #endif conn->Disconnect(conn); crFree( conn ); return NULL; } crDebug( "Done connecting to %s (swapping=%d)", server, conn->swap ); return conn; }
static void crSDPAccept( CRConnection *conn, const char *hostname, unsigned short port ) { int err; socklen_t addr_length; struct sockaddr_in servaddr; struct sockaddr addr; struct hostent *host; struct in_addr sin_addr; if (port != last_port) { /* with the new OOB stuff, we can have multiple ports being * accepted on, so we need to redo the server socket every time. */ cr_sdp.server_sock = socket( AF_INET_SDP, SOCK_STREAM, 0 ); if ( cr_sdp.server_sock == -1 ) { err = crSDPErrno( ); crError( "Couldn't create socket: %s", crSDPErrorString( err ) ); } spankSocket( cr_sdp.server_sock ); servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr = INADDR_ANY; servaddr.sin_port = htons( port ); if ( bind( cr_sdp.server_sock, (struct sockaddr *) &servaddr, sizeof(servaddr) ) ) { err = crSDPErrno( ); crError( "Couldn't bind to socket (port=%d): %s", port, crSDPErrorString( err ) ); } last_port = port; if ( listen( cr_sdp.server_sock, 100 /* max pending connections */ ) ) { err = crSDPErrno( ); crError( "Couldn't listen on socket: %s", crSDPErrorString( err ) ); } } if (conn->broker) { CRConnection *mother; char response[8096]; char my_hostname[256]; char *temp; mother = __copy_of_crMothershipConnect( ); if (!hostname) { if ( crGetHostname( my_hostname, sizeof( my_hostname ) ) ) { crError( "Couldn't determine my own hostname in crSDPAccept!" ); } } else crStrcpy(my_hostname, hostname); /* Hack hostname, YUCK!!! */ temp = strtok(my_hostname, "."); crStrcat(temp, crGetSDPHostnameSuffix()); (void) temp; if (!__copy_of_crMothershipSendString( mother, response, "acceptrequest sdp %s %d %d", temp, conn->port, conn->endianness ) ) { crError( "Mothership didn't like my accept request" ); } __copy_of_crMothershipDisconnect( mother ); sscanf( response, "%u", &(conn->id) ); } addr_length = sizeof( addr ); conn->sdp_socket = accept( cr_sdp.server_sock, (struct sockaddr *) &addr, &addr_length ); if (conn->sdp_socket == -1) { err = crSDPErrno( ); crError( "Couldn't accept client: %s", crSDPErrorString( err ) ); } sin_addr = ((struct sockaddr_in *) &addr)->sin_addr; host = gethostbyaddr( (char *) &sin_addr, sizeof( sin_addr), AF_INET_SDP ); if (host == NULL ) { char *temp = inet_ntoa( sin_addr ); conn->hostname = crStrdup( temp ); } else { char *temp; conn->hostname = crStrdup( host->h_name ); temp = conn->hostname; while (*temp && *temp != '.' ) temp++; *temp = '\0'; } #ifdef RECV_BAIL_OUT err = sizeof(unsigned int); if ( getsockopt( conn->sdp_socket, SOL_SOCKET, SO_RCVBUF, (char *) &conn->krecv_buf_size, &err ) ) { conn->krecv_buf_size = 0; } #endif crDebug( "Accepted connection from \"%s\".", conn->hostname ); }
void crStrcat( char *dest, const char *src ) { crStrcpy( dest + crStrlen(dest), src ); }