コード例 #1
0
int			GSocketUdpServer::Send(const GString &s)
{
#if defined (GWIN)
	int		rc, err;
	WSABUF	DataBuf;
	DWORD	SendBytes = 0;
	DataBuf.len = s.Size();
	DataBuf.buf = s.ToChar();
	rc = WSASendTo(this->_socket, &DataBuf, 1, &SendBytes, NULL, reinterpret_cast <sockaddr*> (&this->_sockaddr), DataBuf.len, NULL, NULL);
	delete[] DataBuf.buf;
	if ((rc == SOCKET_ERROR) && (WSA_IO_PENDING != (err = WSAGetLastError())))
	{
		this->_lastError = GSocketUdpServer::ERROR_SEND;
		throw GException("GSocketUdpServer", "Error WSASend() !");
	}
	return (SendBytes);
#else
	int	l = 0;
	char	*tmp = s.ToChar();
	l = sendto(this->_socket, tmp, s.Size(), 0, 0, 0);
	delete[] tmp;
	if (l < 0)
	{
		this->_lastError = GSocketUdpServer::ERROR_SEND;
		throw GException("GSocketUdpServer", "Error send() !");
	}
	return (l);
#endif
}
コード例 #2
0
GString			GSqlDatabase::EscapeString(const GString &Str)
{
	char *str = Str.ToChar();
	char *to = new char[Str.Size() * 2 + 1];
	unsigned long nb = mysql_real_escape_string(&(this->_mysql), to, str, Str.Size());
	delete[] str;
	GString res = GString::GetBuffer(to, nb);
	delete[] to;
	return (res);
}
コード例 #3
0
ファイル: GRegExp.cpp プロジェクト: hungconcon/geofreylibrary
/* if str2 == str1 */
bool GRegExp::isContener(GString str1, GString str2)
{
	if (str2.Size() > str1.Size())
		return false;
	unsigned int i = 0;
	while (i < str2.Size() && str1[i] == str2[i])
		i++;
	if (i == str2.Size())
		return true;
	return false;
}
コード例 #4
0
ファイル: GRegExp.cpp プロジェクト: hungconcon/geofreylibrary
GString GRegExp::skipDouble(GString str)
{
	GString res("");
	for (unsigned int i = 0; i < str.Size() - 1; i++)
	{
		if (str[i] == str[i + 1])
		{
			unsigned int j = 0;
			while (j < _skip.Size() && _skip[j] != str[i])
				j++;
			if (j == _skip.Size())
				res += str[i];
		}
		else
			res += str[i];
	}
	res += str[str.Size() - 1];
	return res;
}
コード例 #5
0
ファイル: GRegExp.cpp プロジェクト: hungconcon/geofreylibrary
int GRegExp::burnRight(GString str)
{
	for (unsigned int i = str.Size(); i > 0; i--)
	{
		bool test = false;
		for (unsigned int j = 0; j < _burn.Size(); j++)
		{
			if (str[i] == _burn[j])
				test = true;
		}
		if (!test)
			return i;
	}
	return -1;
}
コード例 #6
0
ファイル: GHttp.cpp プロジェクト: hungconcon/geofreylibrary
GString		GHttp::Get(const GString &g)
{
	GString	page(g);
	if (!page.StartWith("http://"))
	{
		page = this->_host + page;
		if (!page.StartWith("http://"))
			page = "http://" + page;
	}
	GString	str = "GET " + page + " HTTP/1.1\r\n";
	str += "Host: " + this->_host + "\r\n";
	if (!this->_proxyUser.IsEmpty())
	{
		str += "Proxy-Authorization: Basic " + GCryptography::GBase64::Encode(this->_proxyUser + ":" + this->_proxyPass) + "\r\n";
		str += "Proxy-Connection : keep-alive\r\n";
	}
	else
	{
		str += "Keep-Alive: 20000\r\n";
		str += "Connection : keep-alive\r\n";
	}
	if (!this->_user.IsEmpty())
		str += "Authorization: Basic " + GCryptography::GBase64::Encode(this->_user + ":" + this->_pass) + "\r\n";
	str += "\r\n";
	this->_socket.Send(str);
	GString rectot;
	while (true)
	{
		GString rec;
		rec = this->_socket.Receive();
		if (rec.Size() < 1024)
		{
			rectot += rec;
			GString	sub = rec.Substr(0, rec.Find("\r\n"));
			GStringList	tab = sub.Split(" ");
			if (tab.Size() > 2)
			{
				//GESTION DES ERREUR
			}
			int	pos = rec.Find("\r\n\r\n");
			if (pos != GString::NotFound)
				;//this->_response = this->_response.Substr(pos + 4);
		}
	}
	return (rectot);
}
コード例 #7
0
ファイル: GRegExp.cpp プロジェクト: hungconcon/geofreylibrary
int GRegExp::isPos(GString str1, GString str2)
{
	if (str1.Size() < str2.Size())
		return -1;
	for (unsigned int i = 0; i <= str1.Size() - str2.Size(); i++)
	{
		unsigned int j = 0;
		while (str1[i + j] == str2[j] && j < str2.Size())
			j++;
		if (j == str2.Size())
			return i;
	}
	return -1;
}
コード例 #8
0
ファイル: GString.cpp プロジェクト: gedamial/GedamialLibrary
	GArray<GString> GString::Split(GString& str, char const token)
	{
		str.Trim(token);
		GArray<GString> arr;

		size_t lastPos = 0;
		size_t tokenPos = str.Find(token);

		while (tokenPos != -1)
		{
			arr.Add(str.SubString(lastPos, tokenPos - 1));

			lastPos = tokenPos + 1;

			tokenPos = str.Find(token, tokenPos + 1);
		}

		arr.Add(str.SubString(lastPos, str.Size() - 1));

		return arr;
	}	
