예제 #1
0
파일: netconf.c 프로젝트: mingodad/citadel
/*
 * modify an existing node
 */
void display_edit_node(void)
{
	WCTemplputParams SubTP;
	HashList *NodeConfig;
	const StrBuf *Index;
	void *vNode;
	const StrBuf *Tmpl;

	Index = sbstr("index");
	if (Index == NULL) {
		AppendImportantMessage(_("Invalid Parameter"), -1);
		url_do_template();
		return;
	}

	NodeConfig = load_netconf(NULL, &NoCtx);
	if (!GetHash(NodeConfig, ChrPtr(Index), StrLength(Index), &vNode) || 
	    (vNode == NULL)) {
		AppendImportantMessage(_("Invalid Parameter"), -1);
		url_do_template();
		DeleteHash(&NodeConfig);
		return;
	}
	StackContext(NULL, &SubTP, vNode, CTX_NODECONF, 0, NULL);
	{
		begin_burst();
		Tmpl = sbstr("template");
		output_headers(1, 0, 0, 0, 1, 0);
		DoTemplate(SKEY(Tmpl), NULL, &SubTP);
		end_burst();
	}
	UnStackContext(&SubTP);
	DeleteHash(&NodeConfig);
	
}
예제 #2
0
		bool OutputFile::output(GeneratorContext * generator_context)
		{
			auto file = file_name_;
			if (path_.size() > 0)
			{
				file = path_ + "/" + file;
			}
			auto f = generator_context->Open(file);
			if (f == nullptr)
			{
				return false;
			}

			stream_ = f;
			output_header_comment();
			output_pre_headers();
			output_headers();
			output_after_headers();
			output_begin_namespace();

			increment_tab();
			output_type();
			decrement_tab();

			output_end_namespace();
			output_after_end_namespace();

			return true;
		}
예제 #3
0
/*
** Output the initialisation program for a Mercury executable, the *_init.erl
** file.
*/
static int
output_init_program(void)
{
    int filenum;
    int num_bunches;
    int i;

    do_path_search(files, num_files);
    output_headers();

    for (filenum = 0; filenum < num_files; filenum++) {
        process_file(files[filenum]);
    }

    fputs("\n", stdout);
    fputs("-module('", stdout);
    /* Make some effort at printing weird module names. */
    for (i = 0; module_name[i] != '\0'; i++) {
        switch (module_name[i]) {
            case '\'':
            case '\\':
                fputc('\\', stdout);
        }
        fputc(module_name[i], stdout);
    }
    fputs("').\n", stdout);
    fputs("-compile(export_all).\n\n", stdout);

    output_init_function(PURPOSE_INIT,
        std_modules, std_module_next);

    output_init_function(PURPOSE_REQ_INIT,
        req_init_modules, req_init_module_next);

    output_init_function(PURPOSE_REQ_FINAL,
        req_final_modules, req_final_module_next);

    printf("init_env_vars() -> \n");
    for (i = 0; i < mercury_env_var_next; i++) {
        /* The environment variable is passed as a string, not a binary. */
        printf("\t'ML_erlang_global_server' ! {init_env_var, \"%s\"},\n",
            mercury_env_vars[i]);
    }
    printf("\tvoid.\n");

    if (num_errors > 0) {
        fputs("% Force syntax error, since there were\n", stdout);
        fputs("% errors in the generation of this file\n", stdout);
        fputs("#error \"You need to remake this file\"\n", stdout);
        if (output_file_name != NULL) {
            (void) fclose(stdout);
            (void) remove(output_file_name);
        }
        return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;
}
예제 #4
0
/*
 * Entry point for RSS feed generator
 */
void feed_rss(void) {
	char buf[1024];

	output_headers(0, 0, 0, 0, 1, 0);
	hprintf("Content-type: text/xml; charset=utf-8\r\n");
	hprintf(
		"Server: %s / %s\r\n"
		"Connection: close\r\n"
	,
		PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software)
	);
	begin_burst();

	wc_printf("<?xml version=\"1.0\"?>"
		"<rss version=\"2.0\">"
		"<channel>"
	);

	wc_printf("<title>");
	escputs(ChrPtr(WC->CurRoom.name));
	wc_printf("</title>");

	wc_printf("<link>");
	escputs(ChrPtr(site_prefix));
	wc_printf("/</link>");

	serv_puts("RINF");
	serv_getln(buf, sizeof buf);
	if (buf[0] == '1') {
		wc_printf("<description>\r\n");
		while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
			escputs(buf);
			wc_printf("\r\n");
		}
		wc_printf("</description>");
	}

	wc_printf("<image><title>");
	escputs(ChrPtr(WC->CurRoom.name));
	wc_printf("</title><url>");
	escputs(ChrPtr(site_prefix));
	wc_printf("/roompic?room=");
	urlescputs(ChrPtr(WC->CurRoom.name));
	wc_printf("</url><link>");
	escputs(ChrPtr(site_prefix));
	wc_printf("/</link></image>\r\n");

	feed_rss_do_room_info_as_description();
	feed_rss_do_messages();

	wc_printf("</channel>"
		"</rss>"
		"\r\n\r\n"
	);

	wDumpContent(0);
}
예제 #5
0
파일: webcit.c 프로젝트: henri14/citadel
/*
 * Convenience functions to display a page containing only a string
 *
 * titlebarcolor	color of the titlebar of the frame
 * titlebarmsg		text to display in the title bar
 * messagetext		body of the box
 */
