static void httpServerCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer) { if (message->method != SOUP_METHOD_GET) { soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED); return; } if (g_str_equal(path, "/test-script")) { GOwnPtr<char> pathToFile(g_build_filename(Test::getResourcesDir().data(), "link-title.js", NULL)); char* contents; gsize length; g_file_get_contents(pathToFile.get(), &contents, &length, 0); soup_message_body_append(message->response_body, SOUP_MEMORY_TAKE, contents, length); soup_message_set_status(message, SOUP_STATUS_OK); soup_message_body_complete(message->response_body); } else if (g_str_equal(path, "/test-image")) { GOwnPtr<char> pathToFile(g_build_filename(Test::getWebKit1TestResoucesDir().data(), "blank.ico", NULL)); char* contents; gsize length; g_file_get_contents(pathToFile.get(), &contents, &length, 0); soup_message_body_append(message->response_body, SOUP_MEMORY_TAKE, contents, length); soup_message_set_status(message, SOUP_STATUS_OK); soup_message_body_complete(message->response_body); } else soup_message_set_status(message, SOUP_STATUS_NOT_FOUND); }
int main(int argc, char **argv) { std::string pathToExe = pathToFile(argv[0]); std::string exeName = last(split(argv[0], '/')); MySQLWorker mysql; mysql.connect("192.168.10.101", "root", "123", "blogDB"); orm::Database db(&mysql); db.registerModel<BlogPost>(); if(argc > 1){ std::cout << "Migrate" << std::endl; db.createScheme(); return 0; } cgi::RequestHandler request; cgi::ResponseHandler response; cgi::RequestArgs args = request.getArgs(); cgi::RequestArgs cont; cont["STATIC_PATH"] = exeName + "?staticfile="; if (args.count("staticfile")){ std::string reqFile = args["staticfile"]; std::string res = readFile(std::string("../static/") + reqFile); if(getExtensionOfFileByPath(reqFile) == "js") response.mimeType = "text/javascript"; response << res; }else{ response << cgi::TemplateEngine::renderTemplate(readFile(pathToExe + "../templates/blogindex.html"), cont).getValue(); } response.send(); return 1; }
int CLuaSoundEngine::Play( lua_State* L ) { int argc = lua_gettop(L); luaL_argcheck(L, argc == 2, 2, "Function CLuaSoundEngine:Play need path to file" ); NrpText pathToFile( lua_tostring( L, 2 ) ); IF_OBJECT_NOT_NULL_THEN { _object->Play( "", pathToFile, false ); } return 0; }
int main(int argc, char *argv[]) { int returnCode = 0; struct args *all; char *msg = malloc(sizeof(char)*80); FILE *log; all = optproc(argc, argv); // This extracts our options struct fileAndLen *histFile = malloc(sizeof(struct fileAndLen)); histFile->file = fopen(all->file, "r"); histFile->length = countLines(histFile->file); int n; char *line = malloc(sizeof(int)*100); char *nudderline; char *logFilePath; char *logFile; int cmdCode = cmdproc(argc, argv); switch(cmdCode) { case 0: fprintf(stderr, "Error incorrect arguments. Usage: lumber command options\n"); returnCode = ARGUMENT_ERROR; break; case 1: // 1 for a create statement logFile = strcat(argv[2],".lumb"); logFilePath = pathToFile(logDirectory,argv[2]); if (access(logFilePath, F_OK) != -1) { fprintf(stderr, "ERROR: log \"%s\" already exists\n", argv[2]); returnCode = LOG_EXISTS_ERROR; } log = fopen(logFilePath, "w"); if (!log) { fprintf(stderr, "ERROR: file could not be opened\n"); returnCode = FILE_ERROR; } break; case 2: // 2 for a switch statement logFile = strcat(argv[2],".lumb"); logFilePath = pathToFile(logDirectory, argv[2]); if (access(logFilePath, F_OK) == -1) { fprintf(stderr, "ERROR: log \"%s\" does not exist\n", argv[2]); return INVALID_LOG_ERROR; } log = fopen(logFilePath, "r"); if (!log) { fprintf(stderr, "ERROR: file could not be opened\n"); returnCode = FILE_ERROR; break; } else { // This line is supposed to get the bottom line line = getNthLineFromBottom(log, line, 0); // This line gets the identifier from that line line = getIdentifierFromLine(line); all->lines = histFile->length - getLineNumberWithIdent(histFile->file, line); fclose(log); } log = fopen(logFilePath, "a"); strcat(msg,"switch lumber"); printf("%s\n",msg); returnCode = sendMessage(msg); if (returnCode != 0) fprintf(stderr, "Connection Error: check lumberd is running \n\t Error Code: %d\n", returnCode); break; case 3: returnCode = sendMessage("kill"); if (returnCode != 0) // Maybe build in the ability to start lumberd from here if not running fprintf(stderr, "Connection Error: check lumberd is running \n\t Error Code: %d\n", returnCode); break; } if ((cmdCode == 1 || cmdCode == 2) && returnCode == 0) { for (n = all->lines;n >= 0; n--) { // This component takes the last n lines fprintf(log, "%s\n", getNthLine(histFile->file, line, histFile->length - n)); // from the history file and enters it into the } // log file } return returnCode; }