Exemple #1
0
static PyObject *
_diypy3__link_queue(PyObject *self, PyObject *args)
{
    int i;
    int rec_size;
    char *queue_str;
    char *str_slice_rec[LNKQ_MAXSIZE];
    char *deq;
    LNKQ Q;

    if (!PyArg_ParseTuple(args, "s", &queue_str))
        return NULL;
    rec_size = split_str(queue_str, str_slice_rec);
    temp_rec = str_slice_rec;
    if (!init_queue(&Q))
        return NULL;
    printf("linked list queue initialized\n");
    printf("\n");
    for (i = 0; i < rec_size; i++) {
        printf("enqueue: %s\n", temp_rec[i]);
        enqueue(&Q, temp_rec[i]);
    }
    while (Q.front != Q.rear) {
        printf("\nstatus: ");
        show_queue(Q);
        dequeue(&Q, &deq);
        printf("dequeue: %s\n", deq);
    }
    printf("\nwarning: empty queue\n");

    Py_RETURN_NONE;
}
Exemple #2
0
int main (int argc, char* argv[])
{
    int data;

    queue_array_init(&q, array, sizeof(int), QUEUE_LENGTH);
    show_queue(&q);

    data = 0x055;
    queue_array_fill(&q, &data, 2);
    show_queue(&q);

    for (int i = 0; i < QUEUE_LENGTH; i++) {
        int res;
        if ((res = queue_array_write(&q, &i, 1)) <= 0) {
            printf("queue_array_write: return = %d, i = %d\n", res, i);
        }
    }
    printf("queue_array_length: %d\n", queue_array_length(&q));
    show_queue(&q);
    printf("queue_array_length: %d\n", queue_array_length(&q));

    pthread_t tid;

    pthread_create(&tid, NULL, thread_read, NULL);

    int buff[100];
    for (int i = 0; i < 100; i++) {
        buff[i] = i;
    }

    // write
    while (true) {
        int wr = 0, res;

        while (wr < 100) {
            if ((res = queue_array_write(&q, buff + wr, 100 - wr)) > 0) {
                wr += res;
            } else {
                usleep(20);
            }
        }

        sleep(2);
    }

    return 0;
}
Exemple #3
0
int main()
{
    int x;
    pnode queue = NULL;
    init_queue(&queue);
    while (1) {
        scanf("%d", &x);
        queue_in(queue, x);
        show_queue(queue);
        scanf("%d", &x);
        queue_in(queue, x);
        show_queue(queue);

        queue_out(queue);
        show_queue(queue);
        printf("***************************\n");
    }
    return 0;
}
Exemple #4
0
int     main(int argc, char **argv)
{
    struct stat st;
    char   *slash;
    int     c;
    int     fd;
    int     mode = PQ_MODE_DEFAULT;
    char   *site_to_flush = 0;
    char   *id_to_flush = 0;
    ARGV   *import_env;
    int     bad_site;

    /*
     * Fingerprint executables and core dumps.
     */
    MAIL_VERSION_STAMP_ALLOCATE;

    /*
     * Be consistent with file permissions.
     */
    umask(022);

    /*
     * To minimize confusion, make sure that the standard file descriptors
     * are open before opening anything else. XXX Work around for 44BSD where
     * fstat can return EBADF on an open file descriptor.
     */
    for (fd = 0; fd < 3; fd++)
	if (fstat(fd, &st) == -1
	    && (close(fd), open("/dev/null", O_RDWR, 0)) != fd)
	    msg_fatal_status(EX_UNAVAILABLE, "open /dev/null: %m");

    /*
     * Initialize. Set up logging, read the global configuration file and
     * extract configuration information. Set up signal handlers so that we
     * can clean up incomplete output.
     */
    if ((slash = strrchr(argv[0], '/')) != 0 && slash[1])
	argv[0] = slash + 1;
    msg_vstream_init(argv[0], VSTREAM_ERR);
    msg_cleanup(unavailable);
    msg_syslog_init(mail_task("postqueue"), LOG_PID, LOG_FACILITY);
    set_mail_conf_str(VAR_PROCNAME, var_procname = mystrdup(argv[0]));

    /*
     * Check the Postfix library version as soon as we enable logging.
     */
    MAIL_VERSION_CHECK;

    /*
     * Parse JCL. This program is set-gid and must sanitize all command-line
     * parameters. The configuration directory argument is validated by the
     * mail configuration read routine. Don't do complex things until we have
     * completed initializations.
     */
    while ((c = GETOPT(argc, argv, "c:fi:ps:v")) > 0) {
	switch (c) {
	case 'c':				/* non-default configuration */
	    if (setenv(CONF_ENV_PATH, optarg, 1) < 0)
		msg_fatal_status(EX_UNAVAILABLE, "out of memory");
	    break;
	case 'f':				/* flush queue */
	    if (mode != PQ_MODE_DEFAULT)
		usage();
	    mode = PQ_MODE_FLUSH_QUEUE;
	    break;
	case 'i':				/* flush queue file */
	    if (mode != PQ_MODE_DEFAULT)
		usage();
	    mode = PQ_MODE_FLUSH_FILE;
	    id_to_flush = optarg;
	    break;
	case 'p':				/* traditional mailq */
	    if (mode != PQ_MODE_DEFAULT)
		usage();
	    mode = PQ_MODE_MAILQ_LIST;
	    break;
	case 's':				/* flush site */
	    if (mode != PQ_MODE_DEFAULT)
		usage();
	    mode = PQ_MODE_FLUSH_SITE;
	    site_to_flush = optarg;
	    break;
	case 'v':
	    if (geteuid() == 0)
		msg_verbose++;
	    break;
	default:
	    usage();
	}
    }
    if (argc > optind)
	usage();

    /*
     * Further initialization...
     */
    mail_conf_read();
    /* Re-evaluate mail_task() after reading main.cf. */
    msg_syslog_init(mail_task("postqueue"), LOG_PID, LOG_FACILITY);
    mail_dict_init();				/* proxy, sql, ldap */
    get_mail_conf_str_table(str_table);

    /*
     * This program is designed to be set-gid, which makes it a potential
     * target for attack. If not running as root, strip the environment so we
     * don't have to trust the C library. If running as root, don't strip the
     * environment so that showq can receive non-default configuration
     * directory info when the mail system is down.
     */
    if (geteuid() != 0) {
	import_env = mail_parm_split(VAR_IMPORT_ENVIRON, var_import_environ);
	clean_env(import_env->argv);
	argv_free(import_env);
    }
    if (chdir(var_queue_dir))
	msg_fatal_status(EX_UNAVAILABLE, "chdir %s: %m", var_queue_dir);

    signal(SIGPIPE, SIG_IGN);

    /* End of initializations. */

    /*
     * Further input validation.
     */
    if (site_to_flush != 0) {
	bad_site = 0;
	if (*site_to_flush == '[') {
	    bad_site = !valid_mailhost_literal(site_to_flush, DONT_GRIPE);
	} else {
	    bad_site = !valid_hostname(site_to_flush, DONT_GRIPE);
	}
	if (bad_site)
	    msg_fatal_status(EX_USAGE,
	      "Cannot flush mail queue - invalid destination: \"%.100s%s\"",
		   site_to_flush, strlen(site_to_flush) > 100 ? "..." : "");
    }
    if (id_to_flush != 0) {
	if (!mail_queue_id_ok(id_to_flush))
	    msg_fatal_status(EX_USAGE,
		       "Cannot flush queue ID - invalid name: \"%.100s%s\"",
		       id_to_flush, strlen(id_to_flush) > 100 ? "..." : "");
    }

    /*
     * Start processing.
     */
    switch (mode) {
    default:
	msg_panic("unknown operation mode: %d", mode);
	/* NOTREACHED */
    case PQ_MODE_MAILQ_LIST:
	show_queue();
	exit(0);
	break;
    case PQ_MODE_FLUSH_SITE:
	flush_site(site_to_flush);
	exit(0);
	break;
    case PQ_MODE_FLUSH_FILE:
	flush_file(id_to_flush);
	exit(0);
	break;
    case PQ_MODE_FLUSH_QUEUE:
	flush_queue();
	exit(0);
	break;
    case PQ_MODE_DEFAULT:
	usage();
	/* NOTREACHED */
    }
}
Exemple #5
0
int ShowQueryPage()
{
	struct list *lpublic;	/*解析public.txt文件的链表头*/
	struct list *lcontrol; 	/*解析help.txt文件的链表头*/
	lpublic=get_chain_head("../htdocs/text/public.txt");
    	lcontrol=get_chain_head("../htdocs/text/control.txt"); 	
  	char *encry=(char *)malloc(BUF_LEN);
  	char *str;
  //FILE *fp;
  //char lan[3];
	  char policer_encry[BUF_LEN]; 
	  char addn[N];        
	  char * mode=(char *)malloc(AMOUNT);
	  memset(mode,0,AMOUNT);
	  int i=0;   
	  int cl=1;
  	int retu=0;
  	int select_flag=0;
  	//char menu[21]="menulist";
  	char* i_char=(char *)malloc(10);
  	char * group=(char * )malloc(10);
  	memset(group,0,10);
  	char * QueryID=(char * )malloc(10);
  	memset(QueryID,0,10);
  	char * wrr_weight=(char * )malloc(10);
  	memset(wrr_weight,0,10);
  	int qos_num=0;
  	char * queue_mode=(char * )malloc(10);
  	memset(queue_mode,0,10);
	char * radiobutton=(char *)malloc(10);
	memset(radiobutton,0,10);
	cgiFormString("radiobutton", radiobutton, 10);

  	struct qos_info receive_qos[MAX_QOS_PROFILE];
  	struct query_info query_info[8];
  	int flag[8];
  	for(i=0;i<8;i++)
    	{
    		flag[i]=0;
    	}
	
  	for(i=0;i<MAX_QOS_PROFILE;i++)
	{
		receive_qos[i].profileindex=0;
		receive_qos[i].dp=0;
		receive_qos[i].up=0;
		receive_qos[i].tc=10;
		receive_qos[i].dscp=0;
	}
  	ccgi_dbus_init();
  	memset(encry,0,BUF_LEN);
  	if(cgiFormStringNoNewlines("UN", encry, BUF_LEN)!=cgiFormNotFound )  /*首次进入该页*/
  	{
    		str=dcryption(encry);
    		if(str==NULL)
    		{
	      		ShowErrorPage(search(lpublic,"ill_user")); 	 /*用户非法*/
	      		return 0;
		}
		strcpy(addn,str);
		memset(policer_encry,0,BUF_LEN);                   /*清空临时变量*/
  	}
  	else
  	{
	     cgiFormStringNoNewlines("encry_configqueue",encry,BUF_LEN);
	     cgiFormStringNoNewlines("group",group,10);
	     cgiFormStringNoNewlines("QueryID",QueryID,10);
	     cgiFormStringNoNewlines("wrr_weight",wrr_weight,10);
	     cgiFormStringNoNewlines("queue_mode",queue_mode,10);
	     cgiFormStringNoNewlines("CheckUsr",addn,10);
	}

  cgiHeaderContentType("text/html");
  fprintf(cgiOut,"<html xmlns=\"http://www.w3.org/1999/xhtml\"><head>");
  fprintf(cgiOut,"<meta http-equiv=Content-Type content=text/html; charset=gb2312>");
  fprintf(cgiOut,"<title>%s</title>",search(lcontrol,"route_manage"));
  fprintf(cgiOut,"<link rel=stylesheet href=/style.css type=text/css>"\
  	"<style type=text/css>"\
  	  "#div1{ width:62px; height:18px; border:1px solid #666666; background-color:#f9f8f7;}"\
	  "#div2{ width:60px; height:15px; padding-left:5px; padding-top:3px}"\
	  "#link{ text-decoration:none; font-size: 12px}"\
  	".ShowPolicy {overflow-x:hidden;  overflow:auto; width: 580px; height: 236px; clip: rect( ); padding-top: 2px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px} "\
  	"</style>"\
  "</head>"\
    "<script type=\"text/javascript\">"\
			  "function popMenu(objId)"\
			  "{"\
				 "var obj = document.getElementById(objId);"\
				 "if (obj.style.display == 'none')"\
				 "{"\
				   "obj.style.display = 'block';"\
				 "}"\
				 "else"\
				 "{"\
				   "obj.style.display = 'none';"\
				 "}"\
			 "}"\
	"</script>"\
  "<body>");

 
  	 retu=checkuser_group(addn);

   	if(cgiFormSubmitClicked("submit_config_query") == cgiFormSuccess)
  	{
  		int ret=0;
  		if(strcmp(queue_mode,"sp")==0)
  		{
  			set_queue_scheduler(queue_mode);
  		}
  		else if(strcmp(queue_mode,"wrr")==0)
  		{
  			if(strcmp(wrr_weight,"")!=0)
  			{
     				set_queue_scheduler(queue_mode);
				if(strcmp(QueryID,"")!=0)
				{
	     			ret=set_wrr_queue(group,QueryID,wrr_weight,1);	     				
	     				
					if(ret==0)
					{
						ShowAlert(search(lcontrol,"config_queue_succ"));
					}
					else 
					{
						ShowAlert(search(lcontrol,"counterconfigfail"));
					}
				}
				else
				{
					ShowAlert(search(lcontrol,"pls_create_profile"));
				}
  			}
  			else
  			{
				ShowAlert(search(lcontrol,"weight_not_null"));
  			}
  				
  		}
  		else if(strcmp(queue_mode,"sp+wrr")==0)
  		{
  			char * temp=(char * )malloc(10);
  			memset(temp,0,10);
  			strcpy(temp,"hybrid");
			if(strcmp(radiobutton,"val")==0)
			{
	  			if(strcmp(wrr_weight,"")!=0)
	  			{
	     				set_queue_scheduler(temp);
					if(strcmp(QueryID,"")!=0)
					{
		   				ret=set_wrr_queue(group,QueryID,wrr_weight,2);		   				
						if(ret==0)
						{
							ShowAlert(search(lcontrol,"config_queue_succ"));
						}
						else 
						{
							ShowAlert(search(lcontrol,"counterconfigfail"));
						}
					}
					else
					{
						ShowAlert(search(lcontrol,"pls_create_profile"));
					}
				}
				else
				{
					ShowAlert(search(lcontrol,"weight_not_null"));
				}	
			}
			else if(strcmp(radiobutton,"sp")==0)
			{
				set_queue_scheduler(temp);
				if(strcmp(QueryID,"")!=0)
				{
					ret=set_wrr_queue(group,QueryID,"sp",2);					
				    if(ret==0)
					{
						ShowAlert(search(lcontrol,"config_queue_succ"));
					}
					else 
					{
						ShowAlert(search(lcontrol,"counterconfigfail"));
					}

				}
				else
				{
					ShowAlert(search(lcontrol,"pls_create_profile"));
				}
			}
			else
			{
				ShowAlert(search(lcontrol,"select_sp_weight"));
			}
  			free(temp);	
  		}
  	}

	show_qos_mode(mode);
  fprintf(cgiOut,"<form method=post>"\
  "<div align=center>"\
  "<table width=976 border=0 cellpadding=0 cellspacing=0>"\
  "<tr>"\
    "<td width=8 align=left valign=top background=/images/di22.jpg><img src=/images/youce4.jpg width=8 height=30/></td>"\
    "<td width=51 align=left valign=bottom background=/images/di22.jpg><img src=/images/youce33.jpg width=37 height=24/></td>"\
    "<td width=153 align=left valign=bottom background=/images/di22.jpg><font id=titleen>QOS</font><font id=%s> %s</font></td>",search(lpublic,"title_style"),search(lpublic,"management"));
    fprintf(cgiOut,"<td width=690 align=right valign=bottom background=/images/di22.jpg>");
    	  fprintf(cgiOut,"<table width=130 border=0 cellspacing=0 cellpadding=0>"\
          "<tr>"\
          "<td width=62 align=center><input id=but type=submit name=submit_config_query style=background-image:url(/images/%s) value=""></td>",search(lpublic,"img_ok"));		  
          
		  if(cgiFormSubmitClicked("submit_config_query") != cgiFormSuccess)
		  {
            fprintf(cgiOut,"<td width=62 align=left><a href=wp_qosModule.cgi?UN=%s target=mainFrame><img src=/images/%s border=0 width=62 height=20/></a></td>",encry,search(lpublic,"img_cancel"));
           
            }
		  else                                         
     		fprintf(cgiOut,"<td width=62 align=left><a href=wp_qosModule.cgi?UN=%s target=mainFrame><img src=/images/%s border=0 width=62 height=20/></a></td>",encry,search(lpublic,"img_cancel"));
		  fprintf(cgiOut,"</tr>"\
          "</table>");
	fprintf(cgiOut,"</td>"\
    "<td width=74 align=right valign=top background=/images/di22.jpg><img src=/images/youce3.jpg width=31 height=30/></td>"\
  "</tr>"\
  "<tr>"\
    "<td colspan=5 align=center valign=middle><table width=976 border=0 cellpadding=0 cellspacing=0 bgcolor=#f0eff0>"\
      "<tr>"\
        "<td width=12 align=left valign=top background=/images/di888.jpg>&nbsp;</td>"\
        "<td width=948><table width=947 border=0 cellspacing=0 cellpadding=0>"\
            "<tr height=4 valign=bottom>"\
              "<td width=120>&nbsp;</td>"\
              "<td width=827 valign=bottom><img src=/images/bottom_05.gif width=827 height=4/></td>"\
            "</tr>"\
            "<tr>"\
              "<td><table width=120 border=0 cellspacing=0 cellpadding=0>"\
                   "<tr height=25>"\
                    "<td id=tdleft>&nbsp;</td>"\
                  "</tr>");       			
                  
     			fprintf(cgiOut,"<tr height=26>"\
     			"<td align=left id=tdleft background=/images/bottom_bg.gif style=\"border-right:0\"><font id=%s>%s</font></td>",search(lpublic,"menu_san"),search(lcontrol,"config_queue_list"));   /*突出显示*/
     			fprintf(cgiOut,"</tr>");
				int rowsCount=0;
				if(retu==0)
					rowsCount=16;
				else rowsCount=12;
				for(i=0;i<rowsCount+2;i++)
					{
						fprintf(cgiOut,"<tr height=25>"\
						  "<td id=tdleft>&nbsp;</td>"\
						"</tr>");
					}
				  fprintf(cgiOut,"</table>"\
              "</td>"\
              "<td align=left valign=top style=\"background-color:#ffffff; border-right:1px solid #707070; padding-left:30px; padding-top:10px\">"\
						"<table width=640 height=310 border=0 cellspacing=0 cellpadding=0>");
				  fprintf(cgiOut,"<tr height='35'>\n"\
				  				"<td style=\"font-size:14px\"><font color='red'><b>%s</b></font></td>"\
				  			  "</tr>\n",search(lcontrol,mode));
						if(retu==0)
						{
    						fprintf(cgiOut,"<tr>"\
    						"<td id=sec1 style=\"border-bottom:2px solid #53868b;font-size:14px\">%s</td>",search(lcontrol,"config_query_mode"));
    						fprintf(cgiOut,"</tr>"\
    						"<tr>"\
    						"<td><table frame=below rules=rows width=440 height=70 border=1>");
    						show_qos_profile(receive_qos,&qos_num,lcontrol);
    						for(i=0;i<qos_num;i++)
    						{
    							if(receive_qos[i].tc!=10)
    							{
    								flag[receive_qos[i].tc]=1;
								select_flag++;
    							}
    						}
    						fprintf(cgiOut,"<tr height=25 align=left  style=padding-top:8px>");
    						    fprintf(cgiOut,"<td id=td1 width=110>%s:</td>",search(lcontrol,"queue_mode"));
    						    fprintf(cgiOut,"<td  align=left style=padding-left:10px colspan=7><select name=queue_mode onchange=\"javascript:this.form.submit();\">");
    						    for(i=0;i<((get_product_id()==PRODUCT_ID_AU3K_BCM)?2:3);i++)
    							if(strcmp(Queue_Scheduler[i],queue_mode)==0)				/*显示上次选中的*/
    								fprintf(cgiOut,"<option value=%s selected=selected>%s",Queue_Scheduler[i],Queue_Scheduler[i]);
    							else				
    								fprintf(cgiOut,"<option value=%s>%s",Queue_Scheduler[i],Queue_Scheduler[i]);
    						    fprintf(cgiOut,"</select>");
    						    fprintf(cgiOut,"</td>");
    						    int Queue_Schedulerchoice=0;
    							cgiFormSelectSingle("queue_mode", Queue_Scheduler, 3, &Queue_Schedulerchoice, 0);
    						   	fprintf(cgiOut,"</tr>");
    							if(Queue_Schedulerchoice==2 || Queue_Schedulerchoice==1)
    							{
    								fprintf(cgiOut,"<tr height=25 align=left  style=padding-top:8px>");
    								fprintf(cgiOut,"<td  align=left style=padding-left:10px colspan=3>");
								if(get_product_id()!=PRODUCT_ID_AU3K_BCM)
								{
									fprintf(cgiOut,"<select name=group>");
        						    			fprintf(cgiOut,"<option value=%s>%s","group1","group1");
        						    			fprintf(cgiOut,"<option value=%s>%s","group2","group2");
        						    		fprintf(cgiOut,"</select>");
								}
								else
								{
									fprintf(cgiOut,"<input type=hidden name=group value=group1><b>group1</b>");
								}
        						    	fprintf(cgiOut,"</td>");
        						    fprintf(cgiOut,"<td id=td1>%s:</td>",search(lcontrol,"queue_TC"));
    								fprintf(cgiOut,"<td  align=left style=padding-left:10px colspan=3>\n");
								if(select_flag!=0)
								{
									fprintf(cgiOut,"<select name=QueryID>");
    									for(i=0;i<8;i++)
    									{
    										if(flag[i]==1)
    										{
    											fprintf(cgiOut,"<option value=%d>%d",i,i);
    										}
    									}
        						    		fprintf(cgiOut,"</select>");
								}
								else
								{
									fprintf(cgiOut,"<font color='red'>%s</font>",search(lcontrol,"not_create_qos_profile"));
								}
        						    fprintf(cgiOut,"</td>");
//***************************************************changed here**********************************************************
								if(Queue_Schedulerchoice==1)
								{
	    								fprintf(cgiOut,"<td id=td1>%s:</td>",search(lcontrol,"weight"));
	    								fprintf(cgiOut,"<td><input type=text name=wrr_weight size=8></td>");
								}
								else if(Queue_Schedulerchoice==2)
								{
	    								fprintf(cgiOut,"<td id=td1><input type=radio name=radiobutton value='val' checked />%s:</td>",search(lcontrol,"weight"));
	    								fprintf(cgiOut,"<td><input type=text name=wrr_weight size=8></td>");
									fprintf(cgiOut,"<td id=td1><input type=radio name=radiobutton value='sp' />sp</td>");
								}
//**********************************************************************************************************************************************************
    								fprintf(cgiOut,"</tr>");
    							}
    						fprintf(cgiOut,"</table>"\
    						"</td>"\
    						"</tr>");
						}
						fprintf(cgiOut,"<tr style=padding-top:18px>"\
						"<td id=sec1 style=\"border-bottom:2px solid #53868b;font-size:14px\">%s</td>",search(lcontrol,"config_queue_list"));
						fprintf(cgiOut,"</tr>"\
						 "<tr>"\
						   "<td align=left valign=top style=padding-top:18px>"\
						   "<div class=ShowPolicy><table width=320 border=1 frame=below rules=rows bordercolor=#cccccc cellspacing=0 cellpadding=0>");
						   fprintf(cgiOut,"<tr height=30 bgcolor=#eaeff9 style=font-size:14px  id=td1  align=left>"\
							 "<th width=90><font id=%s>%s</font></th>", search(lpublic,"menu_thead"),search(lcontrol,"queue_TC"));
							 fprintf(cgiOut,"<th width=120><font id=%s>%s</font></th>", search(lpublic,"menu_thead"),search(lcontrol,"Scheduling_Group"));
							 fprintf(cgiOut,"<th width=70><font id=%s>%s</font></th>", search(lpublic,"menu_thead"),search(lcontrol,"weight"));
							 fprintf(cgiOut,"</tr>");
							 for(i=0;i<8;i++)
			                              {
			                              	flag[i]=0;
			                              	query_info[i].QID=0;
			                              	query_info[i].Scheduling_group=(char * )malloc(10);
			                              	memset(query_info[i].Scheduling_group,0,10);
			                              	query_info[i].weight=0;
			                              }
							show_queue(query_info);
							for(i=0;i<8;i++)
							{
								/*memset(menu,0,21);
							  	strcpy(menu,"menulist");
							  	sprintf(i_char,"%d",i+1);
							  	strcat(menu,i_char);*/

								fprintf(cgiOut,"<tr height=25 bgcolor=%s align=left>",setclour(cl));
								 fprintf(cgiOut,"<td>%u</td>",query_info[i].QID);
								 fprintf(cgiOut,"<td>%s</td>",query_info[i].Scheduling_group);
								 fprintf(cgiOut,"<td>%u</td>",query_info[i].weight); 
								 fprintf(cgiOut,"</tr>");
								 cl=!cl;
							}
							 
						  	fprintf(cgiOut,"</table></div>"\
							 "</td>"\
						   "</tr>"\
						 
						"<tr>"\
						"<td id=sec1 style=\"border-bottom:2px solid #53868b;font-size:14px\">%s</td>",search(lpublic,"description"));
						fprintf(cgiOut,"</tr>"\
						 "<tr height=25 style=padding-top:2px>"\
			   			"<td style=font-size:14px;color:#FF0000>%s</td>",search(lcontrol,"queue_TC_des"));
			   			fprintf(cgiOut,"</tr>"\
			   			
						/*"<tr>"\
						"<td>"\
						"<table width=430 style=padding-top:2px>"\
						"<tr>");
						sprintf(pageNumCA,"%d",pageNum+1);
						sprintf(pageNumCD,"%d",pageNum-1);
						if(cgiFormSubmitClicked("submit_config_query") != cgiFormSuccess)
							{
								fprintf(cgiOut,"<td align=center style=padding-top:2px><a href=wp_srouter.cgi?UN=%s&PN=%s&SN=%s>%s</td>",encry,pageNumCA,"PageDown",search(lcontrol,"page_down"));
								fprintf(cgiOut,"<td align=center style=padding-top:2px><a href=wp_srouter.cgi?UN=%s&PN=%s&SN=%s>%s</td>",encry,pageNumCD,"PageUp",search(lcontrol,"page_up"));
							}
						else if(cgiFormSubmitClicked("submit_config_query") == cgiFormSuccess)
							{
								fprintf(cgiOut,"<td align=center style=padding-top:2px><a href=wp_srouter.cgi?UN=%s&PN=%s&SN=%s>%s</td>",policer_encry,pageNumCA,"PageDown",search(lcontrol,"page_down"));
								fprintf(cgiOut,"<td align=center style=padding-top:2px><a href=wp_srouter.cgi?UN=%s&PN=%s&SN=%s>%s</td>",policer_encry,pageNumCD,"PageUp",search(lcontrol,"page_up"));  
							}
						fprintf(cgiOut,"</tr></table></td>"\
						"</tr>"\*/
						 "<tr>");
						 if(cgiFormSubmitClicked("submit_config_query") != cgiFormSuccess)
						 {
						   fprintf(cgiOut,"<td colspan=6><input type=hidden name=encry_configqueue value=%s></td>",encry);
						   fprintf(cgiOut,"<td><input type=hidden name=CheckUsr value=%s></td>",addn);
						 }
						 else if(cgiFormSubmitClicked("submit_config_query") == cgiFormSuccess)
							 {
							   fprintf(cgiOut,"<td colspan=6><input type=hidden name=encry_configqueue value=%s></td>",encry);
							   fprintf(cgiOut,"<td><input type=hidden name=CheckUsr value=%s></td>",addn);
							 }
						 fprintf(cgiOut,"</tr>"\
					  "</table>"\

              "</td>"\
            "</tr>"\
            "<tr height=4 valign=top>"\
              "<td width=120 height=4 align=right valign=top><img src=/images/bottom_07.gif width=1 height=10/></td>"\
              "<td width=827 height=4 valign=top bgcolor=#FFFFFF><img src=/images/bottom_06.gif width=827 height=15/></td>"\
            "</tr>"\
          "</table>"\
        "</td>"\
        "<td width=15 background=/images/di999.jpg>&nbsp;</td>"\
      "</tr>"\
    "</table></td>"\
  "</tr>"\
  "<tr>"\
    "<td colspan=3 align=left valign=top background=/images/di777.jpg><img src=/images/di555.jpg width=61 height=62/></td>"\
    "<td align=left valign=top background=/images/di777.jpg>&nbsp;</td>"\
    "<td align=left valign=top background=/images/di777.jpg><img src=/images/di666.jpg width=74 height=62/></td>"\
  "</tr>"\
"</table>"\
"</div>"\
"</form>"\
"</body>"\
"</html>");  
free(encry);
free(i_char);
for(i=0;i<8;i++)
{
	free(query_info[i].Scheduling_group);
}
free(group);
free(QueryID);
free(wrr_weight);
free(queue_mode);
release(lpublic);  
release(lcontrol);
free(mode);
return 0;
}
Exemple #6
0
int main()
{
    /*
    Rule of thumb

    read information from the text file

    所有學生錄取第一志願
    超額比序,多的進入queue
    */
    FILE *pStudentData = get_student_txt_fp();
    FILE *pDepartmentData = get_department_txt_fp();

#if DEBUG
    show_student_txt(pStudentData);
    show_department_txt(pDepartmentData);
#endif

    // read all student data to queue
    Student *student_head = NULL; // head == null --> empty
    student_head = enqueue_all_student_records(pStudentData);

#if DEBUG
    show_queue(student_head);

    /*
    //try queue pop(), clear and free all node
    while (student_head) {
        printf("Pop a node out from queue\n");
        student_head = pop(student_head);
        show_queue(student_head);
    }
    */
#endif

    // read all data from department.txt
    Department *department_head = load_department_data(pDepartmentData);

#if DEBUG
    show_all_node(department_head);
#endif
    /*
    initial condition
        all of the student data is in queue
        all of the department data is in a linked list
    */

    // query system UI
    printf("Before processing data, what do you want to do?\n");
    printf("\n(I)nsert, (D)elete, (E)dit, (S)earch, (W)rite to file, (L)ist "
           "all(from file), \n"
           "or press any other key to continue...\n> ");
    char choice[100];
    while (1) {
        while (fgets(choice, 100, stdin) == NULL || choice[0] == '\n') {
            printf("\n(I)nsert, (D)elete, (E)dit, (S)earch, (W)rite to file, (L)ist "
                   "all(from file), \n"
                   "or press any other key to continue...\n> ");
        }
        if (choice[0] == 'I' || choice[0] == 'i') {
            clear_screen();
            printf("Insert! Insert (S)tudent or (D)epartment?\n> ");

            char c;
            long long int ID;
            scanf("%c", &c);

            if (c == 's' || c == 'S') {
                printf("ID to insert? ");
                scanf("%lld", &ID);
                getchar();
                student_head = insert_student_data(student_head, ID);
            } else if (c == 'd' || c == 'D') {
                printf("ID to insert? ");
                scanf("%lld", &ID);
                getchar();
                department_head = insert_department_data(department_head, ID);
            } else {
                printf("Invalid choice\n");
            }
        } else if (choice[0] == 'D' || choice[0] == 'd') {
            clear_screen();
            printf("Delete! Delete (S)tudent or (D)epartment? (C)ancel?\n> ");

            char c;
            long long int ID;
            scanf("%c", &c);
            if (c == 'c' || c == 'C') {
                printf("Operation cancelled\n");
                continue;
            }

            if (c == 's' || c == 'S') {
                printf("ID to delete? ");
                scanf("%lld", &ID);
                getchar();
                student_head = delete_student_data(student_head, ID);
            } else if (c == 'd' || c == 'D') {
                printf("ID to delete? ");
                scanf("%lld", &ID);
                getchar();
                department_head = delete_department_data(department_head, ID);
            } else {
                printf("Invalid choice\n");
            }

        } else if (choice[0] == 'E' || choice[0] == 'e') {
            clear_screen();
            printf("Edit! Edit (S)tudent or (D)epartment?\n> ");

            char c;
            long long int ID;
            scanf("%c", &c);

            if (c == 's' || c == 'S') {
                printf("ID to modify? ");
                scanf("%lld", &ID);
                getchar();
                edit_student_data(student_head, ID);
            } else if (c == 'd' || c == 'D') {
                printf("ID to modify? ");
                scanf("%lld", &ID);
                getchar();
                edit_department_data(department_head, ID);
            } else {
                printf("Invalid choice\n");
            }
        } else if (choice[0] == 'S' || choice[0] == 's') {
            clear_screen();
            printf("Search! Search (S)tudent or (D)epartment by ID?\n> ");
            char c;
            long long int ID;
            scanf("%c %lld", &c, &ID);
            getchar();
            if (c == 's' || c == 'S')
                search_node(c, student_head, ID);
            else if (c == 'd' || c == 'D')
                search_node(c, department_head, ID);
            else
                printf("Invalid choice\n");
        } else if (choice[0] == 'W' || choice[0] == 'w') {
            clear_screen();
            printf("Save file! Save (S)tudent or (D)epartment data to file?\n> ");
            char c;
            scanf("%c", &c);
            getchar();
            if (c == 's' || c == 'S') {
                // close FILE stream first, and then get new one from the function
                fclose(pStudentData);
                pStudentData = save_student_data(student_head);
            } else if (c == 'd' || c == 'D') {
                fclose(pDepartmentData);
                pDepartmentData = save_department_data(department_head);
            } else {
                printf("Invalid choice\n");
            }
        } else if (choice[0] == 'L' || choice[0] == 'l') {
            clear_screen();
            printf("List all data! List (S)tudent or (D)epartment data?\n> ");
            char c;
            scanf("%c", &c);
            getchar();
            printf("First from file then from memory!\n");
            if (c == 's' || c == 'S') {
                // reopen FLIE stream to get latest data
                fclose(pStudentData);
                pStudentData = get_student_txt_fp();
                show_student_txt(pStudentData);

                show_queue(student_head);
            } else if (c == 'd' || c == 'D') {
                fclose(pDepartmentData);
                pDepartmentData = get_department_txt_fp();
                show_department_txt(pDepartmentData);

                show_all_node(department_head);
            } else {
                printf("Invalid choice\n");
            }
        } else {
            printf("Are you sure to move on?[y/n]\n");
            char c;
            c = getchar();
            if (c == 'n' || c == 'N') {
                continue;
            }

            clear_screen();
            printf("Automatically saving changes for you...\n");
            fclose(pStudentData);
            pStudentData = save_student_data(student_head);
            fclose(pDepartmentData);
            pDepartmentData = save_department_data(department_head);

            printf("Let's move on......\n");
            break;
        }

        printf("\n(I)nsert, (D)elete, (E)dit, (S)earch, (W)rite to file, (L)ist "
               "all, \n"
               "or press any other key to continue...\n> ");
    }

    /*
    All update-to-date information of students and departments is in the memory
    and saved to respective text files.

    Now it's time to implement the ranking system!
    */

    if (student_head == NULL || department_head == NULL) {
        printf("There isn't sufficient to keep the system running!\n"
               "Terminating the program\n");
        exit(0);
    }

    // need to set terminating condition
    clear_screen();
    int total_round = 0;
    while (student_head) { // when the queue is empty, the work is done!
#if DEBUG
        printf("start round %d\n", total_round);
#endif
        // put all students from queue to the corresponding department
        while (student_head) {
            // copy the front student node, and then attach to the corresponding
            // department
            Student *new_node = calloc(1, sizeof(Student));
            if (new_node == NULL) {
                CALLOC_ERROR;
                exit(0);
            }
            memcpy(new_node, student_head, sizeof(Student));
#if DEBUG
            printf("department_head %p\n", department_head);
            printf("\n\nBefore processing\n\n");
            show_queue(student_head);
            show_all_node(department_head);
            printf("\n\n");
#endif
            add_student_to_department(department_head, new_node, &student_head);
#if DEBUG
            printf("Pop ID %lld out from queue\n", student_head->ID);
#endif
            student_head = pop(student_head);
#if DEBUG
            printf("\n\n");
            show_queue(student_head);
            show_all_node(department_head);
            printf("\n\n");
#endif
        }
#if DEBUG
        printf("Done!\n");

        // eliminate the excessive students, and then put them in queue
        // check if the current_result runs over 5
        // if the department requested doesn't exist, current_result++
        printf("student_head %p(should be nil)\n", student_head);
#endif
        eliminate_student_from_department(department_head, &student_head);
        total_round++;
#if DEBUG
        printf("student_head %p\n", student_head);
        printf("End round %d\n", total_round);
#endif
        // getchar();
    }

    show_final_result(department_head);

    // Student *student_tail = find_queue_tail(student_head);

    // program ending, clean up
    if (fclose(pStudentData) == EOF)
        printf("Error closing pStudentData\n");
    if (fclose(pDepartmentData) == EOF)
        printf("Error closing pDepartmentData\n");

    return 0;
}
Exemple #7
0
int
main(int argc, char *argv[])
{
	struct sockaddr_un	sun;
	struct parse_result	*res = NULL;
	struct imsg		imsg;
	struct smtpd		smtpd;
	int			ctl_sock;
	int			done = 0;
	int			n, verbose = 0;

	/* parse options */
	if (strcmp(__progname, "sendmail") == 0 || strcmp(__progname, "send-mail") == 0)
		sendmail = 1;
	else if (strcmp(__progname, "mailq") == 0) {
		if (geteuid())
			errx(1, "need root privileges");
		setup_env(&smtpd);
		show_queue(0);
		return 0;
	} else if (strcmp(__progname, "smtpctl") == 0) {

		/* check for root privileges */
		if (geteuid())
			errx(1, "need root privileges");

		setup_env(&smtpd);

		if ((res = parse(argc - 1, argv + 1)) == NULL)
			exit(1);

		/* handle "disconnected" commands */
		switch (res->action) {
		case SHOW_QUEUE:
			show_queue(0);
			break;
		case SHOW_RUNQUEUE:
			break;
		default:
			goto connected;
		}
		return 0;
	} else
		errx(1, "unsupported mode");

connected:
	/* connect to smtpd control socket */
	if ((ctl_sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
		err(1, "socket");

	bzero(&sun, sizeof(sun));
	sun.sun_family = AF_UNIX;
	strlcpy(sun.sun_path, SMTPD_SOCKET, sizeof(sun.sun_path));
	if (connect(ctl_sock, (struct sockaddr *)&sun, sizeof(sun)) == -1) {
		if (sendmail)
			return enqueue_offline(argc, argv);
		err(1, "connect: %s", SMTPD_SOCKET);
	}

	if ((ibuf = calloc(1, sizeof(struct imsgbuf))) == NULL)
		err(1, NULL);
	imsg_init(ibuf, ctl_sock);

	if (sendmail)
		return enqueue(argc, argv);

	/* process user request */
	switch (res->action) {
	case NONE:
		usage();
		/* not reached */

	case SCHEDULE:
	case REMOVE: {
		u_int64_t ulval;
		char *ep;

		errno = 0;
		ulval = strtoull(res->data, &ep, 16);
		if (res->data[0] == '\0' || *ep != '\0')
			errx(1, "invalid msgid/evpid");
		if (errno == ERANGE && ulval == ULLONG_MAX)
			errx(1, "invalid msgid/evpid");
		if (ulval == 0)
			errx(1, "invalid msgid/evpid");

		if (res->action == SCHEDULE)
			imsg_compose(ibuf, IMSG_SCHEDULER_SCHEDULE, 0, 0, -1, &ulval,
			    sizeof(ulval));
		if (res->action == REMOVE)
			imsg_compose(ibuf, IMSG_SCHEDULER_REMOVE, 0, 0, -1, &ulval,
			    sizeof(ulval));
		break;
	}

	case SCHEDULE_ALL: {
		u_int64_t ulval = 0;

		imsg_compose(ibuf, IMSG_SCHEDULER_SCHEDULE, 0, 0, -1, &ulval,
		    sizeof(ulval));
		break;
	}

	case SHUTDOWN:
		imsg_compose(ibuf, IMSG_CTL_SHUTDOWN, 0, 0, -1, NULL, 0);
		break;
	case PAUSE_MDA:
		imsg_compose(ibuf, IMSG_QUEUE_PAUSE_MDA, 0, 0, -1, NULL, 0);
		break;
	case PAUSE_MTA:
		imsg_compose(ibuf, IMSG_QUEUE_PAUSE_MTA, 0, 0, -1, NULL, 0);
		break;
	case PAUSE_SMTP:
		imsg_compose(ibuf, IMSG_SMTP_PAUSE, 0, 0, -1, NULL, 0);
		break;
	case RESUME_MDA:
		imsg_compose(ibuf, IMSG_QUEUE_RESUME_MDA, 0, 0, -1, NULL, 0);
		break;
	case RESUME_MTA:
		imsg_compose(ibuf, IMSG_QUEUE_RESUME_MTA, 0, 0, -1, NULL, 0);
		break;
	case RESUME_SMTP:
		imsg_compose(ibuf, IMSG_SMTP_RESUME, 0, 0, -1, NULL, 0);
		break;
	case SHOW_STATS:
		imsg_compose(ibuf, IMSG_STATS, 0, 0, -1, NULL, 0);
		break;
	case MONITOR:
		/* XXX */
		break;
	case LOG_VERBOSE:
		verbose = 1;
		/* FALLTHROUGH */
	case LOG_BRIEF:
		imsg_compose(ibuf, IMSG_CTL_VERBOSE, 0, 0, -1, &verbose,
		    sizeof(verbose));
		printf("logging request sent.\n");
		done = 1;
		break;
	default:
		errx(1, "unknown request (%d)", res->action);
	}

	while (ibuf->w.queued)
		if (msgbuf_write(&ibuf->w) < 0)
			err(1, "write error");

	while (!done) {
		if ((n = imsg_read(ibuf)) == -1)
			errx(1, "imsg_read error");
		if (n == 0)
			errx(1, "pipe closed");

		while (!done) {
			if ((n = imsg_get(ibuf, &imsg)) == -1)
				errx(1, "imsg_get error");
			if (n == 0)
				break;
			switch(res->action) {
			case REMOVE:
			case SCHEDULE:
			case SCHEDULE_ALL:
			case SHUTDOWN:
			case PAUSE_MDA:
			case PAUSE_MTA:
			case PAUSE_SMTP:
			case RESUME_MDA:
			case RESUME_MTA:
			case RESUME_SMTP:
			case LOG_VERBOSE:
			case LOG_BRIEF:
				done = show_command_output(&imsg);
				break;
			case SHOW_STATS:
				done = show_stats_output(&imsg);
				break;
			case NONE:
				break;
			case MONITOR:
				break;
			default:
				err(1, "unexpected reply (%d)", res->action);
			}
			/* insert imsg replies switch here */

			imsg_free(&imsg);
		}
	}
	close(ctl_sock);
	free(ibuf);

	return (0);
}
Exemple #8
0
int main()
{
	int sel; 
	student stud;

	head = NULL; 
	while(1) 
	{
		printf("\nMenu selections\n");
		printf("---------------\n");
		printf("1. Add student\n");
		printf("2. View all students\n");
		printf("3. View last student\n");
		printf("4. Delete top student\n");
		printf("5. Exit\n");

		printf("\nEnter choice: ");
		scanf("%d", &sel);

		switch(sel)
		{
			case 1:
				getchar();

				printf("Name: ");
				gets(stud.name);
				
				printf("Code: ");
				scanf("%d", &stud.code);

				printf("Grade: "); 
				scanf("%f", &stud.grd);

				add_queue(&stud);
			break;

			case 2:
				if(head != NULL)
					show_queue();
				else
					printf("\nThe queue is empty\n");
			break;

			case 3:
				if(head != NULL)
					printf("\nData: %d %s %.2f\n\n",
					tail->code,tail->name,tail->grd);
				else
					printf("\nThe queue is empty\n");
			break;

			case 4:
				if(head != NULL)
					pop();
				else
					printf("\nThe queue is empty\n");
			break;

			case 5:
				if(head != NULL)
					free_queue();
			return 0; 

			default:
				printf("\nWrong choice\n");
			break;
		}
	}
	return 0;
}