void convenience_page(const char *titlebarcolor, const char *titlebarmsg, const char *messagetext)
{
	hprintf("HTTP/1.1 200 OK\n");
	output_headers(1, 1, 1, 0, 0, 0);
	wc_printf("<div id=\"room_banner_override\">\n");
	wc_printf("<table width=100%% border=0 bgcolor=\"#%s\"><tr><td>", titlebarcolor);
	wc_printf("<span class=\"titlebar\">%s</span>\n", titlebarmsg);
	wc_printf("</td></tr></table>\n");
	wc_printf("</div>\n<div id=\"content\">\n");
	escputs(messagetext);
	wc_printf("<hr />\n");
	wDumpContent(1);
}
예제 #6
0
파일: webcit.c 프로젝트: henri14/citadel
/*
 * Convenience functions to wrap around asynchronous ajax responses
 */
void begin_ajax_response(void) {
	wcsession *WCC = WC;

	FlushStrBuf(WCC->HBuf);
	output_headers(0, 0, 0, 0, 0, 0);

	hprintf("Content-type: text/html; charset=UTF-8\r\n"
		"Server: %s\r\n"
		"Connection: close\r\n"
		,
		PACKAGE_STRING);
	begin_burst();
}
예제 #7
0
파일: wiki.c 프로젝트: henri14/citadel
/*
 * Display a specific page from a wiki room
 */
void display_wiki_page(void)
{
	char pagename[128];
	char rev[128];
	int do_revert = 0;

	output_headers(1, 1, 1, 0, 0, 0);
	safestrncpy(pagename, bstr("page"), sizeof pagename);
	str_wiki_index(pagename);
	safestrncpy(rev, bstr("rev"), sizeof rev);
	do_revert = atoi(bstr("revert"));
	display_wiki_page_backend(pagename, rev, do_revert);
	wDumpContent(1);
}
예제 #8
0
파일: mod_psgi.c 프로젝트: mattn/mod_psgi
static int output_response(request_rec *r, SV *res)
{
    dTHX;
    AV *res_av;
    SV **status;
    SV **headers;
    AV *headers_av;
    SV **body;
    int rc;

    if (!SvROK(res) || SvTYPE(SvRV(res)) != SVt_PVAV) {
        server_error(r, "response must be an array reference");
        return HTTP_INTERNAL_SERVER_ERROR;
    }
    res_av = (AV *) SvRV(res);
    if (av_len(res_av) != 2) {
        server_error(r, "response must have 3 elements");
        return HTTP_INTERNAL_SERVER_ERROR;
    }

    status = av_fetch(res_av, 0, 0);
    if (!SvOK(*status)) {
        server_error(r, "response status must be a scalar value");
        return HTTP_INTERNAL_SERVER_ERROR;
    }
    rc = output_status(r, *status);
    if (rc != OK) return rc;

    headers = av_fetch(res_av, 1, 0);
    if (!SvROK(*headers) || SvTYPE(SvRV(*headers)) != SVt_PVAV) {
        server_error(r, "response headers must be an array reference");
        return HTTP_INTERNAL_SERVER_ERROR;
    }
    headers_av = (AV *) SvRV(*headers);
    if ((av_len(headers_av) + 1) % 2 != 0) {
        server_error(r, "num of response headers must be even");
        return HTTP_INTERNAL_SERVER_ERROR;
    }
    rc = output_headers(r, headers_av);
    if (rc != OK) return rc;

    body = av_fetch(res_av, 2, 0);
    if (!SvROK(*body)) {
        server_error(r, "response body must be a reference");
        return HTTP_INTERNAL_SERVER_ERROR;
    }
    rc = output_body(r, *body);

    return rc;
}
예제 #9
0
파일: webcit.c 프로젝트: henri14/citadel
/*
 * Output a piece of content to the web browser using conformant HTTP and MIME semantics.
 *
 * If this function is called, it is expected that begin_burst() has already been called
 * and some sort of content has been fed into the buffer.  This function will transmit a
 * bunch of headers to the client.  end_burst() will add some headers of its own, and then
 * transmit the buffered content to the client.
 */
