Skip to content

Commit

Permalink
bug fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanocasazza committed Jul 24, 2015
1 parent 6f780f9 commit 488927d
Show file tree
Hide file tree
Showing 19 changed files with 210 additions and 165 deletions.
2 changes: 1 addition & 1 deletion include/ulib/examples/wi_auth_declaration.h
Expand Up @@ -3994,7 +3994,7 @@ static void GET_get_config()

UHTTP::mime_index = U_know;

if (cfg.processData())
if (cfg.processData(false))
{
_body = cfg.getData();

Expand Down
2 changes: 1 addition & 1 deletion include/ulib/file_config.h
Expand Up @@ -128,7 +128,7 @@ class U_EXPORT UFileConfig : public UFile {

// EXT

bool processData();
bool processData(bool bload);

UString getData() const { return data; }
void setData(const UString& _data, bool _preprocessing) { data = _data; preprocessing = _preprocessing; }
Expand Down
8 changes: 5 additions & 3 deletions include/ulib/string.h
Expand Up @@ -1002,6 +1002,8 @@ class U_EXPORT UString {
U_INTERNAL_ASSERT(invariant())
}

void setFromData(const char** ptr, uint32_t sz, unsigned char delim);

public:
// mutable
UStringRep* rep;
Expand Down Expand Up @@ -1765,9 +1767,6 @@ class U_EXPORT UString {
va_end(argp);
}

void setFromData(const char** ptr, uint32_t sz);
void setFromData(const char** ptr, uint32_t sz, unsigned char delim);

void size_adjust() { rep->size_adjust(); }
void size_adjust_force() { rep->size_adjust_force(); }

Expand Down Expand Up @@ -1929,6 +1928,9 @@ class U_EXPORT UString {
private:
char* __append(uint32_t n);
char* __replace(uint32_t pos, uint32_t n1, uint32_t n2);

template <class T> friend class UVector;
template <class T> friend class UHashMap;
};

// operator ==
Expand Down
3 changes: 2 additions & 1 deletion include/ulib/utility/data_session.h
Expand Up @@ -199,7 +199,8 @@ class U_EXPORT UDataSession : public UDataStorage {
{
U_TRACE(0, "UDataSession::getValueVar(%u,%p)", index, &value)

value = vec_var->at(index);
if (index < vec_var->size()) value = vec_var->at(index);
else value.clear();

U_INTERNAL_DUMP("value = %V", value.rep)
}
Expand Down
1 change: 1 addition & 0 deletions include/ulib/utility/uhttp.h
Expand Up @@ -435,6 +435,7 @@ class U_EXPORT UHTTP {
// COOKIE

static UString* set_cookie;
static uint32_t sid_counter_gen;
static UString* set_cookie_option;
static UString* cgi_cookie_option;

Expand Down
34 changes: 28 additions & 6 deletions src/ulib/container/hash_map.cpp
Expand Up @@ -663,12 +663,23 @@ uint32_t UHashMap<UString>::loadFromData(const char* ptr, uint32_t sz)

// U_INTERNAL_DUMP("c = %C", c)

if (c == '"') _key.setFromData(&ptr, sz, '"');
if (c == '"')
{
// NB: check if we have a string null...

if (*ptr != '"') _key.setFromData(&ptr, _end - ptr, '"');
else
{
++ptr;

_key.clear();
}
}
else
{
--ptr;

_key.setFromData(&ptr, sz);
_key.setFromData(&ptr, _end - ptr, terminator);
}

U_INTERNAL_ASSERT(_key)
Expand All @@ -686,12 +697,23 @@ uint32_t UHashMap<UString>::loadFromData(const char* ptr, uint32_t sz)

// U_INTERNAL_DUMP("c = %C", c)

if (c == '"') str.setFromData(&ptr, sz, '"');
if (c == '"')
{
// NB: check if we have a string null...

if (*ptr != '"') str.setFromData(&ptr, _end - ptr, '"');
else
{
++ptr;

str.clear();
}
}
else
{
--ptr;

str.setFromData(&ptr, sz);
str.setFromData(&ptr, _end - ptr, terminator);
}

U_INTERNAL_ASSERT(str)
Expand All @@ -700,9 +722,9 @@ uint32_t UHashMap<UString>::loadFromData(const char* ptr, uint32_t sz)
insert(_key, str);
}

U_INTERNAL_DUMP("ptr-_start = %lu", ptr-_start)
U_INTERNAL_DUMP("ptr - _start = %lu", ptr - _start)

U_INTERNAL_ASSERT((ptr-_start) <= sz)
U_INTERNAL_ASSERT((ptr - _start) <= sz)

sz = ptr - _start;

Expand Down
19 changes: 15 additions & 4 deletions src/ulib/container/vector.cpp
Expand Up @@ -1023,20 +1023,31 @@ uint32_t UVector<UString>::loadFromData(const char* ptr, uint32_t sz)

// U_INTERNAL_DUMP("c = %C", c)

if (c == '"') str.setFromData(&ptr, sz, '"');
if (c == '"')
{
// NB: check if we have a string null...

if (*ptr != '"') str.setFromData(&ptr, _end - ptr, '"');
else
{
++ptr;

str.clear();
}
}
else
{
--ptr;

str.setFromData(&ptr, sz);
str.setFromData(&ptr, _end - ptr, terminator);
}

push(str);
}

U_INTERNAL_DUMP("ptr-_start = %lu", ptr-_start)
U_INTERNAL_DUMP("ptr - _start = %lu", ptr - _start)

U_INTERNAL_ASSERT((ptr-_start) <= sz)
U_INTERNAL_ASSERT((ptr - _start) <= sz)

sz = ptr - _start;

Expand Down
44 changes: 26 additions & 18 deletions src/ulib/file_config.cpp
Expand Up @@ -49,14 +49,12 @@ UFileConfig::UFileConfig(const UString& _data, bool _preprocessing) : data(_data
preprocessing = _preprocessing;
}

bool UFileConfig::processData()
bool UFileConfig::processData(bool bload)
{
U_TRACE(0, "UFileConfig::processData()")
U_TRACE(0, "UFileConfig::processData(%b)", bload)

U_CHECK_MEMORY

bool result = false;

// manage if we need preprocessing...

#if defined(HAVE_CPP) || defined(HAVE_MCPP)
Expand Down Expand Up @@ -126,36 +124,46 @@ bool UFileConfig::processData()
}
#endif

if (data.empty()) U_RETURN(false);
if (data.empty()) U_RETURN(false);
if (bload == false) U_RETURN(true);

_end = data.end();
_start = data.data();
_size = data.size();

if (UFile::isPath())
{
// -------------------------------------------------------------
// Loads configuration information from the file.
// The file type is determined by the file extension.
// The following extensions are supported:
// -------------------------------------------------------------
// .properties - properties file (JAVA Properties)
//------------ -------------------------------------------------------------
// Loads configuration information from the file. The file type is
// determined by the file extension. The following extensions are supported:
// -------------------------------------------------------------------------
// .ini - initialization file (Windows INI)
// -------------------------------------------------------------
// .properties - properties file (JAVA Properties)
// -------------------------------------------------------------------------

UString suffix = UFile::getSuffix();

if (suffix)
{
if (suffix.equal(U_CONSTANT_TO_PARAM("ini"))) { result = loadINI(); goto end; }
else if (suffix.equal(U_CONSTANT_TO_PARAM("properties"))) { result = loadProperties(); goto end; }
if (suffix.equal(U_CONSTANT_TO_PARAM("ini")))
{
if (loadINI()) U_RETURN(true);

U_RETURN(false);
}

if (suffix.equal(U_CONSTANT_TO_PARAM("properties")))
{
if (loadProperties()) U_RETURN(true);

U_RETURN(false);
}
}
}

result = loadSection(0, 0);
if (loadSection(0, 0)) U_RETURN(true);

end:
U_RETURN(result);
U_RETURN(false);
}

void UFileConfig::load()
Expand All @@ -169,7 +177,7 @@ void UFileConfig::load()
if (UFile::open() &&
UFile::size() > 0 &&
UFile::memmap(PROT_READ, &data) &&
processData())
processData(true))
{
if (UFile::isOpen()) UFile::close();
}
Expand Down
71 changes: 37 additions & 34 deletions src/ulib/net/client/imap.cpp
Expand Up @@ -347,12 +347,13 @@ bool UImapClient::list(const UString& ref, const UString& wild, UVector<ListResp
U_RETURN(false);
}

