Boolean WSMProcessProtoTarget(Widget w, Atom target, XtPointer input, unsigned long input_len, int input_fmt, Atom *return_type, XtPointer *output, unsigned long *output_len, int *output_fmt) { Display *dpy; int scr_num; WSMScreenInfo *screen_info; WSMRequest request; WSMReply reply; /* * Check the Target to make sure it is valid. * Check the format to make sure it is WSM_PROTO_FMT. */ if (!WSMIsKnownTarget(w, target)) return(False); if (input_fmt != WSM_PROTO_FMT) { fprintf(stderr, "Format of the request must be %d\n", WSM_PROTO_FMT); return(False); } dpy = XtDisplay(w); scr_num = XScreenNumberOfScreen(XtScreen(w)); /* * Unpack up the request from the wire. */ _WSMUnpackRequest(dpy, scr_num, (MessageData) input, input_len, _WSMTargetToReqType(dpy, target), &request); /* * Call the app's callback function to process the request. */ screen_info = _WSMGetScreenInfo(dpy, scr_num); reply.any.type = request.any.type; reply.any.allocated = False; (*screen_info->request_callback)(w, screen_info->request_data, &request, &reply); /* * Pack up the reply and send it back. */ *output = (XtPointer) _WSMPackReply(dpy, scr_num, &reply, output_len); *output_fmt = WSM_PROTO_FMT; *return_type = target; /* Is this the right return type? */ FreeRequest(&request); FreeReply(&reply); return(TRUE); }
static PyObject *archonhttp_sendrequest(PyObject *self, PyObject *args, int method) { Http_request req; Http_response resp; PyObject *resp_header_dict, *py_header_dict, *py_resp; int rc; const char *py_host; const char *py_path; const char *py_body; char *header_s; //Parse python arguments into a request if (!PyArg_ParseTuple(args, "sssO", &py_host, &py_path, &py_body, &py_header_dict)) { return NULL; } memset(&req, 0, sizeof(Http_request)); req.method = method; if ((header_s = build_headers_string(py_header_dict)) == NULL) { PyErr_SetString(PyExc_RuntimeError, "Error building header string from dict"); return NULL; } if (asprintf(&req.host, "%s", py_host) < 0 || asprintf(&req.path, "%s", py_path) < 0 || asprintf(&req.port, "%s", "80") < 0 || asprintf(&req.headers, "%s", header_s) < 0 || asprintf(&req.body, "%s", py_body) < 0) { PyErr_NoMemory(); return NULL; } memset(&resp, 0, sizeof(Http_response)); //Run if ((rc = SendRequest(&req, &resp)) != 0) { PyErr_SetString(PyExc_RuntimeError, "Error on send"); return NULL; } //Return results to python resp_header_dict = build_headers_dict(&resp); py_resp = Py_BuildValue("sOssss", resp.body, resp_header_dict, resp.status, resp.reason, resp.version, resp.raw_response); FreeRequest(&req); return py_resp; }
static void ExecuteQueuedRequest ( unsigned long requestNum) { char *errorMessage; Boolean success = True; Cmd_RequestQueue *prev = NULL; Cmd_RequestQueue *pNode = requestQueue; unsigned long iomode; for (; pNode != NULL; pNode = pNode->next) { if ( pNode->request_num == requestNum ) { /* * Pluck pNode out of the queue */ if (prev) prev->next = pNode->next; else requestQueue = pNode->next; pNode->next = NULL; break; } /* * Move alone to the next node */ prev = pNode; } if (pNode == NULL) return; errorMessage = XtMalloc (MAX_BUF_SIZE * sizeof (char)); /* * Reopen SPC Channel */ iomode = ( SPCIO_NOIO | SPCIO_SYNC_TERMINATOR | SPCIO_FORCE_CONTEXT ); if ((pNode->channel = (_DtSPCOpen(pNode->exec_host, iomode, errorMessage))) == SPC_ERROR) { success = False; } if ( success ) if ((_DtSPCSpawn(pNode->argv[0], pNode->context, pNode->argv, NULL, pNode->channel, pNode->exec_host, NULL, NULL, errorMessage)) == SPC_ERROR) { success = False; if (DtSPCErrorNumber != SPC_Arg_Too_Long) DtSPCClose(pNode->channel); } if (success && pNode->success_proc != NULL) { if (cmd_Resources.executionHostLogging && pNode->success_data != NULL) { CallbackData *data; data = (CallbackData *) pNode->success_data; (void) sprintf (errorMessage, successHost, data->actionLabel, pNode->exec_host); _DtCmdLogErrorMessage (errorMessage); } (*pNode->success_proc) (NULL, pNode->success_data); } else if (!success) { if (cmd_Resources.executionHostLogging) { if (DtSPCErrorNumber == SPC_Arg_Too_Long) { int cmdlen,i; char *cmdp; /* pointer to complete command string */ char *tmp_message; /* * The message should include all of the command because * the problem may be with some on the internally generated * parts of the command (e.g. the terminal emulator and args). * This means going through all of argv to determine the * length of the string. */ for (cmdlen = 0, i = 0; pNode->argv[i]; i++) { cmdlen+=strlen(pNode->argv[i]); cmdlen+=2; /* make room for a space + string terminator */ } tmp_message = (char *) XtMalloc (strlen (errorSpawn) + strlen (pNode->exec_host) + cmdlen + 4); cmdp = (char *) XtMalloc(cmdlen + 1); *cmdp = NULL; for (i = 0; pNode->argv[i]; i++) { strcat(cmdp,pNode->argv[i]); strcat(cmdp, " "); } (void) sprintf (tmp_message, errorSpawn, pNode->exec_host, cmdp); _DtCmdLogErrorMessage (tmp_message); XtFree(cmdp); XtFree(tmp_message); } } if (pNode->failure_proc != NULL) (*pNode->failure_proc) (errorMessage, pNode->failure_data); } XtFree ((char *)errorMessage); FreeRequest (pNode); }
static void CheckCommandTerminator( SPC_Channel_Ptr cmdChannel, int pid, /* NOT USED */ int type, /* NOT USED */ int cause, /* Exit value of the remote process. */ unsigned long requestNum) /* Specifies the request number. */ { Boolean xhostError; char errorMessage[MAX_BUF_SIZE]; Cmd_RequestQueue *prev = NULL; Cmd_RequestQueue *pNode = requestQueue; DtSPCClose(cmdChannel); /* * Must find the node in the queue. */ for (; pNode != NULL; pNode = pNode->next) { if ( pNode->request_num == requestNum ) { /* * Pluck pNode out of the queue */ if (prev) prev->next = pNode->next; else requestQueue = pNode->next; pNode->next = NULL; break; } /* * Move alone to the next node */ prev = pNode; } if (pNode == NULL) return; /* * Check the exit status of the remote process. */ if (cause == COMMAND_CHECK_FAILURE) { if (pNode->failure_proc != NULL) { (void) sprintf (errorMessage, errorSpawn, pNode->exec_host, pNode->exec_string); if (cmd_Resources.executionHostLogging) _DtCmdLogErrorMessage (errorMessage); (*pNode->failure_proc) (errorMessage, pNode->failure_data); } FreeRequest (pNode); return; } /* * Re-queue this node -- we will execute the command */ pNode->next = requestQueue; requestQueue = pNode; ExecuteQueuedRequest (requestNum); }