void http_transmit_thing(const char *content_type, int is_static)
{
	if (verbose)
		syslog(LOG_DEBUG, "http_transmit_thing(%s)%s", content_type, ((is_static > 0) ? " (static)" : ""));
	output_headers(0, 0, 0, 0, 0, is_static);

	hprintf("Content-type: %s\r\n"
		"Server: %s\r\n"
		"Connection: close\r\n",
		content_type,
		PACKAGE_STRING);

	end_burst();
}
예제 #10
0
파일: openid.c 프로젝트: mingodad/citadel
/*
 * Display the OpenIDs associated with an account
 */
void display_openids(void)
{
	wcsession *WCC = WC;
	char buf[1024];
	int bg = 0;

	output_headers(1, 1, 1, 0, 0, 0);

	do_template("box_begin_1");
	StrBufAppendBufPlain(WCC->WBuf, _("Manage Account/OpenID Associations"), -1, 0);
	do_template("box_begin_2");

	if (WCC->serv_info->serv_supports_openid) {

		wc_printf("<table class=\"altern\">");
	
		serv_puts("OIDL");
		serv_getln(buf, sizeof buf);
		if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
			bg = 1 - bg;
			wc_printf("<tr class=\"%s\">", (bg ? "even" : "odd"));
			wc_printf("<td><img src=\"static/webcit_icons/openid-small.gif\"></td><td>");
			escputs(buf);
			wc_printf("</td><td>");
			wc_printf("<a href=\"openid_detach?id_to_detach=");
			urlescputs(buf);
			wc_printf("\" onClick=\"return confirm('%s');\">",
				_("Do you really want to delete this OpenID?"));
			wc_printf("%s</a>", _("(delete)"));
			wc_printf("</td></tr>\n");
		}
	
		wc_printf("</table><br>\n");
	
	        wc_printf("<form method=\"POST\" action=\"openid_attach\">\n");
		wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WCC->nonce);
		wc_printf(_("Add an OpenID: "));
	        wc_printf("<input type=\"text\" name=\"openid_url\" class=\"openid_urlarea\" size=\"40\">\n");
	        wc_printf("<input type=\"submit\" name=\"attach_button\" value=\"%s\">"
			"</form></center>\n", _("Attach"));
	}

	else {
		wc_printf(_("%s does not permit authentication via OpenID."), ChrPtr(WCC->serv_info->serv_humannode));
	}

	do_template("box_end");
	wDumpContent(2);
}
예제 #11
0
파일: roomchat.c 프로젝트: mingodad/citadel
/*
 * Display the screen containing multiuser chat for a room.
 */
