Example #1
0
void
test_session_tcp6(void) {
    lagopus_result_t ret;
    char cbuf[256] = {0};
    char sbuf[256] = {0};
    lagopus_session_t sesc, sess, sesa;
    struct addrunion dst, src;

    ret = session_create(SESSION_TCP6|SESSION_PASSIVE, &sess);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);

    addrunion_ipv6_set(&src, "::0");
    ret = session_bind(sess, &src, 10023);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);

    ret = session_create(SESSION_TCP6|SESSION_ACTIVE, &sesc);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);

    addrunion_ipv6_set(&dst, "::1");
    ret = session_connect(sesc, &dst, 10023, NULL, 0);
    if (ret == 0 || errno == EINPROGRESS)  {
        TEST_ASSERT(true);
    } else {
        TEST_ASSERT(false);
    }

    ret = session_accept(sess, &sesa);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);
    TEST_ASSERT_NOT_NULL(sesa);

    TEST_ASSERT_TRUE(session_is_alive(sess));
    TEST_ASSERT_TRUE(session_is_alive(sesc));
    TEST_ASSERT_TRUE(session_is_alive(sesa));

    snprintf(cbuf, sizeof(cbuf), "hogehoge\n");
    ret = session_write(sesc, cbuf, strlen(cbuf));
    TEST_ASSERT_EQUAL(ret, strlen(cbuf));
    ret = session_read(sesa, sbuf, sizeof(sbuf));
    TEST_ASSERT_EQUAL(ret, strlen(sbuf));

    ret = session_write(sesa, sbuf, strlen(sbuf));
    TEST_ASSERT_EQUAL(ret, strlen(sbuf));
    ret = session_read(sesc, cbuf, sizeof(cbuf));
    TEST_ASSERT_EQUAL(ret, strlen(cbuf));

    session_destroy(sesc);
    session_destroy(sesa);
    session_destroy(sess);
}
Example #2
0
void
test_session_pair_stream(void) {
    lagopus_result_t ret;
    char cbuf[256] = {0};
    char sbuf[256] = {0};
    lagopus_session_t s[2];

    ret = session_pair(SESSION_UNIX_STREAM, s);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);

    snprintf(cbuf, sizeof(cbuf), "hogehoge\n");
    ret = session_write(s[0], cbuf, strlen(cbuf));
    TEST_ASSERT_EQUAL(ret, strlen(cbuf));
    ret = session_read(s[1], sbuf, sizeof(sbuf));
    TEST_ASSERT_EQUAL(ret, strlen(sbuf));

    ret = session_write(s[1], sbuf, strlen(sbuf));
    TEST_ASSERT_EQUAL(ret, strlen(sbuf));
    ret = session_read(s[0], cbuf, sizeof(cbuf));
    TEST_ASSERT_EQUAL(ret, strlen(cbuf));

    session_destroy(s[0]);
    session_destroy(s[1]);
}
Example #3
0
void
test_session_tcp(void) {
    lagopus_result_t ret;
    char cbuf[256] = {0};
    char sbuf[256] = {0};
    bool b;
    lagopus_session_t sesc, sess, sesa, sesp[3];
    struct addrunion dst, src;

    ret = session_create(SESSION_TCP|SESSION_PASSIVE, &sess);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);

    addrunion_ipv4_set(&src, "0.0.0.0");
    ret = session_bind(sess, &src, 10022);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);

    ret = session_create(SESSION_TCP|SESSION_ACTIVE, &sesc);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);

    addrunion_ipv4_set(&dst, "127.0.0.1");
    ret = session_connect(sesc, &dst, 10022, NULL, 0);
    if (ret == 0 || errno == EINPROGRESS)  {
        TEST_ASSERT(true);
    } else {
        TEST_ASSERT(false);
    }

    session_write_event_set(sesc);
    session_read_event_set(sess);
    sesp[0] = sesc;
    sesp[1] = sess;
    ret = session_poll(sesp, 2, 1);
    TEST_ASSERT_EQUAL(2, ret);

    ret = session_is_writable(sesc, &b);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);
    TEST_ASSERT_TRUE(b);

    ret = session_is_readable(sess, &b);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);
    TEST_ASSERT_TRUE(b);

    ret = session_accept(sess, &sesa);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);
    TEST_ASSERT_NOT_NULL(sesa);

    TEST_ASSERT_TRUE(session_is_alive(sess));
    TEST_ASSERT_TRUE(session_is_alive(sesc));
    TEST_ASSERT_TRUE(session_is_alive(sesa));

    session_write_event_set(sesc);
    session_read_event_set(sess);
    session_read_event_set(sesa);
    sesp[0] = sesc;
    sesp[1] = sess;
    sesp[2] = sesa;
    ret = session_poll(sesp, 3, 1);
    TEST_ASSERT_EQUAL(1, ret);

    ret = session_is_writable(sesc, &b);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);
    TEST_ASSERT_TRUE(b);

    ret = session_is_readable(sess, &b);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);
    TEST_ASSERT_FALSE(b);

    ret = session_is_readable(sesa, &b);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);
    TEST_ASSERT_FALSE(b);

    snprintf(cbuf, sizeof(cbuf), "hogehoge\n");
    ret = session_write(sesc, cbuf, strlen(cbuf));
    TEST_ASSERT_EQUAL(ret, strlen(cbuf));

    session_read_event_set(sesa);
    sesp[0] = sesa;
    ret = session_poll(sesp, 1, 1);
    TEST_ASSERT_EQUAL(1, ret);

    ret = session_is_readable(sesa, &b);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);
    TEST_ASSERT_TRUE(b);

    ret = session_read(sesa, sbuf, sizeof(sbuf));
    TEST_ASSERT_EQUAL(ret, strlen(sbuf));
    ret = session_write(sesa, sbuf, strlen(sbuf));
    TEST_ASSERT_EQUAL(ret, strlen(sbuf));
    ret = session_read(sesc, cbuf, sizeof(cbuf));
    TEST_ASSERT_EQUAL(ret, strlen(cbuf));

    session_close(sesc);
    TEST_ASSERT_FALSE(session_is_alive(sesc));

    session_close(sesa);
    TEST_ASSERT_FALSE(session_is_alive(sesa));

    session_close(sess);
    TEST_ASSERT_FALSE(session_is_alive(sesa));

    session_write_event_set(sesc);
    session_read_event_set(sess);
    session_read_event_set(sesa);
    sesp[0] = sesc;
    sesp[1] = sess;
    sesp[2] = sesa;
    ret = session_poll(sesp, 3, 1);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_TIMEDOUT, ret);

    ret = session_is_writable(sesc, &b);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);
    TEST_ASSERT_FALSE(b);

    ret = session_is_readable(sess, &b);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);
    TEST_ASSERT_FALSE(b);

    ret = session_is_readable(sesa, &b);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);
    TEST_ASSERT_FALSE(b);

    session_destroy(sesc);
    session_destroy(sesa);
    session_destroy(sess);
}
Example #4
0
void
test_session_tls(void) {
#if 0 /* this test code is not work, use openssl s_server/s_client commands for tls session tests. */
    lagopus_result_t ret;
    char cbuf[256] = {0};
    char sbuf[256] = {0};
    lagopus_session_t sesc, sess, sesa;
    struct addrunion src, dst;

    session_tls_set_ca_dir("ca");
    session_tls_set_server_cert("./server1.pem");
    session_tls_set_server_key("./server1_key_nopass.pem");
    session_tls_set_client_key("./client1_key_nopass.pem");

    ret = session_create(SESSION_TCP|SESSION_PASSIVE|SESSION_TLS, &sess);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);
    addrunion_ipv4_set(&src, "0.0.0.0");
    ret = session_bind(sess, &src, 10024);

    addrunion_ipv4_set(&dst, "127.0.0.1");
    ret = session_create(SESSION_TCP|SESSION_TLS|SESSION_ACTIVE, &sesc);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);

    ret = session_connect(sesc, &dst, 10024, &dst, 0);
    if (ret == 0 || errno == EINPROGRESS)  {
        TEST_ASSERT(true);
    } else {
        TEST_ASSERT(false);
    }

    ret = session_accept(sess, &sesa);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);
    TEST_ASSERT_NOT_NULL(sesa);

    TEST_ASSERT_TRUE(session_is_alive(sess));
    TEST_ASSERT_TRUE(session_is_alive(sesa));

    ret = session_read(sesa, sbuf, sizeof(sbuf));
    TEST_ASSERT_EQUAL(ret, strlen(sbuf));

    ret = session_write(sesa, sbuf, strlen(sbuf));
    TEST_ASSERT_EQUAL(ret, strlen(sbuf));

    TEST_ASSERT_TRUE(session_is_alive(sesc));

    snprintf(cbuf, sizeof(cbuf), "hogehoge\n");
    ret = session_write(sesc, cbuf, strlen(cbuf));
    TEST_ASSERT_EQUAL(ret, strlen(cbuf));
    ret = session_read(sesa, sbuf, sizeof(sbuf));
    TEST_ASSERT_EQUAL(ret, strlen(sbuf));

    ret = session_write(sesa, sbuf, strlen(sbuf));
    TEST_ASSERT_EQUAL(ret, strlen(sbuf));
    ret = session_read(sesc, cbuf, sizeof(cbuf));
    TEST_ASSERT_EQUAL(ret, strlen(cbuf));

    session_destroy(sesc);
    session_destroy(sesa);
    session_destroy(sess);
