/** * Write an RFC2965 compliant cookie. * * @param r The request * @param name2 The name of the cookie. * @param val The value to place in the cookie. * @param attrs2 The string containing additional cookie attributes. If NULL, the * DEFAULT_ATTRS will be used. * @param maxage If non zero, a Max-Age header will be added to the cookie. */ AP_DECLARE(apr_status_t) ap_cookie_write2(request_rec * r, const char *name2, const char *val, const char *attrs2, long maxage, ...) { const char *buffer; const char *rfc2965; apr_table_t *t; va_list vp; /* handle expiry */ buffer = ""; if (maxage) { buffer = apr_pstrcat(r->pool, "Max-Age=", apr_ltoa(r->pool, maxage), ";", NULL); } /* create RFC2965 compliant cookie */ rfc2965 = apr_pstrcat(r->pool, name2, "=", val, ";", buffer, attrs2 && *attrs2 ? attrs2 : DEFAULT_ATTRS, NULL); ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00008) LOG_PREFIX "user '%s' set cookie2: '%s'", r->user, rfc2965); /* write the cookie to the header table(s) provided */ va_start(vp, maxage); while ((t = va_arg(vp, apr_table_t *))) { apr_table_addn(t, SET_COOKIE2, rfc2965); } va_end(vp); return APR_SUCCESS; }
static jsonSession* jsonapiunittest_createMockJsonSession(pool*p){ char *tmp; jsonSession* jsonSess=jsonapi_newJsonSessionObj(p); apr_hash_t* tokenMap=NULL; tokenMap=apr_hash_make(p); apr_hash_set(tokenMap,JSON_TOKEN_USER,APR_HASH_KEY_STRING,"dj_chandt"); apr_hash_set(tokenMap,JSON_TOKEN_PASSWORD,APR_HASH_KEY_STRING,"password1"); apr_hash_set(tokenMap,JSON_TOKEN_UUID,APR_HASH_KEY_STRING,"dj_chandt"); apr_hash_set(tokenMap,JSON_TOKEN_TIMESTAMP,APR_HASH_KEY_STRING,apr_ltoa(p,time(NULL))); apr_hash_set(tokenMap,JSON_TOKEN_SAVE_LOGIN,APR_HASH_KEY_STRING,apr_pstrdup(p,"true")); apr_hash_set(tokenMap,JSON_TOKEN_REALM,APR_HASH_KEY_STRING,"default"); apr_hash_set(tokenMap,JSON_TOKEN_TEMPLATE,APR_HASH_KEY_STRING,"default"); jsonSess->token=astru_serializeStringMapEscapeQuote(p,tokenMap); jsonSess->profileMsg=jsonapi_newProfileMessageObj(p); tmp=apr_pstrdup(p,"success"); jsonapi_profileMessageAddEntry(p,jsonSess->profileMsg, "result",tmp); tmp=SAFEDUP(p,"dj_chandt"); jsonapi_profileMessageAddEntry(p,jsonSess->profileMsg, "username",tmp); tmp=SAFEDUP(p,"dj_chandt"); jsonapi_profileMessageAddEntry(p,jsonSess->profileMsg, "uuid", tmp); return jsonSess; }
/* Helper for svn_cl__append_tree_conflict_info_xml(). * Appends the attributes of the given VERSION to ATT_HASH. * SIDE is the content of the version tag's side="..." attribute, * currently one of "source-left" or "source-right".*/ static svn_error_t * add_conflict_version_xml(svn_stringbuf_t **pstr, const char *side, const svn_wc_conflict_version_t *version, apr_pool_t *pool) { apr_hash_t *att_hash = apr_hash_make(pool); apr_hash_set(att_hash, "side", APR_HASH_KEY_STRING, side); if (version->repos_url) apr_hash_set(att_hash, "repos-url", APR_HASH_KEY_STRING, version->repos_url); if (version->path_in_repos) apr_hash_set(att_hash, "path-in-repos", APR_HASH_KEY_STRING, version->path_in_repos); if (SVN_IS_VALID_REVNUM(version->peg_rev)) apr_hash_set(att_hash, "revision", APR_HASH_KEY_STRING, apr_ltoa(pool, version->peg_rev)); if (version->node_kind != svn_node_unknown) apr_hash_set(att_hash, "kind", APR_HASH_KEY_STRING, svn_cl__node_kind_str_xml(version->node_kind)); svn_xml_make_open_tag_hash(pstr, pool, svn_xml_self_closing, "version", att_hash); return SVN_NO_ERROR; }
svn_error_t * svn_ra_serf__create_propfind_handler(svn_ra_serf__handler_t **propfind_handler, svn_ra_serf__session_t *sess, const char *path, svn_revnum_t rev, const char *depth, const svn_ra_serf__dav_props_t *find_props, svn_ra_serf__prop_func_t prop_func, void *prop_func_baton, apr_pool_t *pool) { propfind_context_t *new_prop_ctx; svn_ra_serf__handler_t *handler; svn_ra_serf__xml_context_t *xmlctx; new_prop_ctx = apr_pcalloc(pool, sizeof(*new_prop_ctx)); new_prop_ctx->path = path; new_prop_ctx->find_props = find_props; new_prop_ctx->prop_func = prop_func; new_prop_ctx->prop_func_baton = prop_func_baton; new_prop_ctx->depth = depth; if (SVN_IS_VALID_REVNUM(rev)) { new_prop_ctx->label = apr_ltoa(pool, rev); } else { new_prop_ctx->label = NULL; } xmlctx = svn_ra_serf__xml_context_create(propfind_ttable, propfind_opened, propfind_closed, NULL, new_prop_ctx, pool); handler = svn_ra_serf__create_expat_handler(sess, xmlctx, propfind_expected_status, pool); handler->method = "PROPFIND"; handler->path = path; handler->body_delegate = create_propfind_body; handler->body_type = "text/xml"; handler->body_delegate_baton = new_prop_ctx; handler->header_delegate = setup_propfind_headers; handler->header_delegate_baton = new_prop_ctx; handler->no_dav_headers = TRUE; new_prop_ctx->handler = handler; *propfind_handler = handler; return SVN_NO_ERROR; }
/* Implements svn_ra_serf__request_body_delegate_t */ static svn_error_t * create_gls_body(serf_bucket_t **body_bkt, void *baton, serf_bucket_alloc_t *alloc, apr_pool_t *pool) { serf_bucket_t *buckets; gls_context_t *gls_ctx = baton; buckets = serf_bucket_aggregate_create(alloc); svn_ra_serf__add_open_tag_buckets(buckets, alloc, "S:get-location-segments", "xmlns:S", SVN_XML_NAMESPACE, NULL); svn_ra_serf__add_tag_buckets(buckets, "S:path", gls_ctx->path, alloc); svn_ra_serf__add_tag_buckets(buckets, "S:peg-revision", apr_ltoa(pool, gls_ctx->peg_revision), alloc); svn_ra_serf__add_tag_buckets(buckets, "S:start-revision", apr_ltoa(pool, gls_ctx->start_rev), alloc); svn_ra_serf__add_tag_buckets(buckets, "S:end-revision", apr_ltoa(pool, gls_ctx->end_rev), alloc); svn_ra_serf__add_close_tag_buckets(buckets, alloc, "S:get-location-segments"); *body_bkt = buckets; return SVN_NO_ERROR; }
/* Implements svn_ra_serf__request_body_delegate_t */ static svn_error_t * create_file_revs_body(serf_bucket_t **body_bkt, void *baton, serf_bucket_alloc_t *alloc, apr_pool_t *pool /* request pool */, apr_pool_t *scratch_pool) { serf_bucket_t *buckets; blame_context_t *blame_ctx = baton; buckets = serf_bucket_aggregate_create(alloc); svn_ra_serf__add_open_tag_buckets(buckets, alloc, "S:file-revs-report", "xmlns:S", SVN_XML_NAMESPACE, SVN_VA_NULL); svn_ra_serf__add_tag_buckets(buckets, "S:start-revision", apr_ltoa(pool, blame_ctx->start), alloc); svn_ra_serf__add_tag_buckets(buckets, "S:end-revision", apr_ltoa(pool, blame_ctx->end), alloc); if (blame_ctx->include_merged_revisions) { svn_ra_serf__add_empty_tag_buckets(buckets, alloc, "S:include-merged-revisions", SVN_VA_NULL); } svn_ra_serf__add_tag_buckets(buckets, "S:path", blame_ctx->path, alloc); svn_ra_serf__add_close_tag_buckets(buckets, alloc, "S:file-revs-report"); *body_bkt = buckets; return SVN_NO_ERROR; }
/* Implements svn_ra_serf__request_body_delegate_t */ static svn_error_t * create_get_locations_body(serf_bucket_t **body_bkt, void *baton, serf_bucket_alloc_t *alloc, apr_pool_t *pool) { serf_bucket_t *buckets; loc_context_t *loc_ctx = baton; int i; buckets = serf_bucket_aggregate_create(alloc); svn_ra_serf__add_open_tag_buckets(buckets, alloc, "S:get-locations", "xmlns:S", SVN_XML_NAMESPACE, "xmlns:D", "DAV:", NULL); svn_ra_serf__add_tag_buckets(buckets, "S:path", loc_ctx->path, alloc); svn_ra_serf__add_tag_buckets(buckets, "S:peg-revision", apr_ltoa(pool, loc_ctx->peg_revision), alloc); for (i = 0; i < loc_ctx->location_revisions->nelts; i++) { svn_revnum_t rev = APR_ARRAY_IDX(loc_ctx->location_revisions, i, svn_revnum_t); svn_ra_serf__add_tag_buckets(buckets, "S:location-revision", apr_ltoa(pool, rev), alloc); } svn_ra_serf__add_close_tag_buckets(buckets, alloc, "S:get-locations"); *body_bkt = buckets; return SVN_NO_ERROR; }
/* Implements svn_ra_serf__request_body_delegate_t */ static svn_error_t * create_getdrev_body(serf_bucket_t **body_bkt, void *baton, serf_bucket_alloc_t *alloc, apr_pool_t *pool) { serf_bucket_t *buckets; drev_context_t *drev_ctx = baton; buckets = serf_bucket_aggregate_create(alloc); svn_ra_serf__add_open_tag_buckets(buckets, alloc, "S:get-deleted-rev-report", "xmlns:S", SVN_XML_NAMESPACE, "xmlns:D", "DAV:", NULL, NULL); svn_ra_serf__add_tag_buckets(buckets, "S:path", drev_ctx->path, alloc); svn_ra_serf__add_tag_buckets(buckets, "S:peg-revision", apr_ltoa(pool, drev_ctx->peg_revision), alloc); svn_ra_serf__add_tag_buckets(buckets, "S:end-revision", apr_ltoa(pool, drev_ctx->end_revision), alloc); svn_ra_serf__add_close_tag_buckets(buckets, alloc, "S:get-deleted-rev-report"); *body_bkt = buckets; return SVN_NO_ERROR; }
/* Implements svn_ra_serf__request_body_delegate_t */ static svn_error_t * create_mergeinfo_body(serf_bucket_t **bkt, void *baton, serf_bucket_alloc_t *alloc, apr_pool_t *pool /* request pool */, apr_pool_t *scratch_pool) { mergeinfo_context_t *mergeinfo_ctx = baton; serf_bucket_t *body_bkt; body_bkt = serf_bucket_aggregate_create(alloc); svn_ra_serf__add_open_tag_buckets(body_bkt, alloc, "S:" SVN_DAV__MERGEINFO_REPORT, "xmlns:S", SVN_XML_NAMESPACE, SVN_VA_NULL); svn_ra_serf__add_tag_buckets(body_bkt, "S:" SVN_DAV__REVISION, apr_ltoa(pool, mergeinfo_ctx->revision), alloc); svn_ra_serf__add_tag_buckets(body_bkt, "S:" SVN_DAV__INHERIT, svn_inheritance_to_word(mergeinfo_ctx->inherit), alloc); if (mergeinfo_ctx->include_descendants) { svn_ra_serf__add_tag_buckets(body_bkt, "S:" SVN_DAV__INCLUDE_DESCENDANTS, "yes", alloc); } if (mergeinfo_ctx->paths) { int i; for (i = 0; i < mergeinfo_ctx->paths->nelts; i++) { const char *this_path = APR_ARRAY_IDX(mergeinfo_ctx->paths, i, const char *); svn_ra_serf__add_tag_buckets(body_bkt, "S:" SVN_DAV__PATH, this_path, alloc); } }
/* Build the node-origins index for the repository located at REPOS_PATH. */ static svn_error_t * build_index(const char *repos_path, apr_pool_t *pool) { svn_repos_t *repos; svn_fs_t *fs; svn_revnum_t youngest_rev, i; size_t slotsize; const char *progress_fmt; apr_pool_t *subpool; /* Open the repository. */ SVN_ERR(svn_repos_open3(&repos, repos_path, NULL, pool, pool)); /* Get a filesystem object. */ fs = svn_repos_fs(repos); /* Fetch the youngest revision of the repository. */ SVN_ERR(svn_fs_youngest_rev(&youngest_rev, fs, pool)); slotsize = strlen(apr_ltoa(pool, youngest_rev)); progress_fmt = apr_psprintf (pool, "[%%%" APR_SIZE_T_FMT "ld" "/%%%" APR_SIZE_T_FMT "ld] " "Found %%d new lines of history." "\n", slotsize, slotsize); /* Now, iterate over all the revisions, calling index_revision_adds(). */ subpool = svn_pool_create(pool); for (i = 0; i < youngest_rev; i++) { int count; svn_pool_clear(subpool); SVN_ERR(index_revision_adds(&count, fs, i + 1, subpool)); printf(progress_fmt, i + 1, youngest_rev, count); } svn_pool_destroy(subpool); return SVN_NO_ERROR; }
/** * Given a revision, return a string for the revision, either "HEAD" * or a string representation of the revision value. All other * revision kinds return an error. */ static svn_error_t * opt_revision_to_string(const char **str, const char *path, const svn_opt_revision_t *rev, apr_pool_t *pool) { switch (rev->kind) { case svn_opt_revision_head: *str = apr_pstrmemdup(pool, "HEAD", 4); break; case svn_opt_revision_number: *str = apr_ltoa(pool, rev->value.number); break; default: return svn_error_createf (SVN_ERR_INCORRECT_PARAMS, NULL, _("Illegal file external revision kind %d for path '%s'"), rev->kind, path); break; } return SVN_NO_ERROR; }
static void dbd_pgsql_bbind(apr_pool_t *pool, apr_dbd_prepared_t * statement, const void **values, const char **val, int *len, int *fmt) { int i, j; apr_dbd_type_e type; for (i = 0, j = 0; i < statement->nargs; i++, j++) { type = (values[j] == NULL ? APR_DBD_TYPE_NULL : statement->types[i]); switch (type) { case APR_DBD_TYPE_TINY: val[i] = apr_itoa(pool, *(char*)values[j]); break; case APR_DBD_TYPE_UTINY: val[i] = apr_itoa(pool, *(unsigned char*)values[j]); break; case APR_DBD_TYPE_SHORT: val[i] = apr_itoa(pool, *(short*)values[j]); break; case APR_DBD_TYPE_USHORT: val[i] = apr_itoa(pool, *(unsigned short*)values[j]); break; case APR_DBD_TYPE_INT: val[i] = apr_itoa(pool, *(int*)values[j]); break; case APR_DBD_TYPE_UINT: val[i] = apr_itoa(pool, *(unsigned int*)values[j]); break; case APR_DBD_TYPE_LONG: val[i] = apr_ltoa(pool, *(long*)values[j]); break; case APR_DBD_TYPE_ULONG: val[i] = apr_ltoa(pool, *(unsigned long*)values[j]); break; case APR_DBD_TYPE_LONGLONG: val[i] = apr_psprintf(pool, "%" APR_INT64_T_FMT, *(apr_int64_t*)values[j]); break; case APR_DBD_TYPE_ULONGLONG: val[i] = apr_psprintf(pool, "%" APR_UINT64_T_FMT, *(apr_uint64_t*)values[j]); break; case APR_DBD_TYPE_FLOAT: val[i] = apr_psprintf(pool, "%f", *(float*)values[j]); break; case APR_DBD_TYPE_DOUBLE: val[i] = apr_psprintf(pool, "%lf", *(double*)values[j]); break; case APR_DBD_TYPE_STRING: case APR_DBD_TYPE_TEXT: case APR_DBD_TYPE_TIME: case APR_DBD_TYPE_DATE: case APR_DBD_TYPE_DATETIME: case APR_DBD_TYPE_TIMESTAMP: case APR_DBD_TYPE_ZTIMESTAMP: val[i] = values[j]; break; case APR_DBD_TYPE_BLOB: case APR_DBD_TYPE_CLOB: val[i] = (char*)values[j]; len[i] = *(apr_size_t*)values[++j]; fmt[i] = 1; /* skip table and column */ j += 2; break; case APR_DBD_TYPE_NULL: default: val[i] = NULL; break; } } return; }
/* Implements svn_ra_serf__request_body_delegate_t */ static svn_error_t * create_list_body(serf_bucket_t **body_bkt, void *baton, serf_bucket_alloc_t *alloc, apr_pool_t *pool /* request pool */, apr_pool_t *scratch_pool) { serf_bucket_t *buckets; list_context_t *list_ctx = baton; int i; buckets = serf_bucket_aggregate_create(alloc); svn_ra_serf__add_open_tag_buckets(buckets, alloc, "S:list-report", "xmlns:S", SVN_XML_NAMESPACE, SVN_VA_NULL); svn_ra_serf__add_tag_buckets(buckets, "S:path", list_ctx->path, alloc); svn_ra_serf__add_tag_buckets(buckets, "S:revision", apr_ltoa(pool, list_ctx->revision), alloc); svn_ra_serf__add_tag_buckets(buckets, "S:depth", svn_depth_to_word(list_ctx->depth), alloc); if (list_ctx->patterns) { for (i = 0; i < list_ctx->patterns->nelts; i++) { char *name = APR_ARRAY_IDX(list_ctx->patterns, i, char *); svn_ra_serf__add_tag_buckets(buckets, "S:pattern", name, alloc); } if (list_ctx->patterns->nelts == 0) { svn_ra_serf__add_empty_tag_buckets(buckets, alloc, "S:no-patterns", SVN_VA_NULL); } } for (i = 0; i < list_ctx->props->nelts; i++) { const svn_ra_serf__dav_props_t *prop = &APR_ARRAY_IDX(list_ctx->props, i, const svn_ra_serf__dav_props_t); const char *name = apr_pstrcat(pool, prop->xmlns, prop->name, SVN_VA_NULL); svn_ra_serf__add_tag_buckets(buckets, "S:prop", name, alloc); } svn_ra_serf__add_close_tag_buckets(buckets, alloc, "S:list-report"); *body_bkt = buckets; return SVN_NO_ERROR; }
lt_http_status_t lt_http_server_run( lt_http_server_t * server ) { apr_pool_t * pool = NULL; apr_socket_t * client = NULL; char error[1025]; memset( error, 0, 1025 ); if( server == NULL ) return LT_HTTP_INVALID_ARG; /* prepare connection pool */ apr_pool_create( &pool, server->pool ); /* make the socket non-blocking */ if( APR_SUCCESS != apr_socket_opt_set( server->socket, APR_SO_NONBLOCK, 1 ) ) { my_perror( "ERROR: apr_socket_opt_set failed with: " ); return LT_HTTP_INVALID_ARG; } while( 1 ) { apr_status_t rv; /* bool reading should be atomic operation so no locking is needed */ if( server->stoprequested ) { break; } /* clear pool memory */ apr_pool_clear( pool ); /* accept new connection */ rv = apr_socket_accept( &client, server->socket, pool ); if( APR_STATUS_IS_EAGAIN( rv ) || APR_STATUS_IS_EINTR( rv ) ) { /* sleep for 100ms before accepting new client */ apr_sleep( 100 * 1000 ); continue; } if( APR_SUCCESS != rv ) { my_perror( "ERROR: apr_socket_accept failed with: " ); continue; } /* determine client address */ { apr_sockaddr_t * sa = NULL; char * ip = NULL; if( APR_SUCCESS != apr_socket_addr_get( &sa, APR_REMOTE, client ) ) { my_perror( "ERROR: apr_socket_addr_get failed with: " ); apr_socket_close( client ); continue; } if( APR_SUCCESS != apr_sockaddr_ip_get( &ip, sa ) ) { my_perror( "ERROR: apr_sockaddr_ip_get failed with: " ); apr_socket_close( client ); continue; } } /* immediatelly start sending HTTP response headers */ { char * headers = apr_pstrcat( pool, "HTTP/1.0 200 OK\r\n" "Content-Length: ", apr_ltoa( pool, server->finfo.size ), "\r\n", "Content-Type: application/octet-stream;" " charset=utf-8\r\n", "Connection: Close\r\n", "\r\n", NULL ); apr_size_t headers_size = strlen( headers ); if( APR_SUCCESS != apr_socket_send( client, headers, &headers_size ) ) { my_perror( "ERROR: apr_socket_send failed with: " ); apr_socket_close( client ); continue; } } /* send file contents */ { apr_off_t offset = 0; apr_size_t len = server->finfo.size; if( APR_SUCCESS != apr_socket_sendfile( client, server->file, NULL, &offset, &len, 0 ) ) { my_perror( "ERROR: apr_socket_sendfile failed with: " ); apr_socket_close( client ); continue; } } /* read and discard all headers */ { apr_status_t rv; /* set non-block option on client socket */ if( APR_SUCCESS != apr_socket_timeout_set( client, 2 * 1000 * 1000 ) ) { my_perror( "ERROR: apr_socket_timeout_set failed with: " ); apr_socket_close( client ); continue; } /* read all data until 2 sec timeout or eof, then proceed to */ /* close */ do { char buffer[1024]; apr_size_t len = 1024; rv = apr_socket_recv( client, buffer, &len ); if( APR_STATUS_IS_TIMEUP( rv ) || APR_STATUS_IS_EOF( rv ) ) { break; } } while( 1 ); } /* close our side of connection */ if( APR_SUCCESS != apr_socket_shutdown( client, APR_SHUTDOWN_WRITE ) ) { /* we actually don't care about errors arriving during shutdown * phase * my_perror( "ERROR: apr_socket_shutdown(WRITE) failed with: " ); */ apr_socket_close( client ); continue; } /* close other side of connection */ if( APR_SUCCESS != apr_socket_shutdown( client, APR_SHUTDOWN_READ ) ) { /* we actually don't care about errors arriving during shutdown * phase * my_perror( "ERROR: apr_socket_shutdown(READ) failed with: " ); */ apr_socket_close( client ); continue; } /* close socket */ if( APR_SUCCESS != apr_socket_close( client ) ) { /* we actually don't care about errors arriving during shutdown * phase * my_perror( "ERROR: apr_socket_close failed with: " ); */ continue; } } return LT_HTTP_SUCCESS; }
apr_status_t proc_spawn_process(const char *cmdline, fcgid_proc_info *procinfo, fcgid_procnode *procnode) { HANDLE *finish_event, listen_handle; SECURITY_ATTRIBUTES SecurityAttributes; fcgid_server_conf *sconf; apr_procattr_t *proc_attr; apr_status_t rv; apr_file_t *file; const char * const *proc_environ; char sock_path[FCGID_PATH_MAX]; int argc; char const * wargv[APACHE_ARG_MAX + 1], *word; /* For wrapper */ const char *tmp; /* Build wrapper args */ argc = 0; tmp = cmdline; while (1) { word = ap_getword_white(procnode->proc_pool, &tmp); if (word == NULL || *word == '\0') break; if (argc >= APACHE_ARG_MAX) break; wargv[argc++] = word; } wargv[argc] = NULL; memset(&SecurityAttributes, 0, sizeof(SecurityAttributes)); /* Prepare finish event */ finish_event = apr_palloc(procnode->proc_pool, sizeof(HANDLE)); *finish_event = CreateEvent(NULL, TRUE, FALSE, NULL); if (*finish_event == NULL || !SetHandleInformation(*finish_event, HANDLE_FLAG_INHERIT, TRUE)) { ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(), procinfo->main_server, "mod_fcgid: can't create mutex for subprocess"); return APR_ENOLOCK; } apr_pool_cleanup_register(procnode->proc_pool, finish_event, close_finish_event, apr_pool_cleanup_null); /* For proc_kill_gracefully() */ apr_pool_userdata_set(finish_event, FINISH_EVENT_DATA_NAME, NULL, procnode->proc_pool); /* Pass the finish event id to subprocess */ apr_table_setn(procinfo->proc_environ, SHUTDOWN_EVENT_NAME, apr_ltoa(procnode->proc_pool, (long) *finish_event)); /* Prepare the listen namedpipe file name (no check for truncation) */ apr_snprintf(sock_path, sizeof sock_path, "\\\\.\\pipe\\fcgidpipe-%lu.%d", GetCurrentProcessId(), g_process_counter++); /* Prepare the listen namedpipe handle */ SecurityAttributes.bInheritHandle = TRUE; SecurityAttributes.nLength = sizeof(SecurityAttributes); SecurityAttributes.lpSecurityDescriptor = NULL; listen_handle = CreateNamedPipe(sock_path, PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, 8192, 8192, 0, &SecurityAttributes); if (listen_handle == INVALID_HANDLE_VALUE) { ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(), procinfo->main_server, "mod_fcgid: can't create namedpipe for subprocess"); return APR_ENOSOCKET; } apr_cpystrn(procnode->socket_path, sock_path, sizeof(procnode->socket_path)); apr_cpystrn(procnode->executable_path, wargv[0], sizeof(procnode->executable_path)); /* Build environment variables */ proc_environ = (const char * const *) ap_create_environment(procnode->proc_pool, procinfo->proc_environ); if (!proc_environ) { ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(), procinfo->main_server, "mod_fcgid: can't build environment variables"); return APR_ENOMEM; } /* Create process now */ if ((rv = apr_procattr_create(&proc_attr, procnode->proc_pool)) != APR_SUCCESS || (rv = apr_procattr_dir_set(proc_attr, ap_make_dirstr_parent(procnode->proc_pool, wargv[0]))) != APR_SUCCESS || (rv = apr_procattr_cmdtype_set(proc_attr, APR_PROGRAM)) != APR_SUCCESS || (rv = apr_procattr_detach_set(proc_attr, 1)) != APR_SUCCESS || (rv = apr_procattr_io_set(proc_attr, APR_NO_PIPE, APR_NO_FILE, APR_NO_FILE)) != APR_SUCCESS || (rv = apr_os_file_put(&file, &listen_handle, 0, procnode->proc_pool)) != APR_SUCCESS || (rv = apr_procattr_child_in_set(proc_attr, file, NULL)) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_WARNING, rv, procinfo->main_server, "mod_fcgid: can't create FastCGI process attribute"); CloseHandle(listen_handle); return APR_ENOPROC; } /* fork and exec now */ rv = apr_proc_create(&(procnode->proc_id), wargv[0], wargv, proc_environ, proc_attr, procnode->proc_pool); /* OK, I created the process, now put it back to idle list */ CloseHandle(listen_handle); if (rv != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_ERR, rv, procinfo->main_server, "mod_fcgid: can't run %s", wargv[0]); return rv; } /* FcgidWin32PreventOrphans feature */ sconf = ap_get_module_config(procinfo->main_server->module_config, &fcgid_module); if (sconf->hJobObjectForAutoCleanup != NULL) { /* Associate cgi process to current process */ if (AssignProcessToJobObject(sconf->hJobObjectForAutoCleanup, procnode->proc_id.hproc) == 0) { ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(), procinfo->main_server, "mod_fcgid: unable to assign child process to " "job object"); } } return APR_SUCCESS; }
int slayer_server_log_request(slayer_server_log_manager_t *manager, apr_pool_t *mpool, apr_socket_t *conn, const char *request_line, int response_code, int nbytes_sent, apr_int64_t time_toservice) { //generate data char dstring[1024]; apr_int64_t current_time = apr_time_now(); apr_size_t result_size; apr_time_exp_t ltime; apr_time_exp_lt(<ime,current_time); apr_strftime (dstring, &result_size, sizeof(dstring), "%d/%b/%Y:%H:%M:%S %z", <ime ); apr_sockaddr_t *client_addr; char *client_ip; apr_socket_addr_get(&client_addr,0,conn); apr_sockaddr_ip_get(&client_ip,client_addr); if (manager->fhandle) { char *message = apr_pstrcat(mpool,client_ip," - - ","[",dstring,"] \"",request_line,"\" ", apr_itoa(mpool,response_code)," ",apr_itoa(mpool,nbytes_sent), " ",apr_ltoa(mpool,time_toservice), "\n",NULL); slayer_server_log_message(manager,message); } slayer_server_log_add_entry(manager,mpool,client_ip,current_time,request_line,response_code,nbytes_sent,time_toservice); return 0; }
static svn_error_t * create_log_body(serf_bucket_t **body_bkt, void *baton, serf_bucket_alloc_t *alloc, apr_pool_t *pool) { serf_bucket_t *buckets; log_context_t *log_ctx = baton; buckets = serf_bucket_aggregate_create(alloc); svn_ra_serf__add_open_tag_buckets(buckets, alloc, "S:log-report", "xmlns:S", SVN_XML_NAMESPACE, NULL); svn_ra_serf__add_tag_buckets(buckets, "S:start-revision", apr_ltoa(pool, log_ctx->start), alloc); svn_ra_serf__add_tag_buckets(buckets, "S:end-revision", apr_ltoa(pool, log_ctx->end), alloc); if (log_ctx->limit) { svn_ra_serf__add_tag_buckets(buckets, "S:limit", apr_ltoa(pool, log_ctx->limit), alloc); } if (log_ctx->changed_paths) { svn_ra_serf__add_tag_buckets(buckets, "S:discover-changed-paths", NULL, alloc); } if (log_ctx->strict_node_history) { svn_ra_serf__add_tag_buckets(buckets, "S:strict-node-history", NULL, alloc); } if (log_ctx->include_merged_revisions) { svn_ra_serf__add_tag_buckets(buckets, "S:include-merged-revisions", NULL, alloc); } if (log_ctx->revprops) { int i; for (i = 0; i < log_ctx->revprops->nelts; i++) { char *name = APR_ARRAY_IDX(log_ctx->revprops, i, char *); svn_ra_serf__add_tag_buckets(buckets, "S:revprop", name, alloc); } if (log_ctx->revprops->nelts == 0) { svn_ra_serf__add_tag_buckets(buckets, "S:no-revprops", NULL, alloc); } }
svn_error_t * svn_ra_serf__get_location_segments(svn_ra_session_t *ra_session, const char *path, svn_revnum_t peg_revision, svn_revnum_t start_rev, svn_revnum_t end_rev, svn_location_segment_receiver_t receiver, void *receiver_baton, apr_pool_t *pool) { gls_context_t *gls_ctx; svn_ra_serf__session_t *session = ra_session->priv; svn_ra_serf__handler_t *handler; svn_ra_serf__xml_parser_t *parser_ctx; serf_bucket_t *buckets; const char *relative_url, *basecoll_url, *req_url; svn_error_t *err; gls_ctx = apr_pcalloc(pool, sizeof(*gls_ctx)); gls_ctx->receiver = receiver; gls_ctx->receiver_baton = receiver_baton; gls_ctx->subpool = svn_pool_create(pool); gls_ctx->inside_report = FALSE; gls_ctx->error = SVN_NO_ERROR; gls_ctx->done = FALSE; buckets = serf_bucket_aggregate_create(session->bkt_alloc); svn_ra_serf__add_open_tag_buckets(buckets, session->bkt_alloc, "S:get-location-segments", "xmlns:S", SVN_XML_NAMESPACE, NULL); svn_ra_serf__add_tag_buckets(buckets, "S:path", path, session->bkt_alloc); svn_ra_serf__add_tag_buckets(buckets, "S:peg-revision", apr_ltoa(pool, peg_revision), session->bkt_alloc); svn_ra_serf__add_tag_buckets(buckets, "S:start-revision", apr_ltoa(pool, start_rev), session->bkt_alloc); svn_ra_serf__add_tag_buckets(buckets, "S:end-revision", apr_ltoa(pool, end_rev), session->bkt_alloc); svn_ra_serf__add_close_tag_buckets(buckets, session->bkt_alloc, "S:get-location-segments"); SVN_ERR(svn_ra_serf__get_baseline_info(&basecoll_url, &relative_url, session, NULL, NULL, peg_revision, NULL, pool)); req_url = svn_path_url_add_component(basecoll_url, relative_url, pool); handler = apr_pcalloc(pool, sizeof(*handler)); handler->method = "REPORT"; handler->path = req_url; handler->body_buckets = buckets; handler->body_type = "text/xml"; handler->conn = session->conns[0]; handler->session = session; parser_ctx = apr_pcalloc(pool, sizeof(*parser_ctx)); parser_ctx->pool = pool; parser_ctx->user_data = gls_ctx; parser_ctx->start = start_gls; parser_ctx->end = end_gls; parser_ctx->status_code = &gls_ctx->status_code; parser_ctx->done = &gls_ctx->done; handler->response_handler = svn_ra_serf__handle_xml_parser; handler->response_baton = parser_ctx; svn_ra_serf__request_create(handler); err = svn_ra_serf__context_run_wait(&gls_ctx->done, session, pool); if (gls_ctx->error || parser_ctx->error) { svn_error_clear(err); err = SVN_NO_ERROR; SVN_ERR(gls_ctx->error); SVN_ERR(parser_ctx->error); } if (gls_ctx->inside_report) err = svn_error_createf(SVN_ERR_RA_DAV_REQUEST_FAILED, NULL, _("Location segment report failed on '%s'@'%ld'"), path, peg_revision); SVN_ERR(svn_ra_serf__error_on_status(gls_ctx->status_code, handler->path)); svn_pool_destroy(gls_ctx->subpool); if (err && (err->apr_err == SVN_ERR_UNSUPPORTED_FEATURE)) return svn_error_create(SVN_ERR_RA_NOT_IMPLEMENTED, err, NULL); return err; }