void do_chat(void)
{
	char buf[256];

	WC->last_chat_seq = 0;
	WC->last_chat_user[0] = 0;

	output_headers(1, 1, 1, 0, 0, 0);
	do_template("roomchat");

	serv_puts("RCHT enter");
	serv_getln(buf, sizeof buf);

	wDumpContent(1);
}
예제 #12
0
파일: pstar_io.cpp 프로젝트: P-star/P-star
void pstar_io::write_immortal(const char *str, int len) {
	if (!headers_sent) {
		output_headers();
	}
	apr_status_t rv;
	apr_bucket *b;

	b = apr_bucket_immortal_create (str, len, ba);
	APR_BRIGADE_INSERT_TAIL(bb, b);

	if (waiting_buckets++ % 100 == 0) {
		rv = ap_pass_brigade(r->output_filters, bb);
		if (rv != APR_SUCCESS) {
			throw runtime_error("pstar_io::write(); Could not write to client");
		}
		apr_brigade_cleanup(bb);
	}
}
예제 #13
0
void output(
	const std::string& filename,
	const std::string& rowname, int rowmin, int rowmax,
	const std::string& colname, int colmin, int colmax,
	Args... args
){
	std::ofstream file(filename.c_str());
	file<<rowname<<"\t"<<colname<<"\t";
	output_headers(file,args...);
	file<<std::endl;

	for(int row=rowmin; row<=rowmax; row++){
		for(int col=colmin; col<=colmax; col++){
			file<<row<<"\t"<<col<<"\t";
			output_values(file,row,col,args...);
			file<<std::endl;
		}
	}
}
예제 #14
0
void display_graphics_upload(char *filename)
{
	StrBuf *Line;

	Line = NewStrBuf();
	serv_printf("UIMG 0||%s", filename);
	StrBuf_ServGetln(Line);
	if (GetServerStatusMsg(Line, NULL, 1, 2) != 2) {
		display_main_menu();
		return;
	}
	else
	{
		output_headers(1, 0, 0, 0, 1, 0);
		do_template("files_graphicsupload");
		end_burst();
	}
	FreeStrBuf(&Line);
}
예제 #15
0
파일: webcit.c 프로젝트: henri14/citadel
void http_transmit_headers(const char *content_type, int is_static, long is_chunked, int is_gzip)
{
	wcsession *WCC = WC;
	if (verbose)
		syslog(LOG_DEBUG, "http_transmit_thing(%s)%s", content_type, ((is_static > 0) ? " (static)" : ""));
	output_headers(0, 0, 0, 0, 0, is_static);

	if (is_gzip)
		hprintf("Content-encoding: gzip\r\n");

	if (WCC->Hdr->HaveRange)
		hprintf("Accept-Ranges: bytes\r\n"
			"Content-Range: bytes %ld-%ld/%ld\r\n",
			WCC->Hdr->RangeStart,
			WCC->Hdr->RangeTil,
			WCC->Hdr->TotalBytes);

	hprintf("Content-type: %s\r\n"
		"Server: "PACKAGE_STRING"\r\n"
		"%s"
		"Connection: close\r\n\r\n",
		content_type,
		(is_chunked)?"Transfer-Encoding: chunked\r\n":"");
}
예제 #16
0
파일: webcit.c 프로젝트: henri14/citadel
/*
 * Display a blank page.
 */