/* STATUS command representation
typedef struct StatusInfo {
long messageCount, recentCount, nextUID, uidValidity, unseenCount;
bool hasMessageCount, hasRecentCount, hasNextUID, hasUIDValidity, hasUnseenCount;
} StatusInfo;
*/
/**
* STATUS command representation
* typedef struct StatusInfo {
* long messageCount, recentCount, nextUID, uidValidity, unseenCount;
* bool hasMessageCount, hasRecentCount, hasNextUID, hasUIDValidity, hasUnseenCount;
* } StatusInfo;
*/

bool UImapClient::status(const UString& mailboxName, StatusInfo& retval, int items)
{
Expand Down Expand Up @@ -380,43 +381,44 @@ bool UImapClient::status(const UString& mailboxName, StatusInfo& retval, int ite
uint32_t length, i = (ptr2 - ptr1);

UString x = buffer.substr(i, end - i);

UVector<UString> vec(x);

for (i = 0, length = vec.size(); i < length; ++i)
{
if (!retval.hasMessageCount &&
if (retval.hasMessageCount == false &&
vec[i].equal(U_CONSTANT_TO_PARAM("MESSAGES")))
{
retval.messageCount = vec[++i].strtol();
retval.hasMessageCount = true;
}
else if (!retval.hasRecentCount &&
else if (retval.hasRecentCount == false &&
vec[i] == *str_recent)
{
retval.recentCount = vec[++i].strtol();
retval.hasRecentCount = true;
}
else if (!retval.hasNextUID &&
else if (retval.hasNextUID == false &&
vec[i] == *str_uidnext)
{
retval.nextUID = vec[++i].strtol();
retval.hasNextUID = true;
}
else if (!retval.hasUIDValidity &&
else if (retval.hasUIDValidity == false &&
vec[i] == *str_uidvalidity)
{
retval.uidValidity = vec[++i].strtol();
retval.hasUIDValidity = true;
}
else if (!retval.hasUnseenCount &&
else if (retval.hasUnseenCount == false &&
vec[i] == *str_unseen)
{
retval.unseenCount = vec[++i].strtol();
retval.hasUnseenCount = true;
}
else
{
U_ERROR("Unknow tag response for STATUS command, exit..");
U_WARNING("Unknow tag response %V for STATUS command", vec[i].rep);
}
}

Expand All @@ -429,28 +431,29 @@ bool UImapClient::status(const UString& mailboxName, StatusInfo& retval, int ite
U_RETURN(false);
}

/* (SELECT | EXAMINE) command representation
typedef struct MailboxInfo {
bool readWrite;
StatusInfo status;
int flags, permanentFlags;
bool flagsAvailable, permanentFlagsAvailable, readWriteAvailable;
} MailboxInfo;
enum MailboxFlag {
SEEN = 1 << 0,
ANSWERED = 1 << 1,
FLAGGED = 1 << 2,
DELETED = 1 << 3,
DRAFT = 1 << 4,
RECENT = 1 << 5,
ASTERISK = 1 << 6,
MDNSent = 1 << 7,
Junk = 1 << 8,
NonJunk = 1 << 9,
Forwarded = 1 << 10
};
*/
/**
* (SELECT | EXAMINE) command representation
* typedef struct MailboxInfo {
* bool readWrite;
* StatusInfo status;
* int flags, permanentFlags;
* bool flagsAvailable, permanentFlagsAvailable, readWriteAvailable;
* } MailboxInfo;
*
* enum MailboxFlag {
* SEEN = 1 << 0,
* ANSWERED = 1 << 1,
* FLAGGED = 1 << 2,
* DELETED = 1 << 3,
* DRAFT = 1 << 4,
* RECENT = 1 << 5,
* ASTERISK = 1 << 6,
* MDNSent = 1 << 7,
* Junk = 1 << 8,
* NonJunk = 1 << 9,
* Forwarded = 1 << 10
* };
*/

U_NO_EXPORT void UImapClient::setFlag(int& _flags, UVector<UString>& vec)
{
Expand Down
4 changes: 2 additions & 2 deletions src/ulib/net/server/plugin/usp/cookie.usp
Expand Up @@ -10,8 +10,8 @@ delete_cookie;
UString ses_name;
-->
<!--#code
if (name.empty()) name = ses_name;
else ses_name = name;
if (name.empty()) name = ses_name;
else ses_name = name;

if (delete_cookie) UHTTP::removeDataSession();
-->
Expand Down
2 changes: 1 addition & 1 deletion src/ulib/net/server/plugin/usp/usp_translator.cpp
Expand Up @@ -111,7 +111,7 @@ class Application : public UApplication {
{
UFileConfig cfg(UStringExt::substitute(usp, U_CONSTANT_TO_PARAM("#include"), U_CONSTANT_TO_PARAM("//#include")), true);

if (cfg.processData()) usp = UStringExt::substitute(cfg.getData(), U_CONSTANT_TO_PARAM("//#include"), U_CONSTANT_TO_PARAM("#include"));
if (cfg.processData(false)) usp = UStringExt::substitute(cfg.getData(), U_CONSTANT_TO_PARAM("//#include"), U_CONSTANT_TO_PARAM("#include"));
else
{
# ifndef DEBUG
Expand Down

0 comments on commit 488927d

Please sign in to comment.