if(ap_should_client_block(r)) {
char body[1025];
- memset(body,0,1025);
+ memset(body,0,sizeof(body));
buffer = buffer_init(1025);
}
buffer_add( buffer, body );
- memset(body,0,1025);
+ memset(body,0,sizeof(body));
osrfLogDebug(OSRF_LOG_MARK,
"gateway read %d bytes: %d bytes of data so far", bread, buffer->n_used);
if(buffer->n_used > APACHE_TOOLS_MAX_POST_SIZE) {
osrfLogError(OSRF_LOG_MARK, "gateway received POST larger "
- "than %d bytes. dropping reqeust", APACHE_TOOLS_MAX_POST_SIZE);
+ "than %d bytes. dropping request", APACHE_TOOLS_MAX_POST_SIZE);
buffer_free(buffer);
return NULL;
}
char* cfg = osrf_json_gateway_config_file;
char buf[32];
- memset(buf, 0x0, 32);
int t = time(NULL);
- snprintf(buf, 32, "%d", t);
+ snprintf(buf, sizeof(buf), "%d", t);
if( ! osrfSystemBootstrapClientResc( cfg, CONFIG_CONTEXT, buf ) ) {
ap_log_error( APLOG_MARK, APLOG_ERR, 0, s,
"OpenSRF JSON Request returned error: %s -> %s", statusname, statustext );
int l = strlen(statusname) + strlen(statustext) + 32;
char buf[l];
- bzero(buf,l);
if (isXML)
- snprintf( buf, l, "<debug>\"%s : %s\"</debug>", statusname, statustext );
+ snprintf( buf, sizeof(buf), "<debug>\"%s : %s\"</debug>", statusname, statustext );
else {
char bb[l];
- bzero(bb, l);
- snprintf(bb, l, "%s : %s", statusname, statustext);
+ snprintf(bb, sizeof(bb), "%s : %s", statusname, statustext);
jsonObject* tmp = jsonNewObject(bb);
char* j = jsonToStringFunc(tmp);
- snprintf( buf, l, ",\"debug\": %s", j);
+ snprintf( buf, sizeof(buf), ",\"debug\": %s", j);
free(j);
jsonObjectFree(tmp);
}
/* insert the status code */
char buf[32];
- bzero(buf,32);
if (isXML)
- snprintf(buf, 32, "<status>%d</status>", statuscode );
+ snprintf(buf, sizeof(buf), "<status>%d</status>", statuscode );
else
- snprintf(buf, 32, ",\"status\":%d", statuscode );
+ snprintf(buf, sizeof(buf), ",\"status\":%d", statuscode );
ap_rputs( buf, r );
int l = strlen(toAddr);
char dombuf[l];
- bzero(dombuf, l);
+ memset(dombuf, 0, sizeof(dombuf));
jid_get_domain( toAddr, dombuf, l );
if( eq( dombuf, cs->domain ) ) { /* this is to a user we host */
char* osrfChatMkAuthKey() {
char keybuf[112];
- bzero(keybuf, 112);
- snprintf(keybuf, 111, "%d%ld%s", (int) time(NULL), (long) getpid(), getenv("HOSTNAME"));
+ snprintf(keybuf, sizeof(keybuf), "%d%ld%s", (int) time(NULL), (long) getpid(), getenv("HOSTNAME"));
return strdup(shahash(keybuf));
}
signal(SIGINT, sig_int);
fprintf(stderr, "Listener: %ld\n", (long) getpid() );
char buf[300];
- memset(buf, 0, 300);
+ memset(buf, 0, sizeof(buf));
printf("=> ");
- while( fgets( buf, 299, stdin) ) {
+ while( fgets( buf, sizeof(buf), stdin) ) {
// remove newline
buf[strlen(buf)-1] = '\0';
client_send_message( client, send );
message_free( send );
printf("\n=> ");
- memset(buf, 0, 300);
+ memset(buf, 0, sizeof(buf));
}
fprintf(stderr, "Killing child %d\n", pid );
kill( pid, SIGKILL );
if(_osrfLogIsClient) {
static int _osrfLogXidInc = 0; /* increments with each new xid for uniqueness */
char buf[32];
- memset(buf, 0x0, 32);
- snprintf(buf, 32, "%s%d", _osrfLogXidPfx, _osrfLogXidInc);
+ snprintf(buf, sizeof(buf), "%s%d", _osrfLogXidPfx, _osrfLogXidInc);
_osrfLogSetXid(buf);
_osrfLogXidInc++;
}
if(!is) return;
/* go ahead and create the xid prefix so it will be consistent later */
static char buff[32];
- memset(buff, 0x0, 32);
- snprintf(buff, 32, "%d%ld", (int)time(NULL), (long) getpid());
+ snprintf(buff, sizeof(buff), "%d%ld", (int)time(NULL), (long) getpid());
_osrfLogXidPfx = buff;
}
if( logtype == OSRF_LOG_TYPE_SYSLOG ) {
char buf[1536];
- memset(buf, 0x0, 1536);
+ memset(buf, 0x0, sizeof(buf));
/* give syslog some breathing room, and be cute about it */
strncat(buf, msg, 1535);
buf[1532] = '.';
char target_buf[512];
target_buf[ 0 ] = '\0';
- int len = snprintf( target_buf, 512, "%s@%s/%s",
+ int len = snprintf( target_buf, sizeof(target_buf), "%s@%s/%s",
router_name ? router_name : "(null)",
domain ? domain : "(null)",
remote_service ? remote_service : "(null)" );
/* build a chunky, random session id */
char id[256];
- memset(id,0,256);
- sprintf(id, "%f.%d%ld", get_timestamp_millis(), (int)time(NULL), (long) getpid());
+ snprintf(id, sizeof(id), "%f.%d%ld", get_timestamp_millis(), (int)time(NULL), (long) getpid());
session->session_id = strdup(id);
osrfLogDebug( OSRF_LOG_MARK, "Building a new client session with id [%s] [%s]",
session->remote_service, session->session_id );
while( post >= ctx->chunksize ) post--;
int l = post - pre;
char buf[l];
- memset(buf, 0, l);
- snprintf(buf, l, ctx->chunk + pre);
+ snprintf(buf, sizeof(buf), ctx->chunk + pre);
ctx->handler->handleError( ctx->userData,
"*JSON Parser Error\n - char = %c\n "
"- index = %d\n - near => %s\n - %s",
*/
#define hexdigit(x) ( ((x) <= '9') ? (x) - '0' : ((x) & 7) + 9)
unsigned char utf_out[4];
- memset(utf_out,0,4);
+ memset(utf_out, 0, sizeof(utf_out));
char* buf = ctx->utfbuf->buf;
unsigned int ucs_char =
for(i = 0; i < count; i++) {
- memset(buf, 0, 16);
- snprintf(buf, 16, "key_%d", i);
+ snprintf(buf, sizeof(buf), "key_%d", i);
array = jsonNewObject(NULL);
for(k = 0; k < count + i; k++) {
/* json string */
case '"':
(*index)++;
- status = json_parse_json_string(string, index, obj, current_strlen); break;
+ status = json_parse_json_string(string, index, obj, current_strlen);
+ break;
/* json array */
case '[':
(*index)++;
- status = json_parse_json_array(string, index, obj, current_strlen);
+ status = json_parse_json_array(string, index, obj, current_strlen);
break;
/* json object */
default:
if(isdigit(c) || c == '.' || c == '-') { /* are we a number? */
- status = json_parse_json_number(string, index, obj, current_strlen);
+ status = json_parse_json_number(string, index, obj, current_strlen);
if(status) return status;
break;
}
"json_parse_json_string(): truncated escaped unicode"); }
char buff[5];
- memset(buff,0,5);
+ memset(buff, 0, sizeof(buff));
memcpy(buff, string + (*index), 4);
/* The following chunk was borrowed with permission from
json-c http://oss.metaparadigm.com/json-c/ */
unsigned char utf_out[3];
- memset(utf_out,0,3);
+ memset(utf_out, 0, sizeof(utf_out));
#define hexdigit(x) ( ((x) <= '9') ? (x) - '0' : ((x) & 7) + 9)
int json_handle_error(char* string, unsigned long* index, char* err_msg) {
char buf[60];
- memset(buf, 0, 60);
+ memset(buf, 0, sizeof(buf));
if(*index > 30)
strncpy( buf, string + (*index - 30), 59 );
jsonObject* json = jsonNewObject(NULL);
jsonObjectSetClass(json, "osrfMessage");
jsonObject* payload;
- char sc[64]; memset(sc,0,64);
+ char sc[64];
+ memset(sc, 0, sizeof(sc));
char* str;
payload = jsonNewObject(NULL);
jsonObjectSetClass(payload, msg->status_name);
jsonObjectSetKey(payload, "status", jsonNewObject(msg->status_text));
- sprintf(sc,"%d",msg->status_code);
+ snprintf(sc, sizeof(sc), "%d", msg->status_code);
jsonObjectSetKey(payload, "statusCode", jsonNewObject(sc));
jsonObjectSetKey(json, "payload", payload);
break;
payload = jsonNewObject(NULL);
jsonObjectSetClass(payload,"osrfResult");
jsonObjectSetKey(payload, "status", jsonNewObject(msg->status_text));
- sprintf(sc,"%d",msg->status_code);
+ snprintf(sc, sizeof(sc), "%d", msg->status_code);
jsonObjectSetKey(payload, "statusCode", jsonNewObject(sc));
str = jsonObjectToJSON(msg->_result_content);
jsonObjectSetKey(payload, "content", jsonParseString(str));
/* if no data was reveived within the timeout interval */
if( !recvd && (end - start) >= keepalive ) {
- osrfLogInfo(OSRF_LOG_MARK, "No request was reveived in %d seconds, exiting stateful session", keepalive);
+ osrfLogInfo(OSRF_LOG_MARK, "No request was received in %d seconds, exiting stateful session", keepalive);
osrfAppSessionStatus(
session,
OSRF_STATUS_TIMEOUT,
/* now suck off the data */
char buf[64];
- memset( buf, 0, 64);
+ memset( buf, 0, sizeof(buf) );
if( (n=read(cur_child->read_status_fd, buf, 63)) < 0 ) {
- osrfLogWarning( OSRF_LOG_MARK, "Read error afer select in child status read with errno %d", errno);
+ osrfLogWarning( OSRF_LOG_MARK, "Read error after select in child status read with errno %d", errno);
}
osrfLogDebug( OSRF_LOG_MARK, "Read %d bytes from status buffer: %s", n, buf );
int i,n;
growing_buffer* gbuf = buffer_init( READ_BUFSIZE );
char buf[READ_BUFSIZE];
- memset( buf, 0, READ_BUFSIZE );
+ memset( buf, 0, sizeof(buf) );
for( i = 0; i < child->max_requests; i++ ) {
if(!gotdata)
set_fl(child->read_data_fd, O_NONBLOCK );
buffer_add( gbuf, buf );
- memset( buf, 0, READ_BUFSIZE );
+ memset( buf, 0, sizeof(buf) );
gotdata = 1;
}
osrf_app_session_set_remote( session, msg->sender );
osrf_message* arr[OSRF_MAX_MSGS_PER_PACKET];
- memset(arr, 0, OSRF_MAX_MSGS_PER_PACKET );
+ memset(arr, 0, sizeof(arr));
int num_msgs = osrf_message_deserialize(msg->body, arr, OSRF_MAX_MSGS_PER_PACKET);
osrfLogDebug( OSRF_LOG_MARK, "We received %d messages from %s", num_msgs, msg->sender );
} else {
osrfLogWarning( OSRF_LOG_MARK, " * Jabber Error is for top level remote id [%s], no one "
- "to send my message too!!!", session->remote_id );
+ "to send my message to!!!", session->remote_id );
}
}
if(!(grp && msg)) return -1;
char domain[256];
- bzero(domain, 256);
+ memset(domain, 0, sizeof(domain));
jid_get_domain( msg->recipient, domain, 255 );
osrfTransportGroupNode* node = osrfHashGet(grp->nodes, domain);
int bufsize = 256;
char domain[bufsize];
- bzero(domain, bufsize);
+ memset(domain, 0, sizeof(domain));
jid_get_domain( msg->recipient, domain, bufsize - 1 );
char msgrecip[bufsize];
- bzero(msgrecip, bufsize);
+ memset(msgrecip, 0, sizeof(msgrecip));
jid_get_username(msg->recipient, msgrecip, bufsize - 1);
char msgres[bufsize];
- bzero(msgres, bufsize);
+ memset(msgres, 0, sizeof(msgres));
jid_get_resource(msg->recipient, msgres, bufsize - 1);
char* firstdomain = NULL;
/* update the recipient domain if necessary */
if(updateRecip) {
- bzero(newrcp, 1024);
- sprintf(newrcp, "%s@%s/%s", msgrecip, node->domain, msgres);
+ snprintf(newrcp, sizeof(newrcp), "%s@%s/%s", msgrecip, node->domain, msgres);
free(msg->recipient);
msg->recipient = strdup(newrcp);
}
int read_bytes;
int sock_fd = node->sock_fd;
- memset(buf, 0, RBUFSIZE);
+ memset(buf, 0, sizeof(buf));
set_fl(sock_fd, O_NONBLOCK);
osrfLogInternal( OSRF_LOG_MARK, "%ld : Received data at %f\n", (long) getpid(), get_timestamp_millis());
if(mgr->data_received)
mgr->data_received(mgr->blob, mgr, sock_fd, buf, node->parent_id);
- memset(buf, 0, RBUFSIZE);
+ memset(buf, 0, sizeof(buf));
}
int local_errno = errno; /* capture errno as set by recv() */
char* our_hostname = getenv("HOSTNAME");
size1 = 150 + strlen( server );
char stanza1[ size1 ];
- memset( stanza1, 0, size1 );
- sprintf( stanza1,
+ snprintf( stanza1, sizeof(stanza1),
"<stream:stream version='1.0' xmlns:stream='http://etherx.jabber.org/streams' "
"xmlns='jabber:component:accept' to='%s' from='%s' xml:lang='en'>",
username, our_hostname );
int ss = session->session_id->n_used + strlen(password) + 5;
char hashstuff[ss];
- memset(hashstuff,0,ss);
- sprintf( hashstuff, "%s%s", session->session_id->buf, password );
+ snprintf( hashstuff, sizeof(hashstuff), "%s%s", session->session_id->buf, password );
char* hash = shahash( hashstuff );
size2 = 100 + strlen( hash );
char stanza2[ size2 ];
- memset( stanza2, 0, size2 );
- sprintf( stanza2, "<handshake>%s</handshake>", hash );
+ snprintf( stanza2, sizeof(stanza2), "<handshake>%s</handshake>", hash );
//if( ! tcp_send( session->sock_obj, stanza2 ) ) {
if( socket_send( session->sock_id, stanza2 ) ) {
/* the first Jabber connect stanza */
size1 = 100 + strlen( server );
char stanza1[ size1 ];
- memset( stanza1, 0, size1 );
- sprintf( stanza1,
+ snprintf( stanza1, sizeof(stanza1),
"<stream:stream to='%s' xmlns='jabber:client' "
"xmlns:stream='http://etherx.jabber.org/streams'>",
server );
/* the second jabber connect stanza including login info*/
size2 = 150 + strlen( username ) + strlen(password) + strlen(resource);
char stanza2[ size2 ];
- memset( stanza2, 0, size2 );
-
- sprintf( stanza2,
+ snprintf( stanza2, sizeof(stanza2),
"<iq id='123456789' type='set'><query xmlns='jabber:iq:auth'>"
"<username>%s</username><password>%s</password><resource>%s</resource></query></iq>",
username, password, resource );
int ss = session->session_id->n_used + strlen(password) + 5;
char hashstuff[ss];
- memset(hashstuff,0,ss);
- sprintf( hashstuff, "%s%s", session->session_id->buf, password );
+ snprintf( hashstuff, sizeof(hashstuff), "%s%s", session->session_id->buf, password );
char* hash = shahash( hashstuff );
/* the second jabber connect stanza including login info*/
size2 = 150 + strlen( hash ) + strlen(password) + strlen(resource);
char stanza2[ size2 ];
- memset( stanza2, 0, size2 );
-
- sprintf( stanza2,
+ snprintf( stanza2, sizeof(stanza2),
"<iq id='123456789' type='set'><query xmlns='jabber:iq:auth'>"
"<username>%s</username><digest>%s</digest><resource>%s</resource></query></iq>",
username, hash, resource );
void *session, const xmlChar *ch, int len) {
char data[len+1];
- memset( data, 0, len+1 );
strncpy( data, (char*) ch, len );
data[len] = 0;
if( ses->state_machine->in_error ) {
/* for now... */
- osrfLogWarning( OSRF_LOG_MARK, "ERROR Xml fragment: %s\n", ch );
+ osrfLogWarning( OSRF_LOG_MARK, "ERROR XML fragment: %s\n", ch );
}
}
int i = 0;
while( i < argc ) {
int len = strlen( global_argv[i]);
- bzero( global_argv[i++], len );
+ memset( global_argv[i], 0, len);
global_argv_size += len;
+ i++;
}
global_argv_size -= 2;
int set_proc_title( char* format, ... ) {
VA_LIST_TO_STRING(format);
- bzero( *(global_argv), global_argv_size );
+ memset( *(global_argv), 0, global_argv_size);
return snprintf( *(global_argv), global_argv_size, VA_BUF );
}
len = va_list_size(format, args);
char buf[len];
- memset(buf, 0, len);
+ memset(buf, 0, sizeof(buf));
va_start(a_copy, format);
vsnprintf(buf, len - 1, format, a_copy);
len = va_list_size(format, args);
char buf[len];
- memset(buf, 0, len);
+ memset(buf, 0, sizeof(buf));
va_start(a_copy, format);
vsnprintf(buf, len - 1, format, a_copy);
int buffer_reset( growing_buffer *gb){
if( gb == NULL ) { return 0; }
if( gb->buf == NULL ) { return 0; }
- memset( gb->buf, 0, gb->size );
+ memset( gb->buf, 0, sizeof(gb->buf) );
gb->n_used = 0;
return 1;
}
int len = 1024;
char buf[len];
- bzero(buf, len);
+ memset(buf, 0, sizeof(buf));
growing_buffer* gb = buffer_init(len);
FILE* file = fopen(filename, "r");
return NULL;
}
- while(fgets(buf, len - 1, file)) {
+ while(fgets(buf, sizeof(buf), file)) {
buffer_add(gb, buf);
- bzero(buf, len);
+ memset(buf, 0, sizeof(buf));
}
fclose(file);
MD5_stop (&ctx, digest);
char buf[16];
- memset(buf,0,16);
-
char final[256];
- memset(final,0,256);
+ memset(final, 0, sizeof(final));
for ( i=0 ; i<16 ; i++ ) {
- sprintf(buf, "%02x", digest[i]);
+ snprintf(buf, sizeof(buf), "%02x", digest[i]);
strcat( final, buf );
}
"json_parse_json_string(): truncated escaped unicode"); }
char buff[5];
- memset(buff,0,5);
+ memset(buff, 0, sizeof(buff));
memcpy(buff, string + (*index), 4);
/* The following chunk was borrowed with permission from
json-c http://oss.metaparadigm.com/json-c/ */
unsigned char utf_out[4];
- memset(utf_out,0,4);
+ memset(utf_out, 0, sizeof(utf_out));
#define hexdigit(x) ( ((x) <= '9') ? (x) - '0' : ((x) & 7) + 9)
int json_handle_error(char* string, unsigned long* index, char* err_msg) {
char buf[60];
- memset(buf, 0, 60);
+ memset(buf, 0, sizeof(buf));
if(*index > 30)
strncpy( buf, string + (*index - 30), 59 );
char buf[10240];
char smallbuf[512];
- bzero(buf, 10240);
- bzero(smallbuf, 512);
+ memset(buf, 0, sizeof(buf));
+ memset(smallbuf, 0, sizeof(smallbuf));
- while(fgets(smallbuf, 512, F))
- strcat(buf, smallbuf);
+ while(fgets(smallbuf, sizeof(smallbuf), F))
+ strncat(buf, smallbuf, sizeof(buf) - 1);
/* dig our way into the JSON object we parsed, see test.json to get
an idea of the object structure */
/* if the sender is not a trusted server, drop the message */
int len = strlen(msg->sender) + 1;
char domain[len];
- bzero(domain, len);
+ memset(domain, 0, sizeof(domain));
jid_get_domain( msg->sender, domain, len - 1 );
if(osrfStringArrayContains( router->trustedServers, domain))
/* if the client is not from a trusted domain, drop the message */
int len = strlen(msg->sender) + 1;
char domain[len];
- bzero(domain, len);
+ memset(domain, 0, sizeof(domain));
jid_get_domain( msg->sender, domain, len - 1 );
if(osrfStringArrayContains( router->trustedClients, domain)) {
int T = 32;
osrfMessage* arr[T];
- memset(arr, 0, T );
+ memset(arr, 0, sizeof(arr));
int num_msgs = osrf_message_deserialize( msg->body, arr, T );
osrfMessage* omsg = NULL;
osrfMessage* success = osrf_message_init( STATUS, omsg->thread_trace, omsg->protocol );
- osrfLogDebug( OSRF_LOG_MARK, "router recevied a CONNECT message from %s", msg->sender );
+ osrfLogDebug( OSRF_LOG_MARK, "router received a CONNECT message from %s", msg->sender );
osrf_message_set_status_info(
success, "osrfConnectStatus", "Connection Successful", OSRF_STATUS_OK );
char* home = getenv("HOME");
int l = strlen(home) + 36;
char fbuf[l];
- memset(fbuf, 0, l);
- sprintf(fbuf,"%s/.srfsh.xml",home);
+ snprintf(fbuf, sizeof(fbuf), "%s/.srfsh.xml", home);
if(!access(fbuf, R_OK)) {
if( ! osrf_system_bootstrap_client(fbuf, "srfsh") ) {
char* home = getenv("HOME");
int l = strlen(home) + 24;
char fbuf[l];
-
- memset(fbuf, 0, l);
- sprintf(fbuf,"%s/.srfsh_history",home);
+ snprintf(fbuf, sizeof(fbuf), "%s/.srfsh_history", home);
history_file = strdup(fbuf);
if(!access(history_file, W_OK | R_OK )) {
static const char text[] = "request %s opensrf.system.method %s";
len = sizeof( text ) + strlen( words[1] ) + strlen( words[2] );
char buf[len];
- sprintf( buf, text, words[1], words[2] );
+ snprintf( buf, sizeof(buf), text, words[1], words[2] );
return parse_request( buf );
} else {
static const char text[] = "request %s opensrf.system.method.all";
len = sizeof( text ) + strlen( words[1] );
char buf[len];
- sprintf( buf, text, words[1] );
+ snprintf( buf, sizeof(buf), text, words[1] );
return parse_request( buf );
}
if(!type) type = "opac";
char login_text[] = "request open-ils.auth open-ils.auth.authenticate.init \"%s\"";
- size_t len = sizeof( login_text ) + strlen(username);
+ size_t len = sizeof( login_text ) + strlen(username) + 1;
char buf[len];
- buf[0] = '\0';
- sprintf( buf, login_text, username );
+ snprintf( buf, sizeof(buf), login_text, username );
parse_request(buf);
const char* hash;
size_t both_len = strlen( hash ) + strlen( pass_buf ) + 1;
char both_buf[both_len];
- both_buf[0] = '\0';
- sprintf(both_buf,"%s%s",hash, pass_buf);
+ snprintf(both_buf, sizeof(both_buf), "%s%s", hash, pass_buf);
char* mess_buf = md5sum(both_buf);
} else {
char code[16];
- memset(code, 0, 16);
- sprintf( code, "%d", omsg->status_code );
+ snprintf( code, sizeof(code), "%d", omsg->status_code );
buffer_add( resp_buffer, code );
printf( "\nReceived Exception:\nName: %s\nStatus: %s\nStatus: %s\n",
buffer_add( resp_buffer, omsg->status_text );
buffer_add( resp_buffer, "\nStatus: " );
char code[16];
- memset(code, 0, 16);
- sprintf( code, "%d", omsg->status_code );
+ snprintf( code, sizeof(code), "%d", omsg->status_code );
buffer_add( resp_buffer, code );
}
}
return 0;
const static char router_text[] = "router@%s/router";
- size_t len = sizeof( router_text ) + strlen( router_server );
+ size_t len = sizeof( router_text ) + strlen( router_server ) + 1;
char rbuf[len];
- rbuf[0] = '\0';
- sprintf(rbuf, router_text, router_server );
+ snprintf(rbuf, sizeof(rbuf), router_text, router_server );
transport_message* send =
message_init( "servers", NULL, NULL, rbuf, NULL );
char* answers[] = { "3", "-1", "2", "0.500000" };
float times[ count * 4 ];
- memset(times,0,count*4);
+ memset(times, 0, sizeof(times));
int k;
for(k=0;k!=100;k++) {