Пример #1
0
int main()
{
	char buf[1024];
	wml_init();
	wml_head();
	if (boarddetail_act(buf))
	{
		printf ("<card title=\"错误 -- %s\">", BBSNAME);
		printf ("<p>%s</p>");
	}
	wml_bar(0);
	printf ("</card>");
	wml_tail();
	return 0;
}
Пример #2
0
int main()
{
	char buf[256];
	wml_init();
	wml_head();
	if (bbsbrdchg_act(buf))
	{
		printf ("<card title=\"错误 -- %s\" >", BBSNAME);
		printf ("<p>%s</p>", buf);
	}
	printf ("<p><anchor><prev />返回上一页</anchor></p>");
	wml_bar(0);
	printf ("</card>");
	wml_tail();
	return 0;
}
Пример #3
0
int main()
{
    char buf[256];
    wml_init();
    wml_head();
    if (bbstopic_act(buf))
    {
        printf ("<card title=\"错误\" >");
        printf ("<p>%s</p>", buf);
    }
    printf ("<p><anchor><prev />返回</anchor></p>");
    wml_bar(0);
    printf ("</card>");
    wml_tail();
    return 0;
}
Пример #4
0
int main()
{
	wml_init();
	wml_head();
	int i, tmp, max, min;
	int z;
	char board[80];
	char buf[256], buf2[256], title[256];
	FILE * fp;
	struct rmd r;
	if (loginok)
	{
		wmlmode(u_info, SELECT);
	}
	z = atoi(getparm("zone"));
	if (!*(getparm("zone")) || z < -1 || z >= SECNUM)
	{
		z = -3;//list mode
	}
	strncpy(board, getparm("board"), 79);
	if (*board)//zone模式
	{
		z = -2;
	}
	if (z == -3)
	{
		printf ("<card title=\"选择讨论区 -- %s\" >", BBSNAME);
		printf ("<p>");
		min = 0;
		if (loginok)
		{
			min -= 2;
		}
		for (i = min; i < SECNUM; i++)
		{
			if (i == -2)
			{
				printf ("&#32;&#32;<anchor><go href=\"bbsboa.wml?zone=-1\" />我的收藏</anchor>");
			}
			else if ( i == -1)
			{
				printf ("&#32;&#32;<anchor><go href=\"bbsdoc.wml?board=%s\" />查看邮箱</anchor>", WML_VB_MAIL);
			}
			else
			{
				printf ("&#32;&#32;<anchor><go href=\"bbsboa.wml?zone=%d\" />%s</anchor>", i, secname[i][0]);
			}
			if ((i & 1) && (i < SECNUM - 1))
			{
				printf ("<br />");
			}
		}
		printf ("</p>");
		fp = fopen(PATHRMD, "rb");
		if (fp)
		{
			printf ("<p><em>精彩推荐</em><br />");
			while (fread (&r, sizeof(struct rmd), 1, fp))
			{
				w_hsprintf(buf, "%s", r.cn);
				printf ("<anchor><go href=\"bbscon.wml?board=%s&amp;file=%s\" />%s</anchor> <anchor><go href=\"bbsqry.wml?userid=%s\" />%s</anchor>@<anchor><go href=\"bbsdoc.wml?board=%s\" />%s</anchor><br />", r.board, r.en, buf, r.owner, r.owner, r.board, r.board);
			}
			printf ("</p>");
			fclose (fp);
		}
		fp = fopen("etc/posts/day", "rt");
		if (fp)
		{
			printf ("<p><em>十大热门话题</em><br />");
			fgets(buf, 255, fp);
			fgets(buf, 255, fp);//跳过两行开头
			for(i = 1; i <= 10; i++) 
			{
				if (!fgets(buf, 255, fp))
				{
					break;
				}
				sscanf (buf + 45, "%s", board);
				if (!fgets(buf, 255, fp))//话说,显示ID没有用啊,反正也老出错
				{
					break;
				}
				strsncpy (title, buf + 27, 60);
				rtrims(title);
				printf ("<anchor><go href=\"bbstopic.wml?board=%s&amp;topic=%s\" />", board, urlencode2(title));
				w_hsprintf(buf2, "%s", title);
				printf ("%s</anchor> <anchor><go href=\"bbsdoc.wml?board=%s\" />%s板</anchor> <br />", buf2, board, board);
			}
			fclose (fp);
			printf ("</p>");
		}
		printf ("<p><input name=\"inp_goto\" /><anchor><go href=\"bbssel.wml\" method=\"post\"><postfield name=\"goto\" value=\"$(inp_goto)\" /></go>带我去</anchor></p>");
		wml_bar(0);
		printf ("</card>");
	}
	else//板面
	{
		struct shortfile data[MAXBOARD], *x;
		int total, br;
		printf ("<card title=\"%s -- %s\">", (z >= 0 ? secname[z][0] : (z == -1 ? "我的收藏" : board)), BBSNAME);
		if (z == -1)
		{
			char mybrd[GOOD_BRC_NUM][80];
			int mybrdnum = 0;
			mybrdnum = LoadMyBrdsFromGoodBrd(currentuser.userid, mybrd);
			for(i=0; i<mybrdnum; i++) 
			{
				if(!(x=getbcache(mybrd[i])))
				{
					continue;
				}
				if(x->filename[0] <= 32 || x->filename[0] > 'z')
				{
					continue;
				}
				if(!has_read_perm(&currentuser, x->filename))
				{
					continue;
				}
				if(x->flag & ZONE_FLAG)
				{
					continue;
				}
				data[total++] = *x;
			}
		}
		else
		{
			for(i = 0; i < MAXBOARD; i++) 
			{
				x = &(shm_bcache->bcache[i]);
				if(x->filename[0] <= 32 || x->filename[0] > 'z')
				{
					continue;
				}
				if(!has_read_perm(&currentuser, x->filename))
				{
					continue;
				}
				if(z >= 0 && !strchr(seccode[z], x->title[0]))
				{
					continue;
				}
				if (z == -2)
					//这是某个子分区
				{
					if(!(x->flag & CHILDBOARD_FLAG) && strcasecmp(x->owner, board))
					{
						continue;
					}
				}
				else
					//这是某个分区
				{
					if(x->flag & CHILDBOARD_FLAG)
					{
						continue;
					}
				}
				if((x->flag & ZONE_FLAG) && !count_zone(BOARDS, x->filename))
				{
					continue;
				}
				//节约资源?
				memcpy(&data[total], x, sizeof(struct shortfile));
				total++;
			}
			qsort(data, total, sizeof(struct shortfile), cmpboard);
			//printf ("<p><anchor><go href=\"userindex.wml?zone=%d\" />本区导读</anchor></p>", z);
		}
		for (i = 0; i < total; i++)
		{
			printf ("<p>");
			br = board_read(data[i].filename);
			printf ("<anchor><go href=\"%s.wml?board=%s\" />", (data[i].flag & ZONE_FLAG) ? "bbsboa" : "bbsdoc", data[i].filename);
			if (!br)
			{
				printf ("<em>&#42;");
			}
			w_hprintf ("%s/%s", data[i].title + 10, data[i].filename);
			if (!br)
			{
				printf ("</em>");
			}
			printf ("</anchor></p>");
		}
		wml_bar(0);
		printf ("</card>");
	}
	wml_tail();
	return 0;
}
Пример #5
0
int main(int argc, char **argv)
{
    output_t outputti = NORMAL_OUT;
    FILE *fp = NULL;
    Octstr *output = NULL;
    Octstr *filename = NULL;
    Octstr *wml_text = NULL;
    Octstr *charset = NULL;
    Octstr *wml_binary = NULL;
    int i, ret = 0, opt, file = 0, zero = 0, numstatus = 0, wml_strict = 1;
    long num = 0;

    /* You can give an wml text file as an argument './wml_tester main.wml' */

    gwlib_init();

    while ((opt = getopt(argc, argv, "hsbzrn:f:c:")) != EOF) {
        switch (opt) {
        case 'h':
            help();
            exit(0);
        case 's':
            if (outputti == NORMAL_OUT)
                outputti = SOURCE_OUT;
            else {
                help();
                exit(0);
            }
            break;
        case 'b':
            if (outputti == NORMAL_OUT)
                outputti = BINARY_OUT;
            else {
                help();
                exit(0);
            }
            break;
        case 'z':
            zero = 1;
            break;
        case 'r':
            wml_strict = 0;
            break;
        case 'n':
            numstatus = octstr_parse_long(&num, octstr_imm(optarg), 0, 0);
            if (numstatus == -1) {
                /* Error in the octstr_parse_long */
                error(num, "Error in the handling of argument to option n");
                help();
                panic(0, "Stopping.");
            }
            break;
        case 'f':
            file = 1;
            filename = octstr_create(optarg);
            fp = fopen(optarg, "a");
            if (fp == NULL)
                panic(0, "Couldn't open output file.");
            break;
        case 'c':
            charset = octstr_create(optarg);
            break;
        case '?':
        default:
            error(0, "Invalid option %c", opt);
            help();
            panic(0, "Stopping.");
        }
    }

    if (optind >= argc) {
        error(0, "Missing arguments.");
        help();
        panic(0, "Stopping.");
    }

    if (outputti == BINARY_OUT)
        log_set_output_level(GW_PANIC);
    wml_init(wml_strict);

    while (optind < argc) {
        wml_text = octstr_read_file(argv[optind]);
        if (wml_text == NULL)
            panic(0, "Couldn't read WML source file.");

        if (zero)
            set_zero(wml_text);

        for (i = 0; i <= num; i++) {
            ret = wml_compile(wml_text, charset, &wml_binary, NULL);
            if (i < num)
                octstr_destroy(wml_binary);
        }
        optind++;

        output = octstr_format("wml_compile returned: %d\n\n", ret);

        if (ret == 0) {
            if (fp == NULL)
                fp = stdout;

            if (outputti != BINARY_OUT) {
                if (outputti == SOURCE_OUT) {
                    octstr_insert(output, wml_text, octstr_len(output));
                    octstr_append_char(output, '\n');
                }

                octstr_append(output, octstr_imm(
                                  "Here's the binary output: \n\n"));
                octstr_print(fp, output);
            }

            if (file && outputti != BINARY_OUT) {
                fclose(fp);
                log_open(octstr_get_cstr(filename), 0, GW_NON_EXCL);
                octstr_dump(wml_binary, 0);
                log_close_all();
                fp = fopen(octstr_get_cstr(filename), "a");
            } else if (outputti != BINARY_OUT)
                octstr_dump(wml_binary, 0);
            else
                octstr_print(fp, wml_binary);

            if (outputti != BINARY_OUT) {
                octstr_destroy(output);
                output = octstr_format("\n And as a text: \n\n");
                octstr_print(fp, output);

                octstr_pretty_print(fp, wml_binary);
                octstr_destroy(output);
                output = octstr_format("\n\n");
                octstr_print(fp, output);
            }
        }

        octstr_destroy(wml_text);
        octstr_destroy(output);
        octstr_destroy(wml_binary);
    }

    if (file) {
        fclose(fp);
        octstr_destroy(filename);
    }

    if (charset != NULL)
        octstr_destroy(charset);

    wml_shutdown();
    gwlib_shutdown();

    return ret;
}
Пример #6
0
int main(int argc, char **argv) 
{
    int cf_index;
    int restart = 0;
    Msg *msg;
    Cfg *cfg;
    double heartbeat_freq =  DEFAULT_HEARTBEAT;
    
    gwlib_init();
    cf_index = get_and_set_debugs(argc, argv, NULL);
    
    setup_signal_handlers();
    
    if (argv[cf_index] == NULL)
        config_filename = octstr_create("kannel.conf");
    else
        config_filename = octstr_create(argv[cf_index]);
    cfg = cfg_create(config_filename);

    if (cfg_read(cfg) == -1)
        panic(0, "Couldn't read configuration from `%s'.", octstr_get_cstr(config_filename));

    report_versions("wapbox");

    cfg = init_wapbox(cfg);

    info(0, "------------------------------------------------------------");
    info(0, GW_NAME " wapbox version %s starting up.", GW_VERSION);
    
    sequence_counter = counter_create();
    wsp_session_init(&wtp_resp_dispatch_event,
                     &wtp_initiator_dispatch_event,
                     &wap_appl_dispatch,
                     &wap_push_ppg_dispatch_event);
    wsp_unit_init(&dispatch_datagram, &wap_appl_dispatch);
    wsp_push_client_init(&wsp_push_client_dispatch_event, 
                         &wtp_resp_dispatch_event);
    
    if (cfg)
        wtp_initiator_init(&dispatch_datagram, &wsp_session_dispatch_event,
                           timer_freq);

    wtp_resp_init(&dispatch_datagram, &wsp_session_dispatch_event,
                  &wsp_push_client_dispatch_event, timer_freq);
    wap_appl_init(cfg);

#if (HAVE_WTLS_OPENSSL)
    wtls_secmgr_init();
    wtls_init(&write_to_bearerbox);
#endif
    
    if (cfg) {
        wap_push_ota_init(&wsp_session_dispatch_event, 
                          &wsp_unit_dispatch_event);
        wap_push_ppg_init(&wap_push_ota_dispatch_event, &wap_appl_dispatch, 
                          cfg);
    }
		
    wml_init(wml_xml_strict);
    
    if (bearerbox_host == NULL)
    	bearerbox_host = octstr_create(BB_DEFAULT_HOST);
    connect_to_bearerbox(bearerbox_host, bearerbox_port, bearerbox_ssl, NULL
		    /* bearerbox_our_port */);

    if (cfg)
        wap_push_ota_bb_address_set(bearerbox_host);
	    
    program_status = running;
    if (0 > heartbeat_start(write_to_bearerbox, heartbeat_freq, 
    	    	    	    	       wap_appl_get_load)) {
        info(0, GW_NAME "Could not start heartbeat.");
    }

    while (program_status != shutting_down) {
	WAPEvent *dgram;
        int ret;

        /* block infinite for reading messages */
        ret = read_from_bearerbox(&msg, INFINITE_TIME);
        if (ret == -1) {
            error(0, "Bearerbox is gone, restarting");
            program_status = shutting_down;
            restart = 1;
            break;
        } else if (ret == 1) /* timeout */
            continue;
        else if (msg == NULL) /* just to be sure, may not happens */
            break;
	if (msg_type(msg) == admin) {
	    if (msg->admin.command == cmd_shutdown) {
		info(0, "Bearerbox told us to die");
		program_status = shutting_down;
	    } else if (msg->admin.command == cmd_restart) {
		info(0, "Bearerbox told us to restart");
		restart = 1;
		program_status = shutting_down;
	    }
	    /*
	     * XXXX here should be suspend/resume, add RSN
	     */
	} else if (msg_type(msg) == wdp_datagram) {
        switch (msg->wdp_datagram.destination_port) {
        case CONNECTIONLESS_PORT:
        case CONNECTION_ORIENTED_PORT:
	    	dgram = wap_event_create(T_DUnitdata_Ind);
	    	dgram->u.T_DUnitdata_Ind.addr_tuple = wap_addr_tuple_create(
				msg->wdp_datagram.source_address,
				msg->wdp_datagram.source_port,
				msg->wdp_datagram.destination_address,
				msg->wdp_datagram.destination_port);
	    	dgram->u.T_DUnitdata_Ind.user_data = msg->wdp_datagram.user_data;
	    	msg->wdp_datagram.user_data = NULL;

          	wap_dispatch_datagram(dgram); 
			break;
        case WTLS_CONNECTIONLESS_PORT:
        case WTLS_CONNECTION_ORIENTED_PORT:
#if (HAVE_WTLS_OPENSSL)
            dgram = wtls_unpack_wdp_datagram(msg);
            if (dgram != NULL)
                wtls_dispatch_event(dgram);
#endif
			break;
        default:
                panic(0,"Bad packet received! This shouldn't happen!");
                break;
        } 
	} else {
	    warning(0, "Received other message than wdp/admin, ignoring!");
	}
	msg_destroy(msg);
    }

    info(0, GW_NAME " wapbox terminating.");
    
    program_status = shutting_down;
    heartbeat_stop(ALL_HEARTBEATS);
    counter_destroy(sequence_counter);

    if (cfg)
        wtp_initiator_shutdown();

    wtp_resp_shutdown();
    wsp_push_client_shutdown();
    wsp_unit_shutdown();
    wsp_session_shutdown();
    wap_appl_shutdown();
    radius_acct_shutdown();

    if (cfg) {
        wap_push_ota_shutdown();
        wap_push_ppg_shutdown();
    }

    wml_shutdown();
    close_connection_to_bearerbox();
    alog_close();
    wap_map_destroy();
    wap_map_user_destroy();
    octstr_destroy(device_home);
    octstr_destroy(bearerbox_host);
    octstr_destroy(config_filename);

    /*
     * Just sleep for a while to get bearerbox chance to restart.
     * Otherwise we will fail while trying to connect to bearerbox!
     */
    if (restart) {
        gwthread_sleep(10.0);
        /* now really restart */
        restart_box(argv);
    }

    log_close_all();
    gwlib_shutdown();

    return 0;
}