static NPError NPN_GetAuthenticationInfo(NPP npp, const char* protocol, const char* host, int32_t port, const char* scheme, 
                                         const char* realm, char** username, uint32_t* usernameLength, char** password, uint32_t* passwordLength)
{
    if (!protocol || !host || !scheme || !realm || !username || !usernameLength || !password || !passwordLength)
        return NPERR_GENERIC_ERROR;

    ProtectionSpace protectionSpace;
    if (!initializeProtectionSpace(protocol, host, port, scheme, realm, protectionSpace))
        return NPERR_GENERIC_ERROR;

    RefPtr<NetscapePlugin> plugin = NetscapePlugin::fromNPP(npp);
    String usernameString;
    String passwordString;
    if (!plugin->getAuthenticationInfo(protectionSpace, usernameString, passwordString))
        return NPERR_GENERIC_ERROR;

    NPError result = copyCString(usernameString.utf8(), username, usernameLength);
    if (result != NPERR_NO_ERROR)
        return result;

    result = copyCString(passwordString.utf8(), password, passwordLength);
    if (result != NPERR_NO_ERROR) {
        npnMemFree(*username);
        return result;
    }

    return NPERR_NO_ERROR;
}
static NPError NPN_GetValueForURL(NPP npp, NPNURLVariable variable, const char* url, char** value, uint32_t* len)
{
    if (!value || !len)
        return NPERR_GENERIC_ERROR;
    
    switch (variable) {
        case NPNURLVCookie: {
            RefPtr<NetscapePlugin> plugin = NetscapePlugin::fromNPP(npp);
            PluginDestructionProtector protector(plugin.get());
            
            String cookies = plugin->cookiesForURL(makeURLString(url));
            if (cookies.isNull())
                return NPERR_GENERIC_ERROR;

            return copyCString(cookies.utf8(), value, len);
        }

        case NPNURLVProxy: {
            RefPtr<NetscapePlugin> plugin = NetscapePlugin::fromNPP(npp);
            PluginDestructionProtector protector(plugin.get());
            
            String proxies = plugin->proxiesForURL(makeURLString(url));
            if (proxies.isNull())
                return NPERR_GENERIC_ERROR;

            return copyCString(proxies.utf8(), value, len);
        }
        default:
            notImplemented();
            return NPERR_GENERIC_ERROR;
    }
}
Esempio n. 3
0
//Read in a message from a UDP connection
VyMessage* readUDPMessage(VyConn* conn)
{
	//String to hold the incoming data
	VyString* message = NULL;
	//Buffer to hold the data being read as it comes in
	unsigned char* buffer = malloc(sizeof(char)*1024);
	//The amount of data read in
	int readSize;
	
	//Information about the data being read in
	int addr_len;
    struct sockaddr_in client_addr;
	
	//Keep reading data until there is no more to read
	while((readSize = recvfrom(conn->socket,buffer,1024,0,(struct sockaddr *)&client_addr, &addr_len)) >= 1)
		//Add the data to the message
		message = addCharToStringSafe(message,buffer,readSize);
	
	free(buffer);
	
	//Make sure we recieved a message
	if(message == NULL)
		return NULL;
	
	//Get the ip for the person who sent the message
	char* ip = inet_ntoa(client_addr.sin_addr);
	if(ip != NULL)
	    conn->ip = copyCString(ip);
	else
	    conn->ip = NULL;

	//Convert the VyString to a char array
	unsigned char* cStringMessage = stringToCString(message);

	//Convert the char array to a VyMessage
	VyMessage* returnMessage = parseNewMessage(cStringMessage);

	free(cStringMessage);
	destroyVyString(message);
	
	//Print out information for debug and display
	printf(" - UUID: <%s> ",returnMessage->senderID);
	printf(": Received UDP message: [%s]",returnMessage->command);
	printf(" <%i> ",returnMessage->messageSize);
	printf(" [%s]\n",returnMessage->data);

	return returnMessage;
}
Esempio n. 4
0
//Get the IP of the current machine
char* getIP()
{
    struct hostent *he;
    struct in_addr a;
    int MAXHOSTNAMELEN = 20;
    char *hostname = malloc(MAXHOSTNAMELEN );
    memset( hostname , 0 , MAXHOSTNAMELEN );
    gethostname( hostname,MAXHOSTNAMELEN );
    he = gethostbyname (hostname);
    if (he)
    {
	 while (*he->h_aliases)
	    *he->h_aliases++;
	 while (*he->h_addr_list)
	 {
	      bcopy(*he->h_addr_list++, (char *) &a, sizeof(a));
	      return copyCString(inet_ntoa(a));
	 }
    }
    return NULL;
}