miker [Tue, 1 Jan 2008 01:56:28 +0000 (01:56 +0000)]
Patch from Scott McKellar:
1. Plugs a memory leak in file_to_string(). If we failed to open the
file, we were returning without freeing the growing_buffer that held
the file name.
2. Replaces a couple of calls to buffer_data() with calls to
buffer_release().
miker [Tue, 1 Jan 2008 01:52:44 +0000 (01:52 +0000)]
Patch from Scott McKellar:
1. Added the const qualifier in various places.
2. Eliminated some unnecessary calls to strlen(), where they were
used merely to determine whether a string was empty.
3. Ensured that all members of a new transport_message are
explicitly populated.
4. Plugged a memory leak in the case where strdup() fails.
5. Eliminated some unhelpful casts of malloc'd pointers.
6. Added some protective tests for NULL pointer parameters.
7. In several spots I replaced numeric literals with character
literals, both to make the code more readable and to avoid a needless
dependence on ASCII.
8. Rewrote the jid_get_resource function to avoid repeatedly
overwriting the same buffer.
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