summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-08-23 18:06:26 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-08-23 18:06:26 +0000
commitdeb85740798d3438563628736c0e83edb6966b6e (patch)
treea8ad119fa9d1624a174cded210aba05a1af36173
parent3f3d3d302899aacf8b49fcc871265c965d1fb0fc (diff)
Add some stuff to change how we process a token sepeperated stream
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@7800 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--include/hashcomp.h5
-rw-r--r--src/channels.cpp7
-rw-r--r--src/cmd_ison.cpp5
-rw-r--r--src/command_parse.cpp12
-rw-r--r--src/hashcomp.cpp28
-rw-r--r--src/modules/m_alias.cpp10
-rw-r--r--src/modules/m_cloaking.cpp2
-rw-r--r--src/modules/m_helpop.cpp4
-rw-r--r--src/modules/m_http_client.cpp6
-rw-r--r--src/modules/m_samode.cpp2
-rw-r--r--src/modules/m_spanningtree/treesocket1.cpp13
11 files changed, 49 insertions, 45 deletions
diff --git a/include/hashcomp.h b/include/hashcomp.h
index 2ac346294..033003f71 100644
--- a/include/hashcomp.h
+++ b/include/hashcomp.h
@@ -324,9 +324,10 @@ namespace irc
virtual ~sepstream();
/** Fetch the next token from the stream
- * @return The next token is returned, or an empty string if none remain
+ * @param token The next token from the stream is placed here
+ * @return True if tokens still remain, false if there are none left
*/
- virtual const std::string GetToken();
+ virtual bool GetToken(std::string &token);
/** Fetch the entire remaining stream, without tokenizing
* @return The remaining part of the stream
diff --git a/src/channels.cpp b/src/channels.cpp
index bd8a9719c..83f18abee 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -175,8 +175,11 @@ CUList* chanrec::GetVoicedUsers()
void chanrec::SetDefaultModes()
{
irc::spacesepstream list(ServerInstance->Config->DefaultModes);
- std::string modeseq = list.GetToken();
+ std::string modeseq;
std::string parameter;
+
+ list.GetToken(modeseq);
+
userrec* dummyuser = new userrec(ServerInstance);
dummyuser->SetFd(FD_MAGIC_NUMBER);
@@ -186,7 +189,7 @@ void chanrec::SetDefaultModes()
if (mode)
{
if (mode->GetNumParams(true))
- parameter = list.GetToken().c_str();
+ list.GetToken(parameter);
else
parameter.clear();
diff --git a/src/cmd_ison.cpp b/src/cmd_ison.cpp
index d050af982..e50634f78 100644
--- a/src/cmd_ison.cpp
+++ b/src/cmd_ison.cpp
@@ -54,8 +54,9 @@ CmdResult cmd_ison::Handle (const char** parameters, int pcnt, userrec *user)
/* Its a space seperated list of nicks (RFC1459 says to support this)
*/
irc::spacesepstream list(parameters[i]);
- std::string item("*");
- while (((item = list.GetToken()) != ""))
+ std::string item;
+
+ while (list.GetToken(item))
{
u = ServerInstance->FindNick(item);
if (ison_already.find(u) != ison_already.end())
diff --git a/src/command_parse.cpp b/src/command_parse.cpp
index b333084e7..8a6149a2c 100644
--- a/src/command_parse.cpp
+++ b/src/command_parse.cpp
@@ -134,14 +134,15 @@ int CommandParser::LoopCall(userrec* user, command_t* CommandObj, const char** p
*/
irc::commasepstream items1(parameters[splithere]);
irc::commasepstream items2(parameters[extra]);
- std::string item("*");
+ std::string extrastuff;
+ std::string item;
unsigned int max = 0;
/* Attempt to iterate these lists and call the command objech
* which called us, for every parameter pair until there are
* no more left to parse.
*/
- while (((item = items1.GetToken()) != "") && (max++ < ServerInstance->Config->MaxTargets))
+ while (items1.GetToken(item) && (max++ < ServerInstance->Config->MaxTargets))
{
if (dupes.find(item.c_str()) == dupes.end())
{
@@ -150,7 +151,8 @@ int CommandParser::LoopCall(userrec* user, command_t* CommandObj, const char** p
for (int t = 0; (t < pcnt) && (t < MAXPARAMETERS); t++)
new_parameters[t] = parameters[t];
- std::string extrastuff = items2.GetToken();
+ if (!items2.GetToken(extrastuff))
+ extrastuff = "";
new_parameters[splithere] = item.c_str();
new_parameters[extra] = extrastuff.c_str();
@@ -175,14 +177,14 @@ int CommandParser::LoopCall(userrec* user, command_t* CommandObj, const char** p
/* Only one commasepstream here */
irc::commasepstream items1(parameters[splithere]);
- std::string item("*");
+ std::string item;
unsigned int max = 0;
/* Parse the commasepstream until there are no tokens remaining.
* Each token we parse out, call the command handler that called us
* with it
*/
- while (((item = items1.GetToken()) != "") && (max++ < ServerInstance->Config->MaxTargets))
+ while (items1.GetToken(item) && (max++ < ServerInstance->Config->MaxTargets))
{
if (dupes.find(item.c_str()) == dupes.end())
{
diff --git a/src/hashcomp.cpp b/src/hashcomp.cpp
index b5740d95b..49befd634 100644
--- a/src/hashcomp.cpp
+++ b/src/hashcomp.cpp
@@ -245,32 +245,31 @@ irc::sepstream::sepstream(const std::string &source, char seperator) : tokens(so
n = tokens.begin();
}
-const std::string irc::sepstream::GetToken()
+bool irc::sepstream::GetToken(std::string &token)
{
std::string::iterator lsp = last_starting_position;
while (n != tokens.end())
{
- /** Skip multi seps, converting "<sep><sep>" into "<sep>"
- */
- while ((n+1 != tokens.end()) && (*n == sep) && (*(n+1) == sep))
- n++;
-
if ((*n == sep) || (n+1 == tokens.end()))
{
last_starting_position = n+1;
- std::string strip = std::string(lsp, n+1 == tokens.end() ? n+1 : n++);
+ token = std::string(lsp, n+1 == tokens.end() ? n+1 : n++);
- while ((strip.length()) && (strip.find_last_of(sep) == strip.length() - 1))
- strip.erase(strip.end() - 1);
+ while ((token.length()) && (token.find_last_of(sep) == token.length() - 1))
+ token.erase(token.end() - 1);
- return strip;
+ if (token.empty())
+ n++;
+
+ return n == tokens.end() ? false : true;
}
n++;
}
- return "";
+ token = "";
+ return false;
}
const std::string irc::sepstream::GetRemaining()
@@ -458,16 +457,15 @@ long irc::portparser::GetToken()
in_range = 0;
}
- std::string x = sep->GetToken();
+ std::string x;
+ sep->GetToken(x);
if (x.empty())
return 0;
while (Overlaps(atoi(x.c_str())))
{
- x = sep->GetToken();
-
- if (x.empty())
+ if (!sep->GetToken(x))
return 0;
}
diff --git a/src/modules/m_alias.cpp b/src/modules/m_alias.cpp
index a8f079bf1..2bf4440b0 100644
--- a/src/modules/m_alias.cpp
+++ b/src/modules/m_alias.cpp
@@ -104,12 +104,12 @@ class ModuleAlias : public Module
std::string word;
for (int j = 0; j < index; j++)
- word = ss.GetToken();
+ ss.GetToken(word);
if (everything_after)
{
- std::string more = "*";
- while ((more = ss.GetToken()) != "")
+ std::string more;
+ while (ss.GetToken(more))
{
word.append(" ");
word.append(more);
@@ -201,8 +201,8 @@ class ModuleAlias : public Module
else
{
irc::sepstream commands(Aliases[i].replace_with, '\n');
- std::string command = "*";
- while ((command = commands.GetToken()) != "")
+ std::string command;
+ while (commands.GetToken(command))
{
DoCommand(command, user, safe);
}
diff --git a/src/modules/m_cloaking.cpp b/src/modules/m_cloaking.cpp
index 20e821e85..ad7a7e337 100644
--- a/src/modules/m_cloaking.cpp
+++ b/src/modules/m_cloaking.cpp
@@ -192,7 +192,7 @@ class CloakUser : public ModeHandler
for (int j = 0; j < 4; j++)
{
- octet[j] = seps.GetToken();
+ seps.GetToken(octet[j]);
i[j] = atoi(octet[j].c_str());
}
diff --git a/src/modules/m_helpop.cpp b/src/modules/m_helpop.cpp
index 341f2b861..fd88651c0 100644
--- a/src/modules/m_helpop.cpp
+++ b/src/modules/m_helpop.cpp
@@ -92,10 +92,8 @@ class cmd_helpop : public command_t
irc::sepstream stream(value, '\n');
std::string token = "*";
- while ((token = stream.GetToken()) != "")
- {
+ while (stream.GetToken(token))
user->WriteServ("NOTICE %s :%s", user->nick, token.c_str());
- }
user->WriteServ("NOTICE %s :*** End of HELPOP", user->nick);
}
diff --git a/src/modules/m_http_client.cpp b/src/modules/m_http_client.cpp
index aa97242e0..a2f80687f 100644
--- a/src/modules/m_http_client.cpp
+++ b/src/modules/m_http_client.cpp
@@ -176,10 +176,10 @@ bool HTTPSocket::ParseURL(const std::string &iurl)
for (int p = 0;; p++)
{
- std::string part = tokenizer.GetToken();
- if (part.empty() && tokenizer.StreamEnd())
+ std::string part;
+ if (!tokenizer.GetToken(part))
break;
-
+
if ((p == 0) && (part[part.length() - 1] == ':'))
{
// Protocol ('http:')
diff --git a/src/modules/m_samode.cpp b/src/modules/m_samode.cpp
index f4f00f55a..7f3e9f428 100644
--- a/src/modules/m_samode.cpp
+++ b/src/modules/m_samode.cpp
@@ -47,7 +47,7 @@ class cmd_samode : public command_t
std::deque<std::string> n;
irc::spacesepstream spaced(ServerInstance->Modes->GetLastParse());
std::string one = "*";
- while ((one = spaced.GetToken()) != "")
+ while (spaced.GetToken(one))
n.push_back(one);
Event rmode((char *)&n, NULL, "send_mode");
diff --git a/src/modules/m_spanningtree/treesocket1.cpp b/src/modules/m_spanningtree/treesocket1.cpp
index c939f2349..2b4b6d301 100644
--- a/src/modules/m_spanningtree/treesocket1.cpp
+++ b/src/modules/m_spanningtree/treesocket1.cpp
@@ -341,9 +341,9 @@ void TreeSocket::SendCapabilities()
this->WriteLine("CAPAB START");
/* Send module names, split at 509 length */
- std::string item = "*";
+ std::string item;
std::string line = "CAPAB MODULES ";
- while ((item = modulelist.GetToken()) != "")
+ while (modulelist.GetToken(item))
{
if (line.length() + item.length() + 1 > 509)
{
@@ -384,8 +384,9 @@ void TreeSocket::SendCapabilities()
bool TreeSocket::HasItem(const std::string &list, const std::string &item)
{
irc::commasepstream seplist(list);
- std::string item2 = "*";
- while ((item2 = seplist.GetToken()) != "")
+ std::string item2;
+
+ while (seplist.GetToken(item2))
{
if (item2 == item)
return true;
@@ -397,9 +398,9 @@ bool TreeSocket::HasItem(const std::string &list, const std::string &item)
std::string TreeSocket::ListDifference(const std::string &one, const std::string &two)
{
irc::commasepstream list_one(one);
- std::string item = "*";
+ std::string item;
std::string result;
- while ((item = list_one.GetToken()) != "")
+ while (list_one.GetToken(item))
{
if (!HasItem(two, item))
{