miker [Tue, 11 Dec 2007 12:33:57 +0000 (12:33 +0000)]
Patch from Scott McKellar to correct some problems with _jsonParserError(),
which constructs and issues a message about a parsing error:
The problems arise in the course of extracting a fragment of JSON text to
provide the context of the error.
1. The code starts by picking the beginning and end of the fragment to
extract. In order to avoid beginning before the start of the string,
the original code goes through a loop, incrementing an index until it
is non-negative. A similar loop corrects for an ending beyond the
end of the string.
These loops do the job, but to my eyes they look silly. I replaced
them by assigning the corrected values directly, when corrections
are in order.
2. There is an off-by-two error in calculating the size of the buffer
needed to hold the fragment. To begin with, we miscalculate the
length of the fragment. If the fragment extends from character 30
through character 40, there are 11 characters in the fragment, not
10. Then we neglect to add another byte for a terminal nul.
The result is that the last two characters in the intended fragment
are not displayed. If the character in error is the last or the
next to last character in the string, it doesn't get displayed as
part of the fragment, leading to likely bafflement.
I corrected both these errors, embiggening the buffer by two.
3. The original code copies the fragment into the buffer by calling
snprintf(). Besides being needlessly inefficient, snprintf() is
dangerous in this context. If the copied fragment contains a
format specifier such as "%s" or "%d", sprintf goes off looking for
a non-existent parameter, resulting in a mangled message or worse.
I replaced the snprintf() with a memcpy() and a terminal nul.
miker [Mon, 10 Dec 2007 02:35:36 +0000 (02:35 +0000)]
Patch from Scott McKellar to speed up parts of the growing_buffer API; return values from buffer add/reset API brought into a consistent state for proper return value checks
erickson [Fri, 7 Dec 2007 19:58:27 +0000 (19:58 +0000)]
created external script for downloading java dependencies. added new install.conf settings for where dependency jars are kept and whether or not to build the java libs
dbs [Fri, 7 Dec 2007 05:00:55 +0000 (05:00 +0000)]
Minor code cleanup:
Avoid stepping on str's toes by renaming the variable 'str' to string.
Explicitly call osrf.json and str methods rather than polluting global name space.
erickson [Thu, 29 Nov 2007 16:42:04 +0000 (16:42 +0000)]
added the proof-of-concept http multipart translation code. still needs request parsing to handle client disconnect messages and more testing with non-multipart
miker [Mon, 26 Nov 2007 18:20:40 +0000 (18:20 +0000)]
Patch from Scott McKellar:
1. Shift toward a camel case style of identifiers.
2. Make functions static when they are not called from elsewhere.
3. Populate all members in newly-allocated structs.
4. Add a couple of consts.
Details:
1. We have two redundant typdefs. I replaced all references to the
lower_case_with_underscores version with references to the camelCase
versions (while keeping the obsolescent typedefs themselves):
3. I eliminated osrf_app_session_make_locale_req(), replacing it
with the equivalent osrfAppSessionMakeLocaleRequest function. No
other file references the former.
4. I made the following functions static, and removed their
prototypes from the header, since none is referenced from any other
file:
osrfAppSessionMakeLocaleRequest()
osrfAppSessionSendBatch()
all remaining functions with a leading underscore
5. I explicitly initialized the stateless and session_locale members
of osrfAppSession.
6. I added the const qualifier to a couple of parameters of
osrfAppSessionStatus().
erickson [Tue, 20 Nov 2007 20:01:13 +0000 (20:01 +0000)]
Cleaned up exception messages so they will not be bloated with newlines
(which are rendered as '\n' in syslog and local apache logs, anyway) and
layers of "Mess:" tags. Logging the ISO timestamp instead of the default
output of Perl's localtime()
miker [Mon, 19 Nov 2007 03:19:09 +0000 (03:19 +0000)]
uber-patch from Scott McKellar cleans up large amounts of const-correctness issues and static-ifies several areas of unused header-based code; several cleanups to use simpler APIs such as buffer_release
erickson [Mon, 29 Oct 2007 12:23:31 +0000 (12:23 +0000)]
fixed infinite loop bug by hopping out of the loop if timeout gets down to 0, but the code still allows the the loop to occur once if timeout is initially 0
miker [Thu, 25 Oct 2007 12:20:16 +0000 (12:20 +0000)]
Patch from Scott McKellar to increase const correctness in the JSON parser.
Also made the top level legacy_jsonParseString[Fmt] API const-correct, though this is removed within those wrapper calls to avoid potentially breaking the legacy code.
miker [Fri, 19 Oct 2007 23:43:59 +0000 (23:43 +0000)]
Patches from Scott McKellar covering:
1. Eliminating a const-removing cast from jsonObjectToJSON(). This
cast is no longer necessary now that a recent patch has changed the
signature of jsonObjectEncodeClass().
2. Moving the JSON_INIT_CLEAR macro out of the header file and into
the implementation file. No other file invokes this macro -- nor
could it, since the macro refers to two static functions within
osrf_json_object.c. Strictly speaking another file could provide
other functions with the same signatures, but I doubt that any such
usage was ever intended.
3. Adds some sanity checking to prevent undefined behavior when
a floating point payload is not representable as an int.
4. Streamlines the serialization of hashes and arrays by
eliminating a layer of allocation and deallocation.
dbs [Thu, 18 Oct 2007 01:11:10 +0000 (01:11 +0000)]
Install the JavaScript libraries into an OpenSRF library,
in prepration for OpenSRF applications being able to use
one known good JavaScript library for OpenSRF communication.
(I'm looking at you, EG, and your two copies of JSON.js)
miker [Mon, 1 Oct 2007 02:47:44 +0000 (02:47 +0000)]
Patch that:
1) Creates safe_calloc, suggested by Scott McKellar which includes
memset, as calloc does. safe_malloc will eventually lose its call
to memset.
2) Creates a macro in utils.h called osrf_clearbuf which
* under CLFAGS=-DNDEBUG fills the buffer with !s and a trailing nul
* otherwise (currently) uses memset to fill with nuls
The secondary behavior should be changed to a no-op after no more
problems arise under NDEBUG mode. I reversed the suggested semantics
because I'm not ready to completely break trunk. To break everything
(AKA find where we should be providing a terminal nul) just compile
like this:
$ CLFAGS=-DNDEBUG make clean all
3) replaces all memsets (excepting the ones in safe_?alloc) that act
on char bufs with said macro, so they can be spotted and improved to
deal with nul terminators where needed. I didn't touch any memsets on
struct pointers.
4) made jid_get_*() from src/libopensrf/transport_message.c safe for
use with NDEBUG mode. They were depending on the target buffer that
the caller passes in to be nul-filled (they use strncpy/memcpy which
don't guarantee terminal nul) -- now they provide their own terminal
nul.
Broad patch from Dan Scott to move towards better memory management:
* bzero->memset (with sizeof) - except when followed immediately by
snprintf(), in which case the call was deleted completely
* sprintf->snprintf (with sizeof) - for the C99-guaranteed
null-terminated string and avoidance of overwrites
* fgets (with sizeof) - because in at least one case "len - 1" was
being used for the length, even though fgets is defined to retrieve 1
byte less than the requested length - so the code was effectively
retrieving 2 bytes less than the allocated buffer
* in 2 places in srfsh.c, increased buffer size by 1 to allow for
null terminator
* various typo fixes
Continued const-correctness improvement from Scott McKellar:
1. I changed the signature of jsonObjectDecodeClass so that it accepts
a non-const pointer parameter. Since it doesn't change the contents
of the jsonObject, there's no need to confine it to non-const
jsonObjects.
2. I replaced jsonObjectGetKey() with jsonObjectGetKeyConst().
3. In one spot I captured the return value of jsonObjectGetIndex()
with a const pointer instead of a non-const pointer.
Patch from Scott McKellar to improve const-correctness in srfsh:
This patch sprinkles a few const qualifiers over srfsh.c, and also
fixes a couple of things I stumbled across along the way.
The main purpose is to treat jsonObjects in a more const-correct
manner. I introduced a new jsonObjectGetKeyConst function, and I
prepared for the day when jsonObjectGetString() returns a const
pointer instead of a non-const pointer.
This patch relies on a previous patch that defines the new
jsonObjectGetKeyConst function.
1. In handle_login() I changed hash to a const pointer, so that we
can assign the return value of jsonObjectGetString() to it.
2. Later in the same function, I rearranged the code a bit to ensure
that we always free a prior value of login_session before giving it
a new value. The original code potentially leaks memory.
3. In the same area I changed authtoken to a const pointer.
4. In send_request() I eliminated an unnecessary test for the
non-nullness of omsg->_result_content, because we had just tested
it a few lines ago.
5. Also in send_request(): I introduced a layer of strdup() when
we get content from jsonObjectGetString(). This change concerns
more than just const-correctness.
The problem with the original code is that we get content sometimes
from jsonFormatString() and sometimes from jsonObjectGetString().
The former returns a malloc'ed buffer, which we need to free. The
latter returns a pointer to a buffer owned by a jsonObject, and we
should not free it. As it happens, we do free it. If we got the
string from jsonObjectGetString(), then we leave the jsonObject with
an invalid pointer inside it. If we free the jsonObject later, we'll
try to free that same buffer a second time. Oops.
Another issue is that jsonObjectGetString() can return NULL, which
we should handle more carefully.
These problems occur in two different places in the same function.
I fixed them both the same way, with some differences in the details.
Patch from Scott McKellar which introduces a const-accepting and -returning
version of jsonObjectGetKey. This is the first step in a plan to push
const-correctness on the OpenSRF stack when dealing with complex objects. The
hope is that this will increase the utility of compile-time checks in new
client code.