/* This is to handle HTTP GET request -- La Cam Chung & R. van Engelen */ static void HTTPGet_SendWSDL(request_rec *r, const char *path) { FILE *fd = NULL; char *file; size_t n; char *tmp; size_t size; /* GET wsdl file */ if (!path || strcmp(r->parsed_uri.query, "wsdl")) { SendErrorMessage(r, "HTTP GET: not a ?wsdl request"); return; } file = (char*)malloc(strlen(path) + 6); if (file) { strcpy(file, path); tmp = strstr(file, ".so"); if (tmp) strcpy(tmp, ".wsdl"); else strcat(file, ".wsdl"); fd = fopen(file, "rb"); free(file); } if (!fd) { SendErrorMessage(r, "Error: 404 FILE NOT FOUND"); return; } /* Calculate the size of file */ fseek(fd, 0, SEEK_END); size = ftell(fd); rewind(fd); tmp = (char*)malloc(size); if (tmp) n = fread(tmp, 1, size, fd); if (!tmp || n != size) SendErrorMessage(r, "HTTP GET error reading file"); else { r->content_type = "text/xml"; ap_rputs(tmp, r); } fclose(fd); free(tmp); return; }
void Settings::WriteDefaultsToStdConfigFile(QFile& stdConfigFile, const QString& settings) { int length = settings.length(); if (!stdConfigFile.open(QFile::WriteOnly|QFile::Text)) { SendErrorMessage("Could not open file to write " + stdConfigFile.fileName()); } else { qint64 bytes_written = stdConfigFile.write(qPrintable(settings),length); if (bytes_written != length) { SendErrorMessage("Could not write default settings to " + stdConfigFile.fileName()); if (!stdConfigFile.remove()) { SendErrorMessage("Count not remove configuration file. Please delete " + stdConfigFile.fileName()); } } stdConfigFile.close(); } }
QDir Settings::OpenConfigDirectory() { QDir config_dir(QStandardPaths::writableLocation( QStandardPaths::ConfigLocation)); if (!config_dir.exists()) { QDir dir; if (!dir.mkdir(config_dir.path())) { SendErrorMessage("Could not create configuration directory"); abort(); } } return config_dir; }
QString Settings::ReadJsonFile() { QString default_settings = ReadJsonFileFromInternalResource(); QDir config_dir = OpenConfigDirectory(); QString path = config_dir.filePath(m_filename); QFile std_file(path); if (std_file.exists()) { if (!std_file.open(QFile::ReadOnly|QFile::Text)) { SendErrorMessage("Cound not open " + path); return default_settings; } QString settings = std_file.readAll(); std_file.close(); return settings; } else { WriteDefaultsToStdConfigFile(std_file,default_settings); return default_settings; } }
/** * SOAP content handler. * * @return the value that instructs the caller concerning what happened and what to do next. * OK ("we did our thing") * DECLINED ("this isn't something with which we want to get involved") * HTTP_mumble ("an error status should be reported") */ static int gsoap_handler(request_rec * r) { static const int nResponseBufferLen = IOBUF_CHUNK_SIZE; const char *pszError = NULL; struct soap *psoap = NULL; struct apache_soap_interface *pIntf = NULL; int nRet = 0; char *pszResponse = NULL; gsoapConfiguration *pConfig = getConfiguration(r); gsoapRequestConfiguration *pRqConf = NULL; /* * only handle soap requests */ if (!strstr(r->handler, "soap")) return DECLINED; /* * only handle POST requests */ if (r->method_number != M_POST && r->method_number != M_GET) return DECLINED; pszResponse = apr_pcalloc(r->pool, nResponseBufferLen); assert(NULL != pConfig); psoap = (struct soap *)apr_pcalloc(r->pool, sizeof(struct soap)); pRqConf = apr_pcalloc(r->pool, sizeof(gsoapRequestConfiguration)); pszError = SoapSharedLibraries_loadAllLibraries(pConfig->m_pLibraries, r->pool, r); pIntf = pConfig->m_pLibraries->m_pIntf; ap_update_mtime(r, r->request_time); ap_set_last_modified(r); if (NULL != pszError) { static Bool bFirstTime = TRUE; if (bFirstTime) { ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server, "mod_gsoap: %s", pszError); bFirstTime = FALSE; } } /* * as a next step, we prepare a buffer that sends the request as first line to gsoap. * Then the remaining data. * We start returning bytes on frecv from this buffer, until it is empty. * then it is not necessary to fiddle around with gsoap's request line parsing. */ if (NULL == pszError) { pRqConf->r = r; pRqConf->headers_sent = FALSE; pRqConf->headers_received = FALSE; pRqConf->m_pszAllHeaders = NULL; pRqConf->m_nHeaderLength = strlen(r->the_request) + 2; pRqConf->m_pszCurrentHeaderReadingPosition = NULL; pRqConf->m_nOutBufCount = 0; pRqConf->m_nOutBufLength = nResponseBufferLen; pRqConf->m_pOutBuf = apr_pcalloc(r->pool, nResponseBufferLen); pRqConf->http_parse = NULL; pRqConf->m_pszAllHeaders = apr_pcalloc(r->pool, pRqConf->m_nHeaderLength + 1); pRqConf->m_pszCurrentHeaderReadingPosition = pRqConf->m_pszAllHeaders; strcpy(pRqConf->m_pszAllHeaders, r->the_request); strcat(pRqConf->m_pszAllHeaders, "\r\n"); pRqConf->pIntf = pIntf; } /* * We're about to start sending content, so we need to force the HTTP * headers to be sent at this point. Otherwise, no headers will be sent * at all. We can set any we like first, of course. **NOTE** Here's * where you set the "Content-type" header, and you do so by putting it in * r->content_type, *not* r->headers_out("Content-type"). If you don't * set it, it will be filled in with the server's default type (typically * "text/plain"). You *must* also ensure that r->content_type is lower * case. * */ /* * If we're only supposed to send header information (HEAD request), we're * already there. */ if (r->header_only) { return OK; } if (NULL != pszError) { SendErrorMessage(r, pszError); return OK; } nRet = ap_setup_client_block(r, REQUEST_CHUNKED_DECHUNK); if (OK != nRet) { SendErrorMessage(r, "Failed to start receiving POST buffer"); return OK; } nRet = ap_should_client_block(r); /* we check whether this request is HTTP GET or not and handle the GET request */ if (r->method_number == M_GET) { HTTPGet_SendWSDL(r, pConfig->m_pLibraries->m_pSOAPLibrary->m_pszPath); return OK; } if (0 == nRet) { SendErrorMessage(r, "No body received"); return OK; } if (NULL != pszError) { ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server, "mod_gsoap: %s", pszError); SendErrorMessage(r, pszError); return OK; } if (NULL != pIntf->fsoap_init) { (*pIntf->fsoap_init) (psoap, r); psoap->namespaces = pIntf->namespaces; set_callbacks(r, pRqConf, psoap); if (NULL != pIntf->fsoap_serve) { nRet = (*pIntf->fsoap_serve) (psoap, r); } else { SendErrorMessage(r, "no soap_serve entry point"); return OK; } if (NULL != pIntf->fsoap_destroy) { pIntf->fsoap_destroy(psoap, r); /* not an error in 2.1.10 anymore */ } if (NULL != pIntf->fsoap_end) { pIntf->fsoap_end(psoap, r); } else { SendErrorMessage(r, "no soap_end entry point"); } if (NULL != pIntf->fsoap_done) { pIntf->fsoap_done(psoap, r); } else { SendErrorMessage(r, "no soap_done entry point"); } } else { SendErrorMessage(r, "no soap_init entry point"); return OK; } /* * We did what we wanted to do, so tell the rest of the server we * succeeded. We need not delete pszResponse, because it was allocated from the request pool. */ return OK; }