void blank_page(void) {
	output_headers(1, 1, 0, 0, 0, 0);
	wDumpContent(2);
}
예제 #17
0
void output_headers(std::ofstream& file,const std::string& header,const Any& ignore,Args... args){
	output_headers(file,header,ignore);
	file<<"\t";
	output_headers(file,args...);
}
예제 #18
0
파일: mkinit.c 프로젝트: DeadZen/mercury
/*
** Output the initialisation program for a Mercury executable, the *_init.c
** file.
*/
static int
output_init_program(void)
{
    int filenum;
    int num_bunches;
    int i;

    do_path_search(files, num_files);
    output_headers();

    for (filenum = 0; filenum < num_files; filenum++) {
        process_file(files[filenum]);
    }

    printf("\n");
    for (i = 0; i < mercury_env_var_next; i++) {
        printf("MR_Word %s%s = 0;\n", envvar_prefix, mercury_env_vars[i]);
    }

    if (need_initialization_code) {
        printf("#define MR_MAY_NEED_INITIALIZATION\n\n");
    }

    std_and_special_modules = MR_NEW_ARRAY(const char *,
        std_module_next + special_module_next);

    for (i = 0; i < std_module_next; i++) {
        std_and_special_modules[i] = std_modules[i];
    }

    for (i = 0; i < special_module_next; i++) {
        std_and_special_modules[std_module_next + i] = special_modules[i];
    }

    num_bunches = output_sub_init_functions(PURPOSE_INIT,
        std_and_special_modules, std_module_next + special_module_next);
    output_main_init_function(PURPOSE_INIT, num_bunches);

    num_bunches = output_sub_init_functions(PURPOSE_TYPE_TABLE,
        std_and_special_modules, std_module_next + special_module_next);
    output_main_init_function(PURPOSE_TYPE_TABLE, num_bunches);

    num_bunches = output_sub_init_functions(PURPOSE_DEBUGGER,
        std_modules, std_module_next);
    output_main_init_function(PURPOSE_DEBUGGER, num_bunches);

    num_bunches = output_sub_init_functions(PURPOSE_COMPLEXITY,
        std_modules, std_module_next);
    output_main_init_function(PURPOSE_COMPLEXITY, num_bunches);

    num_bunches = output_sub_init_functions(PURPOSE_PROC_STATIC,
        std_and_special_modules, std_module_next + special_module_next);
    output_main_init_function(PURPOSE_PROC_STATIC, num_bunches);

    num_bunches = output_sub_init_functions(PURPOSE_THREADSCOPE_STRING_TABLE,
        std_modules, std_module_next);
    output_main_init_function(PURPOSE_THREADSCOPE_STRING_TABLE, num_bunches);

    num_bunches = output_sub_init_functions(PURPOSE_REQ_INIT,
        req_init_modules, req_init_module_next);
    output_main_init_function(PURPOSE_REQ_INIT, num_bunches);

    num_bunches = output_sub_init_functions(PURPOSE_REQ_FINAL,
        req_final_modules, req_final_module_next);
    output_main_init_function(PURPOSE_REQ_FINAL, num_bunches);

    output_main();

    if (num_errors > 0) {
        fputs("/* Force syntax error, since there were */\n", stdout);
        fputs("/* errors in the generation of this file */\n", stdout);
        fputs("#error \"You need to remake this file\"\n", stdout);
        if (output_file_name != NULL) {
            (void) fclose(stdout);
            (void) remove(output_file_name);
        }
        return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;
}
예제 #19
0
int lsp::io_def_write(void* ctx,const char* s,size_t len) {
	REQBAG *bag = (REQBAG*)ctx;
	
	output_headers(bag);
	return FCGX_PutStr(s, len, bag->out); 
}
예제 #20
0
int lsp::io_def_putc(void* ctx,int c) {
	REQBAG *bag = (REQBAG*)ctx;
	
	output_headers(bag);
	return FCGX_PutChar(c, bag->out);
}
예제 #21
0
int lsp::io_def_puts(void* ctx,const char* s) { 
	REQBAG *bag = (REQBAG*)ctx;
	
	output_headers(bag);
	return FCGX_PutS(s, bag->out); 
}
예제 #22
0
void display_pushemail(void) 
{
	folder Room;
	int Done = 0;
	StrBuf *Buf;
	long vector[8] = {8, 0, 0, 1, 2, 3, 4, 5};
	WCTemplputParams SubTP;
	char mobnum[20];

	StackContext(NULL, &SubTP, &vector, CTX_LONGVECTOR, 0, NULL);
	vector[0] = 16;

	/* Find any existing settings*/
	Buf = NewStrBuf();
	memset(&Room, 0, sizeof(folder));
	if (goto_config_room(Buf, &Room) == 0) {
		int msgnum = 0;
		serv_puts("MSGS ALL|0|1");
		StrBuf_ServGetln(Buf);
		if (GetServerStatus(Buf, NULL) == 8) {
			serv_puts("subj|__ Push email settings __");
			serv_puts("000");
			while (!Done &&
			       StrBuf_ServGetln(Buf) >= 0) {
				if ( (StrLength(Buf)==3) && 
				     !strcmp(ChrPtr(Buf), "000")) {
					Done = 1;
					break;
				}
				msgnum = StrTol(Buf);
			}
		}
		if (msgnum > 0L) {
		serv_printf("MSG0 %d", msgnum);
		StrBuf_ServGetln(Buf);
		if (GetServerStatus(Buf, NULL) == 1) {
			int i =0;
			Done = 0;
			while (!Done &&
			       StrBuf_ServGetln(Buf) >= 0) {
				if (( (StrLength(Buf)==3) && 
				      !strcmp(ChrPtr(Buf), "000"))||
				    ((StrLength(Buf)==4) && 
				     !strcmp(ChrPtr(Buf), "text")))
				{
					Done = 1;
					break;
				}
			}
			if (!strcmp(ChrPtr(Buf), "text")) {
				Done = 0;
				while (!Done &&
				       StrBuf_ServGetln(Buf) >= 0) {
					if ( (StrLength(Buf)==3) && 
					     !strcmp(ChrPtr(Buf), "000")) {
						Done = 1;
						break;
					}
					if (strncasecmp(ChrPtr(Buf), "none", 4) == 0) {
						vector[1] = 0;
					} else if (strncasecmp(ChrPtr(Buf), "textmessage", 11) == 0) {
						vector[1] = 1;
						i++;
					} else if (strncasecmp(ChrPtr(Buf), "funambol", 8) == 0) {
						vector[1] = 2;
					} else if (strncasecmp(ChrPtr(Buf), "httpmessage", 12) == 0) {
						vector[1] = 3;
					} else if (i == 1) {
						strncpy(mobnum, ChrPtr(Buf), 20);
						i++;
					}
				}	
			}
		}
		}
		serv_printf("GOTO %s", ChrPtr(WC->CurRoom.name));
		StrBuf_ServGetln(Buf);
		GetServerStatus(Buf, NULL);
	}
	FlushFolder(&Room);
	output_headers(1, 1, 1, 0, 0, 0);
	DoTemplate(HKEY("prefs_pushemail"), NULL, &SubTP);
	wDumpContent(1);
	UnStackContext(&SubTP);
	FreeStrBuf(&Buf);
}
예제 #23
0
int
mz_sendmail_send_password_mail (const char   *command_path,
                                const char   *from,
                                const char   *recipient,
                                const char   *body,
                                unsigned int  body_length,
                                const char   *boundary,
                                const char   *password,
                                int           timeout)
{
    pid_t pid;
    int stdout_pipe[2];
    int stderr_pipe[2];
    int stdin_pipe[2];

    if (pipe(stdout_pipe) < 0 ||
        pipe(stderr_pipe) < 0 ||
        pipe(stdin_pipe) < 0) {
        return -1;
    }

    pid = fork();
    if (pid == -1)
        return -1;

    if (pid == 0) {
        close_pipe(stdout_pipe, READ);
        close_pipe(stderr_pipe, READ);
        close_pipe(stdin_pipe, WRITE);

        if (sane_dup2(stdin_pipe[READ], STDIN_FILENO) < 0 ||
            sane_dup2(stdout_pipe[WRITE], STDOUT_FILENO) < 0 ||
            sane_dup2(stderr_pipe[WRITE], STDERR_FILENO) < 0) {
        }

        if (stdin_pipe[READ] >= 3)
            close_pipe(stdin_pipe, READ);
        if (stdout_pipe[WRITE] >= 3)
            close_pipe(stdout_pipe, WRITE);
        if (stderr_pipe[WRITE] >= 3)
            close_pipe(stderr_pipe, WRITE);

        execl(command_path, command_path, recipient, (char*)NULL);
        _exit(-1);
    } else {
        int status;

        close_pipe(stdout_pipe, WRITE);
        close_pipe(stderr_pipe, WRITE);
        close_pipe(stdin_pipe, READ);

        output_headers(stdin_pipe[WRITE], from, recipient, boundary);
        output_password(stdin_pipe[WRITE], password, boundary);
        output_body(stdin_pipe[WRITE], body, body_length);

        while (waitpid(pid, &status, WNOHANG) <= 0);
  
        return status;
    }

    return 0;
}
예제 #24
0
파일: pass2.c 프로젝트: bihai/xchain
/*
 * pass2() creates the output file and the memory buffer to create the file
 * into.  It drives the process to get everything copied into the buffer for
 * the output file.  It then writes the output file and deallocates the buffer.
 */ 
extern
void
pass2(void)
{
    unsigned long i, j, section_type;
    struct object_list *object_list, **p;
#ifndef RLD
    int mode;
    struct stat stat_buf;
    kern_return_t r;

	/*
	 * In UNIX standard conformance mode we are not allowed to replace
	 * a file that is not writeable.
	 */
	if(get_unix_standard_mode() == TRUE && 
	   access(outputfile, F_OK) == 0 &&
	   access(outputfile, W_OK) == -1)
	    system_fatal("can't write output file: %s", outputfile);

	/*
	 * Create the output file.  The unlink() is done to handle the problem
	 * when the outputfile is not writable but the directory allows the
	 * file to be removed (since the file may not be there the return code
	 * of the unlink() is ignored).
	 */
	(void)unlink(outputfile);
	if((fd = open(outputfile, O_WRONLY | O_CREAT | O_TRUNC, 0777)) == -1)
	    system_fatal("can't create output file: %s", outputfile);
#ifdef F_NOCACHE
        /* tell filesystem to NOT cache the file when reading or writing */
	(void)fcntl(fd, F_NOCACHE, 1);
#endif
	if(fstat(fd, &stat_buf) == -1)
	    system_fatal("can't stat file: %s", outputfile);
	/*
	 * Turn the execute bits on or off depending if there are any undefined
	 * symbols in the output file.  If the file existed before the above
	 * open() call the creation mode in that call would have been ignored
	 * so it has to be set explicitly in any case.
	 */
	if(output_mach_header.flags & MH_NOUNDEFS ||
	   (has_dynamic_linker_command && output_for_dyld))
	    mode = (stat_buf.st_mode & 0777) | (0111 & ~umask(0));
	else
	    mode = (stat_buf.st_mode & 0777) & ~0111;
	if(fchmod(fd, mode) == -1)
	    system_fatal("can't set execution permissions output file: %s",
			 outputfile);

	/*
	 * Create the buffer to copy the parts of the output file into.
	 */
	if((r = vm_allocate(mach_task_self(), (vm_address_t *)&output_addr,
			    output_size, TRUE)) != KERN_SUCCESS)
	    mach_fatal(r, "can't vm_allocate() buffer for output file of size "
		       "%lu", output_size);

	/*
	 * Set up for flushing pages to the output file as they fill up.
	 */
	if(flush)
	    setup_output_flush();

	/*
	 * Make sure pure_instruction sections are padded with nop's.
	 */
	nop_pure_instruction_scattered_sections();

#endif /* !defined(RLD) */

	/*
	 * The strings indexes for the merged string blocks need to be set
	 * before the dylib tables are output because the module names are in
	 * them as well as the merged symbol names.
	 */
	set_merged_string_block_indexes();

#ifndef RLD
	/*
	 * Copy the dylib tables into the output file.  This is done before the
	 * sections are outputted so that the indexes to the local and external
	 * relocation entries for each object can be used as running indexes as
	 * each section in the object is outputted.
	 */
	if(filetype == MH_DYLIB)
	    output_dylib_tables();
#endif /* !defined(RLD) */

	/*
	 * Create the array of pointers to merged sections in the output file
	 * so the relocation routines can use it to set the 'referenced' fields
	 * in the merged section structures.
	 */
	create_output_sections_array();

	/*
	 * Copy the merged literal sections and the sections created from files
	 * into the output object file.
	 */
	output_literal_sections();
#ifndef RLD
	output_sections_from_files();
#endif /* !defined(RLD) */

	/*
	 * For each non-literal content section in each object file loaded 
	 * relocate it into the output file (along with the relocation entries).
	 * Then relocate local symbols into the output file for the loaded
	 * objects.
	 */
	for(p = &objects; *p; p = &(object_list->next)){
	    object_list = *p;
	    for(i = 0; i < object_list->used; i++){
		cur_obj = &(object_list->object_files[i]);
		/* print the object file name if tracing */
		if(trace){
		    print_obj_name(cur_obj);
		    print("\n");
		}
		if(cur_obj->dylib)
		    continue;
		if(cur_obj->bundle_loader)
		    continue;
		if(cur_obj->dylinker)
		    continue;
		if(cur_obj != base_obj){
		    for(j = 0; j < cur_obj->nsection_maps; j++){
			if(cur_obj->section_maps[j].s->flags & S_ATTR_DEBUG)
			    continue;
#ifdef RLD
			if(cur_obj->set_num == cur_set)
#endif /* RLD */
			{
			    section_type = (cur_obj->section_maps[j].s->flags &
                                                   SECTION_TYPE);
			    if(section_type == S_REGULAR ||
			       section_type == S_SYMBOL_STUBS ||
			       section_type == S_NON_LAZY_SYMBOL_POINTERS ||
			       section_type == S_LAZY_SYMBOL_POINTERS ||
			       section_type == S_COALESCED ||
			       section_type == S_MOD_INIT_FUNC_POINTERS ||
			       section_type == S_MOD_TERM_FUNC_POINTERS){
				output_section(&(cur_obj->section_maps[j]));
			    }
			}
		    }
		}
		output_local_symbols();
#if defined(VM_SYNC_DEACTIVATE) && !defined(_POSIX_C_SOURCE) && !defined(__CYGWIN__)
		vm_msync(mach_task_self(), (vm_address_t)cur_obj->obj_addr,
			 (vm_size_t)cur_obj->obj_size, VM_SYNC_DEACTIVATE);
#endif /* VM_SYNC_DEACTIVATE */
	    }
	}
	/*
	 * If there were errors in output_section() then return as so not
	 * to cause later internal errors.
	 */
	if(errors != 0)
	    return;

#ifdef RLD
	/*
	 * For each content section clean up the data structures not needed
	 * after rld is run.  This must be done after ALL the sections are
	 * output'ed because the fine relocation entries could be used by any
	 * of the sections.
	 */
	for(p = &objects; *p; p = &(object_list->next)){
	    object_list = *p;
	    for(i = 0; i < object_list->used; i++){
		cur_obj = &(object_list->object_files[i]);
		for(j = 0; j < cur_obj->nsection_maps; j++){
		    if(cur_obj->section_maps[j].nfine_relocs != 0){
			free(cur_obj->section_maps[j].fine_relocs);
			cur_obj->section_maps[j].fine_relocs = NULL;
			cur_obj->section_maps[j].nfine_relocs = 0;
		    }
		}
		if(cur_obj->nundefineds != 0){
		    free(cur_obj->undefined_maps);
		    cur_obj->undefined_maps = NULL;
		    cur_obj->nundefineds = 0;
		}
	    }
	}
#endif /* RLD */

	/*
	 * Set the SG_NORELOC flag in the segments that had no relocation to
	 * or for them.
	 */
	set_SG_NORELOC_flags();

#ifndef SA_RLD
	/*
	 * Copy the indirect symbol table into the output file.
	 */
	output_indirect_symbols();
#endif /* SA_RLD */

	/*
	 * Copy the merged symbol table into the output file.
	 */
	output_merged_symbols();

	/*
	 * Copy the headers into the output file.
	 */
	output_headers();

#ifndef RLD
	if(flush){
	    /*
	     * Flush the sections that have been scatter loaded.
	     */
	    flush_scatter_copied_sections();
	    /*
	     * flush the remaining part of the object file that is not a full
	     * page.
	     */
	    final_output_flush();
	}
	else{
	    /*
	     * Write the entire object file.
	     */
	    if(write(fd, output_addr, output_size) != (int)output_size)
		system_fatal("can't write output file");

	    if((r = vm_deallocate(mach_task_self(), (vm_address_t)output_addr,
				  output_size)) != KERN_SUCCESS)
		mach_fatal(r, "can't vm_deallocate() buffer for output file");
	}
#ifdef F_NOCACHE
	/* re-enable caching of file reads/writes */
	(void)fcntl(fd, F_NOCACHE, 0);
#endif
	if(close(fd) == -1)
	    system_fatal("can't close output file");
#endif /* RLD */
}
예제 #25
0
파일: wiki.c 프로젝트: henri14/citadel
/*
 * Display the revision history for a wiki page
 */
void display_wiki_history(void)
{
	output_headers(1, 1, 1, 0, 0, 0);
	do_template("wiki_history");
	wDumpContent(1);
}
예제 #26
0
파일: wiki.c 프로젝트: henri14/citadel
/*
 * Display a list of all pages in a Wiki room.  Search requests in a Wiki room also go here.
 */
void display_wiki_pagelist(void)
{
	output_headers(1, 1, 1, 0, 0, 0);
	do_template("wiki_pagelist");
	wDumpContent(1);
}