Example #1
0
static int httpCreateFinishingGetConnection(const char* parturl, Connection*& conn, bool ssl) {
	HttpConnection* http;
	TLTZ_PASS(httpCreateConnection(parturl, http, HTTP_GET, ssl));
	http->mState = HttpConnection::FINISHING;
	conn = http;
	return 1;
}
Example #2
0
SYSCALL(MAHandle, maHttpCreate(const char* url, int method)) {
	LOGST("HttpCreate %i %s", gConnNextHandle, url);
	if(gConnections.size() >= CONN_MAX)
		return CONNERR_MAX;
	HttpConnection* conn;
	if(sstrcmp(url, http_string) == 0) {
		const char* parturl = url + sizeof(http_string) - 1;
		TLTZ_PASS(httpCreateConnection(parturl, conn, method, false));
	} else if(sstrcmp(url, https_string) == 0) {
		const char* parturl = url + sizeof(https_string) - 1;
		TLTZ_PASS(httpCreateConnection(parturl, conn, method, true));
	} else {
		return CONNERR_URL;
	}
	MAConn* mac = new MAStreamConn(gConnNextHandle, conn);
	gConnections.insert(ConnPair(gConnNextHandle, mac));
	return gConnNextHandle++;
}
Example #3
0
int SslConnection::connect() {
	TLTZ_PASS(TcpConnection::connect());
	TSSLZ(mSession = SSL_new(sSslContext));
	mState = eInit;
	TSSLLTZ(SSL_set_tlsext_host_name(mSession, mHostname.c_str()));
	TSSLZ(SSL_set_fd(mSession, mSock));
	TSSLLTZ(SSL_connect(mSession));
	mState = eHandshook;
	// TODO: Check that the CN matches the hostname.
	// TODO: Check the certificate chain against a set of root certificates.
#if 0
	X509* peerCert = SSL_get_peer_certificate(mSession);
	char commonName [512];
	X509_NAME* name = X509_get_subject_name(peerCert);
	X509_NAME_get_text_by_NID(name, NID_commonName, commonName, 512);
	if(stricmp(commonName, mHostname.c_str()) != 0) {
		LOG("Certificate was issued for '%s', but used for '%s'. Fail.\n");
		return CONNERR_SSL;
	}
#endif
	return 1;
}
Example #4
0
SYSCALL(MAHandle, maConnect(const char* url)) {
	LOGST("Connect %i %s", gConnNextHandle, url);
	if(gConnections.size() >= CONN_MAX)
		return CONNERR_MAX;
	Connection* conn;
	if(sstrcmp(url, http_string) == 0) {
		const char* parturl = url + sizeof(http_string) - 1;
		TLTZ_PASS(httpCreateFinishingGetConnection(parturl, conn, false));
	} else if(sstrcmp(url, https_string) == 0) {
		const char* parturl = url + sizeof(https_string) - 1;
		TLTZ_PASS(httpCreateFinishingGetConnection(parturl, conn, true));
	} else if(sstrcmp(url, socket_string) == 0) {
		//possible forms:
		// socket://	# server on random port
		// socket://:%i	# server on specified port
		// socket://%s:%i	# client
		//only the last one is allowed for now.

		//extract address and port
		const char* parturl = url + sizeof(socket_string) - 1;
		TLTZ_PASS(createSocketConnection(parturl, conn, false));
	} else if(sstrcmp(url, ssl_string) == 0) {
		const char* parturl = url + sizeof(ssl_string) - 1;
		TLTZ_PASS(createSocketConnection(parturl, conn, true));
	} else if(sstrcmp(url, btspp_string) == 0) {
		//allowed forms:
		// btspp://localhost:%32x
		// btspp://localhost:%32x;name=%s
		// btspp://%12x:%i
		//the first two are for servers, without and with service name.
		//the last is for clients.

		//extract address and port
		const char* parturl = url + sizeof(btspp_string) - 1;
		const char* first_colon = strchr(parturl, ':');
		if(!first_colon) {
			return CONNERR_URL;
		}

#ifndef _WIN32_WCE	//not yet supported
		if(strstr(parturl, "localhost") == parturl) {
			//server
			static const char name_string[] = "name=";
			const char* uuidStr = first_colon + 1;
			const char* semicolon = strchr(uuidStr, ';');
			const char* name;
			int uuidLen;
			if(semicolon == NULL) {
				uuidLen = strlen(uuidStr);
				name = NULL;
			} else {
				uuidLen = semicolon - uuidStr;

				const char* paramPtr = semicolon + 1;
				if(strstr(paramPtr, name_string) == paramPtr) {
					//we have a name
					name = paramPtr + sizeof(name_string) - 1;
				} else {
					name = NULL;
				}
			}
			if(uuidLen != 32)
				return CONNERR_URL;
			MAUUID uuid;
			//todo, optional: check that every uuid char isxdigit().
			if(4 != sscanf(uuidStr, "%8x%8x%8x%8x",
				&uuid.i[0], &uuid.i[1], &uuid.i[2], &uuid.i[3]))
			{
				return CONNERR_URL;
			}

			//we have the data. let's create the server
			BtSppServer* serv = new BtSppServer;
			int res = serv->open(uuid, name);
			if(res < 0) {
				delete serv;
				return res;
			}
			gConnMutex.lock();
			{
				MAServerConn* mac = new MAServerConn(gConnNextHandle, serv);
				gConnections.insert(ConnPair(gConnNextHandle, mac));
				mac->state = 0;
				res = gConnNextHandle++;
			}
			gConnMutex.unlock();
			return res;
		} else
#endif	//_WIN32_WCE
		{
			//client

			int purlLen = first_colon - parturl;
			if(purlLen != 12) {
				return CONNERR_URL;
			}
			int ai[6];	//address ints
			if(6 != sscanf(parturl, "%2x%2x%2x%2x%2x%2x",
				&ai[0], &ai[1], &ai[2], &ai[3], &ai[4], &ai[5]))
			{
				return CONNERR_URL;
			}
			MABtAddr address;
			for(int i=0; i<BTADDR_LEN; i++) {
				address.a[i] = (byte)ai[i];
			}

			int port = atoi(first_colon + 1);
			if(port <= 0 || port > 30) {
				return CONNERR_URL;
			}

			conn = createBtSppConnection(&address, port);
		}
	} else {
		return CONNERR_URL;
	}
	//success. let's store our new connection.
	int result;
	gConnMutex.lock();
	{
		MAStreamConn* mac = new MAStreamConn(gConnNextHandle, conn);
		gConnections.insert(ConnPair(gConnNextHandle, mac));
		mac->state = CONNOP_CONNECT;
		gThreadPool.execute(new Connect(*mac));
		result = gConnNextHandle++;
	}
	gConnMutex.unlock();
	return result;
}
Example #5
0
int RtspConnection::readResponseCode(const char* line, int len) {
	int responseCode;
	TLTZ_PASS(responseCode = readProtocolResponseCode("RTSP/", line, len));
	return responseCode;
}