コード例 #9
0
ファイル: GRegExp.cpp プロジェクト: hungconcon/geofreylibrary
int GRegExp::longRes(GVector<GString> *res, unsigned int pos, unsigned int reg, GString &str)
{
	if ( pos > str.Size() || res->Size() < reg)
		return -1;
	if (!res || res->Size() == reg)
	{
		if (this->_opt.Size() == 0 || (this->_opt.Size() > reg && (_opt[reg].getObliWord().Size() == 0)))
		{
			if (_opt.Size() != 0)
			{
				GString tmp = _opt[reg].getStopChar();
				for (unsigned int i = pos; i < str.Size(); i++)
					for (unsigned int j = 0; j < tmp.Size(); j++)
						if (tmp[j] == str[i])
							return -1;
				if (_opt[reg].getEmp() == NOEMPTY && (str.Size() - pos) == 0)
					return -1;
				return str.Size() - pos;
			}
			return str.Size() - pos;
		}
		return str.Size();
	}
	if (this->_opt.Size() == 0 || (this->_opt.Size() > reg && (_opt[reg].getObliWord().Size() == 0)))
	{
		unsigned int i = pos;
		while (i < str.Size() - (*res)[reg].Size() + 1)
		{
			if (this->_opt.Size() > reg)
			{
				GString tmp = _opt[reg].getStopChar();
				for (unsigned int j = 0; j < tmp.Size(); j++)
				{
					if (tmp[j] == str[i])
					{
						if ((int)i - (int)pos < 0)
							return -1;
						else if (this->_opt.Size() == 0 || (this->_opt.Size() > reg && _opt[reg].getEmp() == EMPTY))
							return i - pos;
						else if (i - pos > 0)
							return i - pos;
						return -1;
					}
				}
			}
			if (_opt.Size() > reg + 1 && _opt[reg + 1].getStopChar() == "" && _opt[reg + 1].getObliWord().Size() == 0)
			{
				if (_opt[reg].getStopChar().Size() == 0 && _opt[reg].getObliWord().Size() == 0)
				{
					unsigned int j = 0;
					while ((*res)[reg].Size() > j && (*res)[reg][j] == str[i + j])
						j++;
					if (j == (*res)[reg].Size())
						return i - pos;
				}
				i++;
			}	
			else
			{
				unsigned int j = 0;
				if ((*res)[reg].Size() == 0)
				{
					if (this->_opt.Size() > reg && _opt[reg].getEmp() == NOEMPTY && (i - pos) > 0)
					{
						if (longRes(res, i, reg + 1, str) != -1)
							return i - pos;
					}
					else
					{
						if (this->_opt.Size() <= reg || (this->_opt.Size() > reg && _opt[reg].getEmp() == EMPTY))
							return i - pos;
					}
				}
				else
				{
					while ((*res)[reg].Size() > j && (*res)[reg][j] == str[i + j])
						j++;
				/* test fin avec (.*)t sans opt*/
					if (j == (*res)[reg].Size())
					{
						if (this->_opt.Size() > reg)
						{
							if ((_opt[reg].getEmp() == NOEMPTY && (i - pos) > 1) || _opt[reg].getEmp() == EMPTY)
								if ((reg + 1 < res->Size()) || (reg + 1 == res->Size() && str.Size() == i + (*res)[reg].Size()))
									return i - pos;
						}
						else
						{
							if ((reg + 1 < res->Size()) || (reg + 1 == res->Size() && str.Size() == i + (*res)[reg].Size()))
								return i - pos;
						}
					}
				}
				i++;
			}
		}
		return -1;
	}
	if (this->_opt.Size() > reg && _opt[reg].getObliWord().Size() > 0)
	{
		GVector<GString> tmp = _opt[reg].getObliWord();
		for (unsigned int i = 0; i < tmp.Size(); i++)
		{	
			if (tmp[i].Size() <= str.Size() + pos)
			{
				unsigned int j = 0;
				while (j < tmp[i].Size() && tmp[i][j] == str[pos + j])
					j++;
				if (j == tmp[i].Size())
				{
					if (reg == res->Size() && str.Size() == pos + j)
						return j;
					if (reg < res->Size())
					{
						unsigned int k = 0;
						while (k < str.Size() && k < (*res)[reg].Size() && str[k + pos + j] == (*res)[reg][k])
							k++;

						/*test fin de chaine */
						if ((*res)[reg].Size() == k)
							return tmp[i].Size();
					}
				}
			}
		}
		return -1;
	}
	return -1;
}