int message_api_tests_passed(){ void * p = request_memory_block(); int i = 0; int testCases = 100; for(i = 0; i < testCases; i++){ set_sender_PID(p, i); assert(get_sender_PID(p) == i,"message api function is broken"); set_destination_PID(p, i); assert(get_destination_PID(p) == i,"message api function is broken"); set_message_type(p, i); assert(get_message_type(p) == i,"message api function is broken"); assert(get_message_data(p) != 0,"message api function is broken"); assert(get_message_data(p) != 0,"message api function is broken"); //set_message_data(p,p, 10); } release_memory_block(p); return 1; }
/** * Callback called when a response from a request was retrieved * * @callback net~onResponse * * @param {Object} data * @param {String} data.body * The message body * @param {Object} data.he * An object that contains all response headers * @param {SoupMessage} message The soup message * */ static void request_callback(SoupSession *session, SoupMessage *message, JSObjectRef function) { JSContextRef ctx = scripts_get_global_context(); if (ctx != NULL) { if (message->response_body->data != NULL) { JSValueRef o = get_message_data(message); JSValueRef vals[] = { o, make_object_for_class(ctx, CLASS_GOBJECT, G_OBJECT(message), true) }; scripts_call_as_function(ctx, function, function, 2, vals); } JSValueUnprotect(ctx, function); scripts_release_global_context(); } }
/* ********************************************************************** * control_rpt_line() * * Add line (for current file) to control report * * Inputs: file_id - file_id of file we are reporting on * server_id - server_id of file we are reporting on * filename - file we are reporting on * control_filename - name of corresponding control file, if any. * error_code - 0 if no error, other wise error that occurred. * * Outputs: none * * Returns: void * Globals: *********************************************************************** */ void control_rpt_line(COM_SOURCE *src, int file_id, tiny server_id, char *filename, int num_bytes, int error_code ) { ERROR_MESSAGE msg_struct; if(error_code) { if(get_message_data(error_code, &msg_struct) == SUCCESS) sprintf(gstrScratch,"%s", msg_struct.text); else strcpy(gstrScratch,"Message number not found"); } else { strcpy(gstrScratch, "SUCCESS"); } fprintf(gfpCtrlRpt, "%8d %8d %-8.8s %-8.8s %-7.7s %9d %6d %-42.42s %8d %s\n", src->contact->ext_contact_id, src->contact->source_id, src->source_type_sdisplay, src->access_method_sdisplay, src->contact->is_send ? "SEND" : "RECEIVE", file_id, server_id, filename, num_bytes, gstrScratch); if ( fflush(gfpCtrlRpt) != 0 ) MPS_EMIT_CALL_ERRNO_LOG(fflush); /* set to FALSE since at least one line is output...*/ gbNoOutput = FALSE; return; } /* control_rpt_line() */
/** * Sends a http-request synchronously * @name sendRequestSync * @memberOf net * @function * * @param {String} uri The uri the request will be sent to. * @param {String} [method] The http request method, default GET * * @returns {Object} * Object that contains the response body, the response headers and the * http status code of the request. * */ static JSValueRef net_send_request_sync(JSContextRef ctx, JSObjectRef f, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc) { char *method = NULL, *uri = NULL; SoupMessage *msg; guint status; JSValueRef val; JSObjectRef o; JSStringRef js_key; JSValueRef js_value; if (argc < 1) return NIL; uri = js_value_to_char(ctx, argv[0], -1, exc); if (uri == NULL) return NIL; if (argc > 1) method = js_value_to_char(ctx, argv[1], -1, exc); msg = soup_message_new(method == NULL ? "GET" : method, uri); if (argc > 2) set_request(ctx, msg, argv[2], exc); status = soup_session_send_message(webkit_get_default_session(), msg); val = get_message_data(msg); js_key = JSStringCreateWithUTF8CString("status"); js_value = JSValueMakeNumber(ctx, status); o = JSValueToObject(ctx, val, exc); JSObjectSetProperty(ctx, o, js_key, js_value, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly, exc); JSStringRelease(js_key); return o; }