#endif
}
Example #5
0
static void dispatcher_loop()
{
	int numfds;
	fd_set fdset;
	int count;
	struct timeval timeout;


	timeout.tv_usec = 0;

	while(1)
	{
		if(sighup)
		{
			resource_update(config_dir);
			sighup = False;
		}

		if(trace_level > 1)
		{
			trace_sessions();
		}

		numfds = 0;
		FD_ZERO(&fdset);

		numfds = MAX(clients_sd, agents_sd);
		numfds = MAX(numfds,trap_sd);
		numfds++;
		FD_SET(clients_sd, &fdset);
		FD_SET(agents_sd, &fdset);
		FD_SET(trap_sd, &fdset);

		timeout.tv_sec = relay_agent_poll_interval;

		/* we compute the timeout according to the	*/
		/* timeout of the pending requests		*/
		session_select_info(&timeout);

		count = select(numfds, &fdset, 0, 0, &timeout);
		if(count > 0)
		{
			if(FD_ISSET(agents_sd, &fdset))
			{
				/* we read the responses of the agents */
				session_read();
				continue;
				
			}

			if(FD_ISSET(trap_sd, &fdset))
			{
				/* working on the trap */
				trap_processing();
				continue;
				
			}

			if(FD_ISSET(clients_sd, &fdset))
			{
				/* we dispatch the requests of the application */
				session_dispatch();

			        session_timeout();
				continue;
			}

		}
		else
		{
			switch(count)
			{
				case 0:
					/* we check if some requests have timeout */
					session_timeout();
					  watch_dog_in_action();
					break;

				case -1:
					if(errno == EINTR)
					{
						break;
					}
					else
					{
						error_exit(ERR_MSG_SELECT, errno_string());
					}
			}
		}
	}
}
Example #6
0
int cgiMain()
{
	
	
	int ret = session_read(name);
	if(ret != 1)
	{
		cgiHeaderContentType("text/html;charset=gb2312");
		fprintf(cgiOut, "<HTML><HEAD>\n");
		fprintf(cgiOut,	"</HEAD><BODY>\n");
		fprintf(cgiOut, "<script type=\"text/javascript\">\n");
		fprintf(cgiOut, "window.alert(\"用户尚未登录,请重新登录(错误码:%d)!\");\n", ret);
		fprintf(cgiOut, "window.location.href=\"../login.html\";\n");
		fprintf(cgiOut, "</script>\n");
		fprintf(cgiOut, "</BODY>\n");
		fprintf(cgiOut, "</HTML>\n");
		return 0;
	}
	
	ret = its_conf_gpio_query(name, &con_gpio);
	
	
	
	cgiHeaderContentType("text/html;charset=gb2312");
	fprintf(cgiOut, "<style type=\"text/css\">\n");
	fprintf(cgiOut, "<!--\n");
	fprintf(cgiOut, "body {\n");
	fprintf(cgiOut, "	margin-left: 0px;\n");
	fprintf(cgiOut, "	margin-top: 0px;\n");
	fprintf(cgiOut, "	margin-right: 0px;\n");
	fprintf(cgiOut, "	margin-bottom: 0px;\n");
	fprintf(cgiOut, "	background-color: #F8F9FA;\n");
	fprintf(cgiOut, "}\n");
	fprintf(cgiOut, "-->\n");
	fprintf(cgiOut, "</style>\n");
	fprintf(cgiOut, "<link href=\"../images/skin.css\" rel=\"stylesheet\" type=\"text/css\" />\n");
	//fprintf(cgiOut, "<HEAD><meta http-equiv=\"refresh\" content=\"1\">\n");
	fprintf(cgiOut,	"</HEAD>\n");
	fprintf(cgiOut, "<body>\n");
	
	if(ret != QUERY_OK)
	{
		fprintf(cgiOut, "<script type=\"text/javascript\">\n");
		fprintf(cgiOut, "window.alert(\"(错误码:%d)!\");\n", ret);
		fprintf(cgiOut, "</script>\n");		
	}else if (cgiFormSubmitClicked("setting") == cgiFormSuccess){


		char *str1[2] = {"0","1"};
		int  i;/*must be int, f**k*/
		cgiFormSelectSingle("output1", str1, sizeof(str1)/sizeof(str1[0]), &i, 0);
		con_gpio.output[0]= i;

		cgiFormSelectSingle("output2", str1, sizeof(str1)/sizeof(str1[0]), &i, 0);
		con_gpio.output[1]= i;

		cgiFormSelectSingle("output3", str1, sizeof(str1)/sizeof(str1[0]), &i, 0);
		con_gpio.output[2]= i;

      cgiFormSelectSingle("output4", str1, sizeof(str1)/sizeof(str1[0]), &i, 0);
		con_gpio.output[3]= i;
      

		

#if 0
		its_conf_gpio_set(name,&con_gpio);
#else
		if (GPIO_SET_OK!=its_conf_gpio_set(name,&con_gpio)){
	
			fprintf(cgiOut, "<script type=\"text/javascript\">\n");
			fprintf(cgiOut, "window.alert(\"提交失败(错误码:%d)!\");\n", ret);
			fprintf(cgiOut, "</script>\n");
			
			//提交失败后需要重新获取参数
			bzero(&con_gpio, sizeof(con_gpio));
			its_conf_gpio_query(name, &con_gpio);
		}
		else
		{
			//fprintf(cgiOut, "[%s][%s][%s][%s]\n", con_sys.host_name, con_sys.host_pos, con_sys.host_id, con_sys.description);
			fprintf(cgiOut, "<script type=\"text/javascript\">\n");
			fprintf(cgiOut, "window.alert(\"提交成功!\");\n");
			fprintf(cgiOut, "</script>\n");
		}

#endif
	}
		
	
	
SHOW:	
	fprintf(cgiOut, "<table width=\"100%%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
	fprintf(cgiOut, "  <tr>\n");
	fprintf(cgiOut, "    <td width=\"17\" height=\"29\" valign=\"top\" background=\"../images/mail_leftbg.gif\"><img src=\"../images/left-top-right.gif\" width=\"17\" height=\"29\" /></td>\n");
	fprintf(cgiOut, "    <td width=\"935\" height=\"29\" valign=\"top\" background=\"../images/content-bg.gif\"><table width=\"100%%\" height=\"31\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"left_topbg\" id=\"table2\">\n");
	fprintf(cgiOut, "      <tr>\n");
	fprintf(cgiOut, "        <td height=\"31\"><div class=\"titlebt\">传感器设置</div></td>\n");
	fprintf(cgiOut, "      </tr>\n");
	fprintf(cgiOut, "    </table></td>\n");
	fprintf(cgiOut, "    <td width=\"16\" valign=\"top\" background=\"../images/mail_rightbg.gif\"><img src=\"../images/nav-right-bg.gif\" width=\"16\" height=\"29\" /></td>\n");
	fprintf(cgiOut, "  </tr>\n");
	fprintf(cgiOut, "  <tr>\n");
	fprintf(cgiOut, "    <td height=\"71\" valign=\"middle\" background=\"../images/mail_leftbg.gif\">&nbsp;</td>\n");
	fprintf(cgiOut, "    <td valign=\"top\" bgcolor=\"#F7F8F9\"><table width=\"100%%\" height=\"138\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
	fprintf(cgiOut, "      <tr>\n");
	fprintf(cgiOut, "        <td height=\"13\" valign=\"top\">&nbsp;</td>\n");
	fprintf(cgiOut, "      </tr>\n");
	fprintf(cgiOut, "      <tr>\n");
	fprintf(cgiOut, "        <td valign=\"top\"><table width=\"98%%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">\n");
	fprintf(cgiOut, "          <tr>\n");
	fprintf(cgiOut, "            <td class=\"left_txt\"></td>\n");
	fprintf(cgiOut, "          </tr>\n");
	fprintf(cgiOut, "          <tr>\n");
	fprintf(cgiOut, "            <td height=\"20\"><table width=\"100%%\" height=\"1\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"#CCCCCC\">\n");
	fprintf(cgiOut, "              <tr>\n");
	fprintf(cgiOut, "                <td></td>\n");
	fprintf(cgiOut, "              </tr>\n");
	fprintf(cgiOut, "            </table></td>\n");
	fprintf(cgiOut, "          </tr>\n");
	fprintf(cgiOut, "          <tr>\n");
	fprintf(cgiOut, "            <td><table width=\"100%%\" height=\"55\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
	fprintf(cgiOut, "              <tr>\n");
	fprintf(cgiOut, "                <td width=\"10%%\" height=\"55\" valign=\"middle\"><img src=\"../images/title.gif\" width=\"54\" height=\"55\"></td>\n");
	fprintf(cgiOut, "                <td width=\"90%%\" valign=\"top\"><span class=\"left_txt2\"></span><span class=\"left_txt3\"></span><span class=\"left_txt2\"></span><br>\n");
	fprintf(cgiOut, "                          <span class=\"left_txt2\"></span><span class=\"left_txt3\"></span><span class=\"left_txt2\"></span><span class=\"left_txt3\"></span><span class=\"left_txt2\"> </span></td>\n");
	fprintf(cgiOut, "              </tr>\n");
	fprintf(cgiOut, "            </table></td>\n");
	fprintf(cgiOut, "          </tr>\n");
	fprintf(cgiOut, "          <tr>\n");
	fprintf(cgiOut, "            <td>&nbsp;</td>\n");
	fprintf(cgiOut, "          </tr>\n");
	fprintf(cgiOut, "          <tr>\n");
	fprintf(cgiOut, "            <td><table width=\"100%%\" height=\"31\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"nowtable\">\n");
	fprintf(cgiOut, "              <tr>\n");
	fprintf(cgiOut, "                <td class=\"left_bt2\">&nbsp;&nbsp;&nbsp;&nbsp;报警信号输入状态</td>\n");
	fprintf(cgiOut, "              </tr>\n");
	fprintf(cgiOut, "            </table></td>\n");
	fprintf(cgiOut, "          </tr>\n");
	fprintf(cgiOut, "          <tr>\n");
	fprintf(cgiOut, "            <td><table width=\"100%%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n");
	fprintf(cgiOut, "              <form name=\"form1\" method=\"POST\" action=\"");
	fprintf(cgiOut, "\">\n");
	

	fprintf(cgiOut, "                </tr>\n");
	fprintf(cgiOut, "                <tr>\n");
	fprintf(cgiOut, "                  <td height=\"30\" align=\"right\" bgcolor=\"#F7F8F9\" class=\"left_txt2\">Alarm1</td>\n");
	fprintf(cgiOut, "                  <td bgcolor=\"#F7F8F9\">&nbsp;</td>\n");
	fprintf(cgiOut, "                  <td height=\"30\" bgcolor=\"#F7F8F9\"><label>\n");
	
	show_alarm(1);
	fprintf(cgiOut, "                </tr>\n");
	fprintf(cgiOut, "                <tr>\n");
	fprintf(cgiOut, "                  <td height=\"30\" align=\"right\" bgcolor=\"#F7F8F9\" class=\"left_txt2\">Alarm2</td>\n");
	fprintf(cgiOut, "                  <td bgcolor=\"#F7F8F9\">&nbsp;</td>\n");
	fprintf(cgiOut, "                  <td height=\"30\" bgcolor=\"#F7F8F9\"><label>\n");
	show_alarm(2);
	fprintf(cgiOut, "                </tr>\n");
	fprintf(cgiOut, "                <tr>\n");
	fprintf(cgiOut, "                  <td height=\"30\" align=\"right\" bgcolor=\"#F7F8F9\" class=\"left_txt2\">Alarm3</td>\n");
	fprintf(cgiOut, "                  <td bgcolor=\"#F7F8F9\">&nbsp;</td>\n");
	fprintf(cgiOut, "                  <td height=\"30\" bgcolor=\"#F7F8F9\"><label>\n");
	show_alarm(3);
   /*
   fprintf(cgiOut, "                </tr>\n");
	fprintf(cgiOut, "                <tr>\n");
	fprintf(cgiOut, "                  <td height=\"30\" align=\"right\" bgcolor=\"#F7F8F9\" class=\"left_txt2\">Alarm4</td>\n");
	fprintf(cgiOut, "                  <td bgcolor=\"#F7F8F9\">&nbsp;</td>\n");
	fprintf(cgiOut, "                  <td height=\"30\" bgcolor=\"#F7F8F9\"><label>\n");
	show_alarm(4);
	fprintf(cgiOut, "                </tr>\n");
	fprintf(cgiOut, "                <tr>\n");
	fprintf(cgiOut, "                  <td height=\"30\" align=\"right\" bgcolor=\"#F7F8F9\" class=\"left_txt2\">Alarm5</td>\n");
	fprintf(cgiOut, "                  <td bgcolor=\"#F7F8F9\">&nbsp;</td>\n");
	fprintf(cgiOut, "                  <td height=\"30\" bgcolor=\"#F7F8F9\"><label>\n");
	show_alarm(5);
	fprintf(cgiOut, "                </tr>\n");
	fprintf(cgiOut, "                <tr>\n");
	fprintf(cgiOut, "                  <td height=\"30\" align=\"right\" bgcolor=\"#F7F8F9\" class=\"left_txt2\">Alarm6</td>\n");
	fprintf(cgiOut, "                  <td bgcolor=\"#F7F8F9\">&nbsp;</td>\n");
	fprintf(cgiOut, "                  <td height=\"30\" bgcolor=\"#F7F8F9\"><label>\n");
	show_alarm(6);
	fprintf(cgiOut, "                </tr>\n");
	fprintf(cgiOut, "                <tr>\n");
	fprintf(cgiOut, "                  <td height=\"30\" align=\"right\" bgcolor=\"#F7F8F9\" class=\"left_txt2\">Alarm7</td>\n");
	fprintf(cgiOut, "                  <td bgcolor=\"#F7F8F9\">&nbsp;</td>\n");
	fprintf(cgiOut, "                  <td height=\"30\" bgcolor=\"#F7F8F9\"><label>\n");
	show_alarm(7);
	fprintf(cgiOut, "                </tr>\n");
	fprintf(cgiOut, "                <tr>\n");
	fprintf(cgiOut, "                  <td height=\"30\" align=\"right\" bgcolor=\"#F7F8F9\" class=\"left_txt2\">Alarm8</td>\n");
	fprintf(cgiOut, "                  <td bgcolor=\"#F7F8F9\">&nbsp;</td>\n");
	fprintf(cgiOut, "                  <td height=\"30\" bgcolor=\"#F7F8F9\"><label>\n");
	show_alarm(8);
   */

	fprintf(cgiOut, "                    </label></td>\n");
	fprintf(cgiOut, "                </tr>\n");
	fprintf(cgiOut, "                <tr>\n");
	fprintf(cgiOut, "                  <td height=\"30\" align=\"right\" class=\"left_txt2\">Output1:</td>\n");
	fprintf(cgiOut, "                  <td>&nbsp;</td>\n");
	fprintf(cgiOut, "                  <td height=\"30\"><label>\n");
	show_output1();

	fprintf(cgiOut, "                    </label></td>\n");
	fprintf(cgiOut, "                </tr>\n");
	fprintf(cgiOut, "                <tr>\n");
	fprintf(cgiOut, "                  <td height=\"30\" align=\"right\" class=\"left_txt2\">Output2:</td>\n");
	fprintf(cgiOut, "                  <td>&nbsp;</td>\n");
	fprintf(cgiOut, "                  <td height=\"30\"><label>\n");
	show_output2();

	fprintf(cgiOut, "                    </label></td>\n");
	fprintf(cgiOut, "                </tr>\n");
	fprintf(cgiOut, "                <tr>\n");
	fprintf(cgiOut, "                  <td height=\"30\" align=\"right\" class=\"left_txt2\">Output3:</td>\n");
	fprintf(cgiOut, "                  <td>&nbsp;</td>\n");
	fprintf(cgiOut, "                  <td height=\"30\"><label>\n");
	show_output3();

   fprintf(cgiOut, "                    </label></td>\n");
	fprintf(cgiOut, "                </tr>\n");
	fprintf(cgiOut, "                <tr>\n");
	fprintf(cgiOut, "                  <td height=\"30\" align=\"right\" class=\"left_txt2\">Output4:</td>\n");
	fprintf(cgiOut, "                  <td>&nbsp;</td>\n");
	fprintf(cgiOut, "                  <td height=\"30\"><label>\n");
	show_output4();

	fprintf(cgiOut, "                <tr>\n");
	fprintf(cgiOut, "                  <td height=\"30\" colspan=\"4\" align=\"center\" class=\"left_txt2\"><input type=\"submit\" value=\"设置\" name=\"setting\" /></td>\n");
	fprintf(cgiOut, "                </tr>\n");
	
	fprintf(cgiOut, "</body>\n");
}
Example #7
0
/*
 * plugin_load()
 *
 * ³aduje wtyczkê o podanej nazwie.
 * 
 * 0/-1
 */
int plugin_load(const char *name, int prio, int quiet)
{
#ifdef SHARED_LIBS
	char lib[PATH_MAX];
	char *env_ekg_plugins_path = NULL;
	char *init = NULL;
#endif

	plugin_t *pl;
	void *plugin = NULL;
	int (*plugin_init)() = NULL;

	if (!name)
		return -1;

	if (plugin_find(name)) {
		printq("plugin_already_loaded", name); 
		return -1;
	}
#ifdef SHARED_LIBS
#ifndef NO_POSIX_SYSTEM
#ifdef SCONS
#	define DOTLIBS "" 
#else
#	define DOTLIBS ".libs/"
#endif
	if ((env_ekg_plugins_path = getenv("EKG_PLUGINS_PATH"))) {
		if (snprintf(lib, sizeof(lib), "%s/%s.so", env_ekg_plugins_path, name) < sizeof(lib))
			plugin = ekg2_dlopen(lib);
		if (!plugin && (snprintf(lib, sizeof(lib), "%s/%s/" DOTLIBS "%s.so", env_ekg_plugins_path, name, name) < sizeof(lib)))
				plugin = ekg2_dlopen(lib);
	}

#ifndef SKIP_RELATIVE_PLUGINS_DIR
	/* The following lets ekg2 load plugins when it is run directly from
	 * the source tree, without installation. This can be beneficial when
	 * developing the program, or for less knowlegeable users, who don't
	 * know how to or cannot for some other reason use installation prefix
	 * to install in their home directory. However this impses a security
	 * risk if the program installed in the system directory is run in
	 * untrusted $CWD or when $CWD/../plugins is untrusted.
	 *
	 * TODO(porridge,darkjames): This can be fixed by having a wrapper
	 * script in the source tree to run ekg/.libs/ekg2 with
	 * EKG_PLUGINS_PATH set appropriately.
	 */
	if (!plugin) {
		if (snprintf(lib, sizeof(lib), "plugins/%s/" DOTLIBS "%s.so", name, name) < sizeof(lib))
			plugin = ekg2_dlopen(lib);
	}

	if (!plugin) {
		if (snprintf(lib, sizeof(lib), "../plugins/%s/" DOTLIBS "%s.so", name, name) < sizeof(lib))
			plugin = ekg2_dlopen(lib);
	}
#endif

	if (!plugin) {
		if (snprintf(lib, sizeof(lib), "%s/%s.so", PLUGINDIR, name) < sizeof(lib))
			plugin = ekg2_dlopen(lib);
	}
#else	/* NO_POSIX_SYSTEM */
	if (!plugin) {
		if (snprintf(lib, sizeof(lib), "c:\\ekg2\\plugins\\%s.dll", name) < sizeof(lib))
			plugin = ekg2_dlopen(lib);
	}
#endif /* SHARED_LIBS */
	if (!plugin) {
		printq("plugin_doesnt_exist", name);
		return -1;
	}
#endif

#ifdef STATIC_LIBS
#ifndef SCONS
/* first let's try to load static plugin... */
	extern int jabber_plugin_init(int prio);
	extern int irc_plugin_init(int prio);
	extern int gtk_plugin_init(int prio);

	debug("searching for name: %s in STATICLIBS: %s\n", name, STATIC_LIBS);

	if (!xstrcmp(name, "jabber")) plugin_init = &jabber_plugin_init;
	if (!xstrcmp(name, "irc")) plugin_init = &irc_plugin_init;
	if (!xstrcmp(name, "gtk")) plugin_init = &gtk_plugin_init;
//	if (!xstrcmp(name, "miranda")) plugin_init = &miranda_plugin_init;
#else
	debug_function("plugin_load(), trying to find static plugin '%s'\n", name);
	void *plugin_load_static(const char *name); /* autogenerated by scons */
	plugin_init = plugin_load_static(name);
#endif
#endif

#ifdef SHARED_LIBS
	if (!plugin_init) {
# ifdef EKG2_WIN32_HELPERS
		void (*plugin_preinit)(void *);
		char *preinit = saprintf("win32_plugin_init");
		if (!(plugin_preinit = ekg2_dlsym(plugin, preinit))) {
			debug("NO_POSIX_SYSTEM, PLUGIN:%s NOT COMPILATED WITH EKG2_WIN32_SHARED_LIB?!\n", name);
			printq("plugin_incorrect", name);
			xfree(preinit);
			return -1;
		}
		xfree(preinit);
		plugin_preinit(&win32_helper);
# endif
/* than if we don't have static plugin... let's try to load it dynamicly */
		init = saprintf("%s_plugin_init", name);

		if (!(plugin_init = ekg2_dlsym(plugin, init))) {
			printq("plugin_incorrect", name);
			ekg2_dlclose(plugin);
			xfree(init);
			return -1;
		}
		xfree(init);
	}
#endif
	if (!plugin_init) {
		printq("plugin_doesnt_exist", name);
		return -1;
	}

	if (plugin_init(prio) == -1) {
		printq("plugin_not_initialized", name);
		ekg2_dlclose(plugin);
		return -1;
	}

	if ((pl = plugin_find(name))) {
		pl->dl = plugin;
	} else {
		debug_error("plugin_load() plugin_find(%s) not found.\n", name);
		/* It's FATAL */
	}

	query_emit_id(pl, SET_VARS_DEFAULT);

	printq("plugin_loaded", name);

	if (!in_autoexec) {
		const char *tmp;

		in_autoexec = 1;
		if ((tmp = prepare_pathf("config-%s", name)))
			config_read(tmp);
		if ((pl->pclass == PLUGIN_PROTOCOL) && (tmp = prepare_pathf("sessions-%s", name)))
			session_read(tmp);

		if (pl)
			query_emit_id(pl, CONFIG_POSTINIT);

		in_autoexec = 0;
		config_changed = 1;
	}
	return 0;
}
Example #8
0
int cgiMain()
{
	int ret = session_read(name);
	if(ret != 1)
	{
		cgiHeaderContentType("text/html;charset=gb2312");
		fprintf(cgiOut, "<HTML><HEAD>\n");
		fprintf(cgiOut,	"</HEAD><BODY>\n");
		fprintf(cgiOut, "<script type=\"text/javascript\">\n");
		fprintf(cgiOut, "window.alert(\"用户尚未登录,请重新登录(错误码:%d)!\");\n", ret);
		fprintf(cgiOut, "window.location.href=\"../login.html\";\n");
		fprintf(cgiOut, "</script>\n");
		fprintf(cgiOut, "</BODY>\n");
		fprintf(cgiOut, "</HTML>\n");
		return 0;
	}

	int id = atoi(cgiQueryString);
	con_mode.id = id;
	ret = its_conf_mode_query(name, &con_mode);
	
	cgiHeaderContentType("text/html;charset=gb2312");
	fprintf(cgiOut, "<style type=\"text/css\">\n");
	fprintf(cgiOut, "<!--\n");
	fprintf(cgiOut, "body {\n");
	fprintf(cgiOut, "	margin-left: 0px;\n");
	fprintf(cgiOut, "	margin-top: 0px;\n");
	fprintf(cgiOut, "	margin-right: 0px;\n");
	fprintf(cgiOut, "	margin-bottom: 0px;\n");
	fprintf(cgiOut, "	background-color: #F8F9FA;\n");
	fprintf(cgiOut, "}\n");
	fprintf(cgiOut, "-->\n");
	fprintf(cgiOut, "</style>\n");
	fprintf(cgiOut, "<link href=\"../images/skin.css\" rel=\"stylesheet\" type=\"text/css\" />\n");
	fprintf(cgiOut, "<body>\n");
	
	if(ret != QUERY_OK)
	{
		fprintf(cgiOut, "<script type=\"text/javascript\">\n");
		fprintf(cgiOut, "window.alert(\"(错误码:%d)!\");\n", ret);
		fprintf(cgiOut, "</script>\n");		
	}
	else if(cgiFormSubmitClicked("mode") == cgiFormSuccess)
	{

		get_workmode();
		get_datamode();
		int i;
		for(i = 0; i < 6; i++)
			get_session(i);
		
		ret = its_conf_mode_set(name, &con_mode);
		if(ret != MODE_SET_OK)
		{
			fprintf(cgiOut, "<script type=\"text/javascript\">\n");
			fprintf(cgiOut, "window.alert(\"提交失败(错误码:%d)!\");\n", ret);
			fprintf(cgiOut, "</script>\n");
			
			//提交失败后需要重新获取参数
			bzero(&con_mode, sizeof(con_mode));
			con_mode.id = id;
			its_conf_mode_query(name, &con_mode);
		}
		else
		{
			fprintf(cgiOut, "<script type=\"text/javascript\">\n");
			fprintf(cgiOut, "window.alert(\"提交成功!\");\n");
			fprintf(cgiOut, "</script>\n");
		}
	}
	
	
fprintf(cgiOut, "<table width=\"100%%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
fprintf(cgiOut, "	<tr>\n");
fprintf(cgiOut, "	  <td width=\"17\" height=\"29\" valign=\"top\" background=\"../images/mail_leftbg.gif\"><img src=\"../images/left-top-right.gif\" width=\"17\" height=\"29\" /></td>\n");
fprintf(cgiOut, "	 <td width=\"935\" height=\"29\" valign=\"top\" background=\"../images/content-bg.gif\"><table width=\"100%%\" height=\"31\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"left_topbg\" id=\"table2\">\n");
fprintf(cgiOut, " 	 <tr>\n");
fprintf(cgiOut, " 	   <td height=\"31\"><div class=\"titlebt\">模式管理</div></td>\n");
fprintf(cgiOut, "	   </tr>\n");
fprintf(cgiOut, "	  </table></td>\n");
fprintf(cgiOut, "	 <td width=\"16\" valign=\"top\" background=\"../images/mail_rightbg.gif\"><img src=\"../images/nav-right-bg.gif\" width=\"16\" height=\"29\" /></td>\n");
fprintf(cgiOut, "  </tr>\n");
fprintf(cgiOut, "	<tr>\n");
fprintf(cgiOut, "	  <td height=\"71\" valign=\"middle\" background=\"../images/mail_leftbg.gif\">&nbsp;</td>\n");
fprintf(cgiOut, "	 <td valign=\"top\" bgcolor=\"#F7F8F9\"><table width=\"100%%\" height=\"138\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
fprintf(cgiOut, "	  <tr>\n");
fprintf(cgiOut, "		<td height=\"13\" valign=\"top\">&nbsp;</td>\n");
fprintf(cgiOut, "		</tr>\n");
fprintf(cgiOut, " 	 <tr>\n");
fprintf(cgiOut, " 	   <td valign=\"top\"><table width=\"98%%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">\n");
fprintf(cgiOut, " 		 <tr>\n");
fprintf(cgiOut, " 		   <td class=\"left_txt\">当前位置:模式管理</td>\n");
fprintf(cgiOut, " 		 </tr>\n");
fprintf(cgiOut, "		  <tr>\n");
fprintf(cgiOut, "			<td height=\"20\"><table width=\"100%%\" height=\"1\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"#CCCCCC\">\n");
fprintf(cgiOut, "			  <tr>\n");
fprintf(cgiOut, "				<td></td>\n");
fprintf(cgiOut, " 			 </tr>\n");
fprintf(cgiOut, "			</table></td>\n");
fprintf(cgiOut, " 		 </tr>\n");
fprintf(cgiOut, "		  <tr>\n");
fprintf(cgiOut, "			<td><table width=\"100%%\" height=\"55\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
fprintf(cgiOut, " 			 <tr>\n");
fprintf(cgiOut, " 			   <td width=\"10%%\" height=\"55\" valign=\"middle\"><img src=\"../images/title.gif\" width=\"54\" height=\"55\"></td>\n");
fprintf(cgiOut, "				 <td width=\"90%%\" valign=\"top\"><span class=\"left_txt2\">在这里,您可以根据您的要求,修改设置设备的</span><span class=\"left_txt3\">工作模式</span><span class=\"left_txt2\">!</span><br>\n");
fprintf(cgiOut, " 						 <span class=\"left_txt2\">包括</span><span class=\"left_txt3\">工作模式,数据模式,协议,端口</span><span class=\"left_txt2\">等参数</span><span class=\"left_txt3\"></span><span class=\"left_txt2\">。 </span></td>\n");
fprintf(cgiOut, "			  </tr>\n");
fprintf(cgiOut, "			 </table></td>\n");
fprintf(cgiOut, "		  </tr>\n");
fprintf(cgiOut, "		   <tr>\n");
fprintf(cgiOut, "			 <td>&nbsp;</td>\n");
fprintf(cgiOut, "			</tr>\n");
fprintf(cgiOut, " 		 <tr>\n");
fprintf(cgiOut, " 		   <td><table width=\"100%%\" height=\"31\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"nowtable\">\n");
fprintf(cgiOut, "			   <tr>\n");
fprintf(cgiOut, "				 <td class=\"left_bt2\">&nbsp;&nbsp;&nbsp;&nbsp;端口%d设置</td>\n", con_mode.id);
fprintf(cgiOut, " 			 </tr>\n");
fprintf(cgiOut, "			</table></td>\n");
fprintf(cgiOut, " 		 </tr>\n");
fprintf(cgiOut, "		  <tr>\n");
fprintf(cgiOut, "			<td><table width=\"100%%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n");
fprintf(cgiOut, "			   <form name=\"form1\" method=\"POST\" action=\"");
fprintf(cgiOut, "\">\n");

fprintf(cgiOut, "			   <tr>\n");
fprintf(cgiOut, "				 <td width=\"20%%\" height=\"30\" align=\"right\" bgcolor=\"#f2f2f2\" class=\"left_txt2\">工作模式:</td>\n");
fprintf(cgiOut, "				 <td width=\"3%%\" bgcolor=\"#f2f2f2\">&nbsp;</td>\n");
fprintf(cgiOut, " 			   <td width=\"32%%\" height=\"30\" bgcolor=\"#f2f2f2\">\n");
show_workmode();

fprintf(cgiOut, "							</td>\n");
fprintf(cgiOut, "				<td width=\"45%%\" height=\"30\" bgcolor=\"#f2f2f2\" class=\"left_txt\">&nbsp;</td>\n");
fprintf(cgiOut, "			  </tr>\n");
fprintf(cgiOut, "			   <tr>\n");
fprintf(cgiOut, "				 <td height=\"30\" align=\"right\" class=\"left_txt2\">TCP数据模式:</td>\n");
fprintf(cgiOut, " 			   <td>&nbsp;</td>\n");
fprintf(cgiOut, "				<td height=\"30\">\n");
show_datamode();

fprintf(cgiOut, "							</td>\n");
fprintf(cgiOut, "				<td height=\"30\" class=\"left_txt\">&nbsp;</td>\n");
fprintf(cgiOut, "				</tr>\n");
fprintf(cgiOut, " 			 <tr>\n");
fprintf(cgiOut, " 			   <td height=\"17\" colspan=\"4\" align=\"right\" >&nbsp;</td>\n");
fprintf(cgiOut, "			   </tr>\n");
fprintf(cgiOut, "				<tr>\n");
fprintf(cgiOut, "				  <td height=\"30\" colspan=\"4\" align=\"right\" class=\"left_txt2\"><table width=\"100%%\" height=\"31\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"nowtable\">\n");
fprintf(cgiOut, "				  <tr>\n");
fprintf(cgiOut, "					<td class=\"left_bt2\">&nbsp;&nbsp;&nbsp;&nbsp;会话</td>\n");
fprintf(cgiOut, "					</tr>\n");
fprintf(cgiOut, " 			   </table></td>\n");
fprintf(cgiOut, "				</tr>\n");
fprintf(cgiOut, " 			 <tr>\n");
fprintf(cgiOut, " 			   <td height=\"30\" colspan=\"4\" class=\"left_txt2\"><table width=\"100%%\" height=\"99\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
fprintf(cgiOut, "			<tr>\n");
fprintf(cgiOut, "			 <td width=\"12%%\" height=\"30\" align=\"right\" bgcolor=\"#f2f2f2\" class=\"left_txt\">&nbsp;</td>\n");
fprintf(cgiOut, "			 <td width=\"22%%\" height=\"30\" align=\"center\" bgcolor=\"#f2f2f2\" class=\"left_txt\">协议</td>\n");
fprintf(cgiOut, "			 <td width=\"22%%\" height=\"30\" align=\"center\" bgcolor=\"#f2f2f2\" class=\"left_txt\">对端主机</td>\n");
fprintf(cgiOut, "			 <td width=\"22%%\" height=\"30\" align=\"center\" bgcolor=\"#f2f2f2\" class=\"left_txt\">本机端口</td>\n");
fprintf(cgiOut, "					<td width=\"22%%\" height=\"30\" align=\"center\" bgcolor=\"#f2f2f2\" class=\"left_txt\">对端端口</td>\n");
fprintf(cgiOut, "			</tr>				   <tr>\n");
fprintf(cgiOut, "					 <td width=\"12%%\" height=\"30\" align=\"right\" bgcolor=\"#f2f2f2\" class=\"left_txt\">①						 </td>\n");
show_session(0);

fprintf(cgiOut, " 				 </tr>\n");
fprintf(cgiOut, "				  <tr>\n");
fprintf(cgiOut, "					<td width=\"12%%\" height=\"30\" align=\"right\" bgcolor=\"#f2f2f2\" class=\"left_txt\">②</td>\n");
show_session(1);
fprintf(cgiOut, " 				 </tr>\n");
fprintf(cgiOut, "				  <tr>\n");
fprintf(cgiOut, "					<td width=\"12%%\" height=\"30\" align=\"right\" bgcolor=\"#f2f2f2\" class=\"left_txt\">③</td>\n");
show_session(2);
fprintf(cgiOut, "				  </tr>\n");
fprintf(cgiOut, "				   <tr>\n");
fprintf(cgiOut, "					 <td width=\"12%%\" height=\"30\" align=\"right\" bgcolor=\"#f2f2f2\" class=\"left_txt\">④</td>\n");
show_session(3);
fprintf(cgiOut, " 				 </tr>\n");
fprintf(cgiOut, "				  <tr>\n");
fprintf(cgiOut, "					<td width=\"12%%\" height=\"30\" align=\"right\" bgcolor=\"#f2f2f2\" class=\"left_txt\">⑤</td>\n");
show_session(4);
fprintf(cgiOut, "				   </tr>\n");
fprintf(cgiOut, "				<tr>\n");
fprintf(cgiOut, "					  <td width=\"12%%\" height=\"30\" align=\"right\" bgcolor=\"#f2f2f2\" class=\"left_txt\">⑥</td>\n");
show_session(5);
fprintf(cgiOut, " 				 </tr>					<tr>\n");
fprintf(cgiOut, "					  <td colspan=\"3\" align=\"right\">&nbsp;</td>\n");
fprintf(cgiOut, "				   </tr>\n");
fprintf(cgiOut, "				  </table></td>\n");
fprintf(cgiOut, "			   </tr>\n");
fprintf(cgiOut, "				<tr>\n");
fprintf(cgiOut, "				  <td height=\"30\" colspan=\"4\" class=\"left_txt\"><table width=\"100%%\" height=\"90\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
fprintf(cgiOut, "				  <tr>\n");
fprintf(cgiOut, "					<td width=\"27%%\" align=\"center\" bgcolor=\"#f2f2f2\" class=\"left_txt\">&nbsp;</td>\n");
fprintf(cgiOut, " 				   <td width=\"27%%\" bgcolor=\"#f2f2f2\" class=\"left_txt\">&nbsp;</td>\n");
fprintf(cgiOut, "					 <td width=\"24%%\" bgcolor=\"#f2f2f2\" class=\"left_txt\">&nbsp;</td>\n");
fprintf(cgiOut, " 				   <td width=\"22%%\" bgcolor=\"#f2f2f2\" class=\"left_txt\"><span class=\"left_txt2\">\n");
fprintf(cgiOut, "					  <input type=\"submit\" value=\"完成以上修改\" name=\"mode\" />\n");
fprintf(cgiOut, "					</span></td>\n");
fprintf(cgiOut, "					</tr>\n");
fprintf(cgiOut, " 				 <tr>\n");
fprintf(cgiOut, " 				   <td align=\"center\" class=\"left_txt\">&nbsp;</td>\n");
fprintf(cgiOut, "					<td class=\"left_txt\">&nbsp;</td>\n");
fprintf(cgiOut, "					<td class=\"left_txt\">&nbsp;</td>\n");
fprintf(cgiOut, "					<td class=\"left_txt\">&nbsp;</td>\n");
fprintf(cgiOut, "				  </tr>\n");
fprintf(cgiOut, "				   <tr>\n");
fprintf(cgiOut, "					 <td align=\"center\" bgcolor=\"#f2f2f2\" class=\"left_txt\">&nbsp;</td>\n");
fprintf(cgiOut, "					  <td bgcolor=\"#f2f2f2\" class=\"left_txt\">&nbsp;</td>\n");
fprintf(cgiOut, "					  <td bgcolor=\"#f2f2f2\" class=\"left_txt\">&nbsp;</td>\n");
fprintf(cgiOut, "					  <td bgcolor=\"#f2f2f2\" class=\"left_txt\">&nbsp;</td>\n");
fprintf(cgiOut, "					</tr>\n");
fprintf(cgiOut, " 			   </table></td>\n");
fprintf(cgiOut, "				  </tr>\n");
fprintf(cgiOut, "			 </table></td>\n");
fprintf(cgiOut, "		  </tr>\n");
fprintf(cgiOut, "		 </table>\n");
fprintf(cgiOut, " 		 <table width=\"100%%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n");
fprintf(cgiOut, "			  <tr>\n");
fprintf(cgiOut, "			  <td colspan=\"3\">&nbsp;</td>\n");
fprintf(cgiOut, "			 </tr>\n");
fprintf(cgiOut, "			<tr>\n");
fprintf(cgiOut, "			   <td height=\"30\" colspan=\"3\">&nbsp;</td>\n");
fprintf(cgiOut, "			</tr>\n");
fprintf(cgiOut, " 		   \n");
fprintf(cgiOut, "			 <tr>\n");
fprintf(cgiOut, " 			 <td height=\"30\" colspan=\"3\">&nbsp;</td>\n");
fprintf(cgiOut, "			  </tr>\n");
fprintf(cgiOut, "			 <tr>\n");
fprintf(cgiOut, " 			 <td width=\"50%%\" height=\"30\" align=\"right\">&nbsp;</td>\n");
fprintf(cgiOut, "				<td width=\"6%%\" height=\"30\" align=\"right\">&nbsp;</td>\n");
fprintf(cgiOut, "			  <td width=\"44%%\" height=\"30\">&nbsp;</td>\n");
fprintf(cgiOut, " 		   </tr>\n");
fprintf(cgiOut, "			  <tr>\n");
fprintf(cgiOut, "			  <td height=\"30\" colspan=\"3\">&nbsp;</td>\n");
fprintf(cgiOut, " 		   </tr>\n");
fprintf(cgiOut, "			</table></td>\n");
fprintf(cgiOut, " 	 </tr>\n");
fprintf(cgiOut, "	</table></td>\n");
fprintf(cgiOut, "    <td background=\"../images/mail_rightbg.gif\">&nbsp;</td>\n");
fprintf(cgiOut, "  </tr>\n");
fprintf(cgiOut, "  <tr>\n");
fprintf(cgiOut, "	<td valign=\"middle\" background=\"../images/mail_leftbg.gif\"><img src=\"../images/buttom_left2.gif\" width=\"17\" height=\"17\" /></td>\n");
fprintf(cgiOut, "	   <td height=\"17\" valign=\"top\" background=\"../images/buttom_bgs.gif\"><img src=\"../images/buttom_bgs.gif\" width=\"17\" height=\"17\" /></td>\n");
fprintf(cgiOut, "	<td background=\"../images/mail_rightbg.gif\"><img src=\"../images/buttom_right2.gif\" width=\"16\" height=\"17\" /></td>\n");
fprintf(cgiOut, "  </tr>\n");
fprintf(cgiOut, "</table>\n");
	fprintf(cgiOut, "</body>\n");
}
Example #9
0
/*
   service_read ()

   Used to read from a session. Handles scheduling
   if the session would block.

   Used for reading from a service thread. If the read would block,
   put the thread to wait. When the scheduling cycle sees input on this
   session the random_input_ready_action is called.
   This wakes up this thread and schedules it for execution on the next
   round

   The need_all argument controls whether this function may return after reading
   fewer than the requested number of bytes. This function always reads at
   least 1 byte.

   If the calling thread is the scheduling thread and io would block, this
   allows schedule and recursively blocks on all pending i/o.
   If the calling thread is some other thread, this disables
   the thread and tells the scheduler to resume this when the input is ready.

   Returns the number of bytes read.
 */
int
service_read (dk_session_t * ses, char *buffer, int req_bytes, int need_all)
{
  USE_GLOBAL
  int last_read = 0;
  int bytes = req_bytes;
  du_thread_t *cur_proc;	/* mty NEW */
  int rc;

  DBG_CHECK_READ_FAIL (ses);

  while (bytes > 0)
    {
      without_scheduling_tic ();
      if (!ses->dks_is_read_select_ready && ses->dks_session && ses->dks_session->ses_class != SESCLASS_STRING)
	{
	  tcpses_is_read_ready (ses->dks_session, &ses->dks_read_block_timeout);
	  if (DKSESSTAT_ISSET (ses, SST_TIMED_OUT))
	    rc = -1;
	  else
	    rc = session_read (ses->dks_session, &(buffer[last_read]), bytes);
	}
      else
	{
	  if (!ses->dks_session)
	    longjmp_splice (&(SESSION_SCH_DATA (ses)->sio_read_broken_context), 1);

	  rc = session_read (ses->dks_session, &(buffer[last_read]), bytes);
	}
      ses->dks_is_read_select_ready = 0;
      restore_scheduling_tic ();

      if (rc == 0)
	PROCESS_ALLOW_SCHEDULE ();
      else if (rc > 0)
	{
	  bytes = bytes - rc;
	  last_read = last_read + rc;
	  if (!need_all)
	    {
	      ses->dks_bytes_received += last_read;
	      return (last_read);
	    }
	}
      if (rc <= 0)
	{
	  if (SESSTAT_ISSET (ses->dks_session, SST_INTERRUPTED))
	    {
	      PROCESS_ALLOW_SCHEDULE ();
	    }
	  else if (SESSTAT_ISSET (ses->dks_session, SST_BLOCK_ON_READ))
	    {
	      /* would block. suspend thread */

	      cur_proc = current_process;	 /* mty NEW */
	      if (!PROCESS_TO_DK_THREAD (cur_proc))
		{
		  /* We have a block on a server thread. We recognize it
		   * because a server thread is not associated to a request.
		   * The read would block the server thread. Run others and
		   * do a recursive check_inputs to resume other threads that
		   * may now be ready for i/o. Do a timeout round to unblock
		   * threads waiting on timed-out futures if the select times
		   * out. Finally retry read.
		   */
		  int rc2;
		  PROCESS_ALLOW_SCHEDULE ();
		  rc2 = check_inputs (PASS_G & atomic_timeout, 1);
		  if (rc2 == 0)
		    timeout_round (PASS_G ses);
		}
	      else
		{
		  SESSION_SCH_DATA (ses)->sio_random_read_ready_action = unfreeze_thread_read;
		  SESSION_SCH_DATA (ses)->sio_reading_thread = cur_proc;
		  add_to_served_sessions (ses);
		  semaphore_enter (cur_proc->thr_sem);
		}
	    }
	  else if (1 ||				 /* ?? */
	      SESSTAT_ISSET (ses->dks_session, SST_TIMED_OUT) || SESSTAT_ISSET (ses->dks_session, SST_BROKEN_CONNECTION))
	    {
	      SESSTAT_CLR (ses->dks_session, SST_OK);
	      SESSTAT_SET (ses->dks_session, SST_BROKEN_CONNECTION);

	      longjmp_splice (&(SESSION_SCH_DATA (ses)->sio_read_broken_context), 1);
	    }
	  else
	    {
	      ses->dks_bytes_received += last_read;

	      ss_dprintf_2 (("Unrecognized I/O error rc=%d errno=%d in service_read.", rc, errno));
	      longjmp_splice (&(SESSION_SCH_DATA (ses)->sio_read_broken_context), 1);
	    }
	}
    }
  ses->dks_bytes_received += last_read;
  return (last_read);
}