Beispiel #1
0
void LCD_init()	
{
	write_com(0x80);
	for(a=0;a<16;a++)
	{
		write_date(table5[a]);
		delayms(5);
	}
	write_com(0x80+0x40);
	for(a=0;a<12;a++)
	{		
		write_date(table6[a]);
		delayms(5);
	}				   

}
Beispiel #2
0
/* Write a principal's lockout data. */
static krb5_error_code
princ_lockout(struct rec_args *args, const char *name, krb5_db_entry *dbe)
{
    struct rechandle *h = args->rh;

    if (startrec(h) < 0)
        return errno;
    if (writefield(h, "%s", name) < 0)
        return errno;
    if (write_date(args, dbe->last_success) < 0)
        return errno;
    if (write_date(args, dbe->last_failed) < 0)
        return errno;
    if (writefield(h, "%d", dbe->fail_auth_count) < 0)
        return errno;
    if (endrec(h) < 0)
        return errno;
    return 0;
}
Beispiel #3
0
/* Write a principal's ticket policy. */
static krb5_error_code
princ_tktpolicy(struct rec_args *args, const char *name, krb5_db_entry *dbe)
{
    struct rechandle *h = args->rh;

    if (startrec(h) < 0)
        return errno;
    if (writefield(h, "%s", name) < 0)
        return errno;
    if (write_date(args, dbe->expiration) < 0)
        return errno;
    if (write_date(args, dbe->pw_expiration) < 0)
        return errno;
    if (writefield(h, "%d", dbe->max_life) < 0)
        return errno;
    if (writefield(h, "%d", dbe->max_renewable_life) < 0)
        return errno;
    if (endrec(h) < 0)
        return errno;
    return 0;
}
Beispiel #4
0
/**
 * closes a flow described by fd
 * if send_reply is non-zero, a response is sent to client's mapi stub,
 * (send_reply=0 is used for local clean-ups)
 */
static void cmd_close_flow(int fd, int pid, int sock, int send_reply) {
	struct flow *f;
	struct client *cl;
	struct mapiipcbuf buf;
	long file_size;

	f=(struct flow*)flist_get(flowlist, fd);

	if (f) {
		/* to avoid reading memory after it's freed */
		int tmpfd = f->fd;
		/* prevent closing flows of other processes */
		if (pid != f->id) {
			DEBUG_CMD(Debug_Message(
					"Proc %d tried to close flow %d, which belongs to proc %d",
					pid, f->fd, f->id));
			report_error(MAPI_INVALID_FLOW, pid, sock);
			return;
		}

		cleanup_flow(f);

		while(__sync_lock_test_and_set(&clientlist_lock,1));
		cl = flist_get(clientlist, pid);
		f = (struct flow *) flist_remove(cl->flowlist, fd);
		cl->numflows--;
		clientlist_lock = 0;

		//send an ACK that flow closed
		if (send_reply) {

			buf.mtype = pid;
			buf.cmd = CLOSE_FLOW_ACK;
			buf.fd = tmpfd;
			mapiipc_daemon_write((struct mapiipcbuf *) &buf, sock);

			if (log_to_file) {
				file_size = acquire_write_lock(log_fd_info);
				write_to_file(log_fd_info, "MAPID: flow %d was closed at ",
						buf.fd);
				write_date(log_fd_info);
				write_newline(log_fd_info, "\n");
				release_write_lock(log_fd_info, file_size);
			}
			if (log_to_syslog)
				log_message("flow %d was closed", buf.fd);
		}
	} else {
		report_error(MAPI_INVALID_FLOW, pid, sock);
	}
}
Beispiel #5
0
static void cmd_delete_offline_device(char *dev, int pid, int sock) {
	mapidrv *drv;
	struct mapiipcbuf buf;
	long file_size;

	for (drv = drvlist; drv != NULL; drv = drv->next) {
		if (drv->device != NULL)
			if (strcmp(dev, drv->device) == 0) {
				break;
			}
	}

	if (drv == NULL) {
		DEBUG_CMD(Debug_Message("No device found for %s", dev));
		report_error(MAPID_NO_DEVICE, pid, sock);
		return;
	}

	if (drv->offline != 0) {
		mapidrv_delete_device = get_drv_funct(drv->handle,
				"mapidrv_delete_device");
		mapidrv_delete_device(drv->devid);
		drv->active=0;
	}

	buf.mtype = pid;
	buf.cmd = DELETE_OFFLINE_DEVICE_ACK;
	buf.fd = -1;

	if (log_to_file) {
		file_size = acquire_write_lock(log_fd_info);
		write_to_file(log_fd_info, "MAPID: offline device %s was deleted at ",
				dev);
		write_date(log_fd_info);
		write_newline(log_fd_info, "\n");
		release_write_lock(log_fd_info, file_size);
	}
	if (log_to_syslog)
		log_message("offline device %s was deleted", dev);
    
  DEBUG_CMD(Debug_Message("Deleted offline device %s", dev));

	mapiipc_daemon_write((struct mapiipcbuf *) &buf, sock);
}
Beispiel #6
0
static void cmd_connect(int fd, int pid, int sock)
//Connect to flow
//fd = flow descriptor
{
	struct mapiipcbuf buf;
	int err = 0;
	mapidrv *drv = get_drv(fd);
	long file_size;

	if (drv == NULL) {
		/* driver not found(should be handled in create_flow), or invalid flow id */
		DEBUG_CMD(Debug_Message("cmd_connect: no driver found"));
		report_error(MAPI_INVALID_FLOW, pid, sock);
		return;
	}

	if (err == 0) {
		mapidrv_connect = get_drv_funct(drv->handle, "mapidrv_connect");
		err = mapidrv_connect(drv->devid, fd);
	}
	if (err != 0) {
		report_error(err, pid, sock);
		return;
	}

	buf.cmd = CONNECT_ACK;
	buf.mtype = get_id(fd); /* should be == pid */
	buf.fd = fd;

	if (log_to_file) {
		file_size = acquire_write_lock(log_fd_info);
		write_to_file(log_fd_info, "MAPID: connect to flow %d at ", fd);
		write_date(log_fd_info);
		write_newline(log_fd_info, "\n");
		release_write_lock(log_fd_info, file_size);
	}
	if (log_to_syslog)
		log_message("connect to flow %d", fd);

	mapiipc_daemon_write((struct mapiipcbuf *) &buf, sock);
}
Beispiel #7
0
int datfix(struct wcsprm *wcs)

{
  static const char *function = "datfix";

  char orig_dateobs[72];
  char ctmp[72], ctmp2[72];
  char *dateobs;
  int  day, dd, hour = 0, jd, minute = 0, month, msec, n4, year;
  double mjdobs, sec = 0.0, t;
  struct wcserr **err;

  if (wcs == 0x0) return FIXERR_NULL_POINTER;
  err = &(wcs->err);

  dateobs = wcs->dateobs;
  strncpy(orig_dateobs, dateobs, 72);
  if (dateobs[0] == '\0') {
    if (undefined(wcs->mjdobs)) {
     /* No date information was provided. */
      return FIXERR_NO_CHANGE;

    } else {
      /* Calendar date from MJD. */
      jd = 2400001 + (int)wcs->mjdobs;

      n4 =  4*(jd + ((2*((4*jd - 17918)/146097)*3)/4 + 1)/2 - 37);
      dd = 10*(((n4-237)%1461)/4) + 5;

      year  = n4/1461 - 4712;
      month = (2 + dd/306)%12 + 1;
      day   = (dd%306)/10 + 1;
      sprintf(dateobs, "%.4d-%.2d-%.2d", year, month, day);

      /* Write time part only if non-zero. */
      if ((t = wcs->mjdobs - (int)wcs->mjdobs) > 0.0) {
        t *= 24.0;
        hour = (int)t;
        t = 60.0 * (t - hour);
        minute = (int)t;
        sec    = 60.0 * (t - minute);

        /* Round to 1ms. */
        dd = 60000*(60*hour + minute) + (int)(1000*(sec+0.0005));
        hour = dd / 3600000;
        dd -= 3600000 * hour;
        minute = dd / 60000;
        msec = dd - 60000 * minute;
        sprintf(dateobs+10, "T%.2d:%.2d:%.2d", hour, minute, msec/1000);

        /* Write fractions of a second only if non-zero. */
        if (msec%1000) {
          sprintf(dateobs+19, ".%.3d", msec%1000);
        }
      }
    }

  } else {
    if (strlen(dateobs) < 8) {
      /* Can't be a valid date. */
      return wcserr_set(WCSERR_SET(FIXERR_BAD_PARAM),
        "Invalid parameter value: date string too short '%s'", dateobs);
    }

    /* Identify the date format. */
    if (dateobs[4] == '-' && dateobs[7] == '-') {
      /* Standard year-2000 form: CCYY-MM-DD[Thh:mm:ss[.sss...]] */
      if (sscanf(dateobs, "%4d-%2d-%2d", &year, &month, &day) < 3) {
        return wcserr_set(WCSERR_SET(FIXERR_BAD_PARAM),
          "Invalid parameter value: invalid date '%s'", dateobs);
      }

      if (dateobs[10] == 'T') {
        if (parse_date(dateobs+11, &hour, &minute, &sec)) {
          return wcserr_set(WCSERR_SET(FIXERR_BAD_PARAM),
            "Invalid parameter value: invalid time '%s'", dateobs+11);
        }
      } else if (dateobs[10] == ' ') {
        hour = 0;
        minute = 0;
        sec = 0.0;
        if (parse_date(dateobs+11, &hour, &minute, &sec)) {
          write_date(dateobs+10, hour, minute, sec);
        } else {
          dateobs[10] = 'T';
        }
      }

    } else if (dateobs[4] == '/' && dateobs[7] == '/') {
      /* Also allow CCYY/MM/DD[Thh:mm:ss[.sss...]] */
      if (sscanf(dateobs, "%4d/%2d/%2d", &year, &month, &day) < 3) {
        return wcserr_set(WCSERR_SET(FIXERR_BAD_PARAM),
          "Invalid parameter value: invalid date '%s'", dateobs);
      }

      if (dateobs[10] == 'T') {
        if (parse_date(dateobs+11, &hour, &minute, &sec)) {
          return wcserr_set(WCSERR_SET(FIXERR_BAD_PARAM),
            "Invalid parameter value: invalid time '%s'", dateobs+11);
        }
      } else if (dateobs[10] == ' ') {
        hour = 0;
        minute = 0;
        sec = 0.0;
        if (parse_date(dateobs+11, &hour, &minute, &sec)) {
          write_date(dateobs+10, hour, minute, sec);
        } else {
          dateobs[10] = 'T';
        }
      }

      /* Looks ok, fix it up. */
      dateobs[4]  = '-';
      dateobs[7]  = '-';

    } else {
      if (dateobs[2] == '/' && dateobs[5] == '/') {
        /* Old format date: DD/MM/YY, also allowing DD/MM/CCYY. */
        if (sscanf(dateobs, "%2d/%2d/%4d", &day, &month, &year) < 3) {
          return wcserr_set(WCSERR_SET(FIXERR_BAD_PARAM),
            "Invalid parameter value: invalid date '%s'", dateobs);
        }

      } else if (dateobs[2] == '-' && dateobs[5] == '-') {
        /* Also recognize DD-MM-YY and DD-MM-CCYY */
        if (sscanf(dateobs, "%2d-%2d-%4d", &day, &month, &year) < 3) {
          return wcserr_set(WCSERR_SET(FIXERR_BAD_PARAM),
            "Invalid parameter value: invalid date '%s'", dateobs);
        }

      } else {
        /* Not a valid date format. */
        return wcserr_set(WCSERR_SET(FIXERR_BAD_PARAM),
          "Invalid parameter value: invalid date '%s'", dateobs);
      }

      if (year < 100) year += 1900;

      /* Doesn't have a time. */
      sprintf(dateobs, "%.4d-%.2d-%.2d", year, month, day);
    }

    /* Compute MJD. */
    mjdobs = (double)((1461*(year - (12-month)/10 + 4712))/4
             + (306*((month+9)%12) + 5)/10
             - (3*((year - (12-month)/10 + 4900)/100))/4
             + day - 2399904)
             + (hour + (minute + sec/60.0)/60.0)/24.0;

    if (undefined(wcs->mjdobs)) {
      wcs->mjdobs = mjdobs;
    } else {
      /* Check for consistency. */
      if (fabs(mjdobs - wcs->mjdobs) > 0.5) {
        return wcserr_set(WCSERR_SET(FIXERR_BAD_PARAM),
          "Invalid parameter value: inconsistent date '%s'", dateobs);
      }
    }
  }

  if (strncmp(orig_dateobs, dateobs, 72)) {
    wcserr_set(WCSERR_SET(FIXERR_DATE_FIX),
      "Changed '%s' to '%s'", orig_dateobs, dateobs);

    return FIXERR_SUCCESS;
  }

  return FIXERR_NO_CHANGE;
}
Beispiel #8
0
/* Write a principal's metadata. */
static krb5_error_code
princ_meta(struct rec_args *args, const char *name, krb5_db_entry *dbe)
{
    int got_adb = 0;
    char *modby;
    krb5_kvno mkvno;
    const char *policy;
    krb5_principal mod_princ = NULL;
    krb5_timestamp mod_time, last_pwd;
    krb5_error_code ret;
    osa_princ_ent_rec adb;
    struct rechandle *h = args->rh;

    memset(&adb, 0, sizeof(adb));
    if (startrec(h) < 0)
        return errno;
    if (writefield(h, "%s", name) < 0)
        return errno;

    ret = krb5_dbe_lookup_last_pwd_change(util_context, dbe, &last_pwd);
    if (ret)
        return ret;
    ret = krb5_dbe_get_mkvno(util_context, dbe, &mkvno);
    if (ret)
        return ret;

    ret = krb5_dbe_lookup_mod_princ_data(util_context, dbe, &mod_time,
                                         &mod_princ);
    if (ret)
        return ret;
    ret = krb5_unparse_name(util_context, mod_princ, &modby);
    krb5_free_principal(util_context, mod_princ);
    if (ret)
        return ret;
    ret = writefield(h, "%s", modby);
    krb5_free_unparsed_name(util_context, modby);
    if (ret < 0)
        return errno;

    if (write_date(args, mod_time) < 0)
        return errno;
    if (write_date(args, last_pwd) < 0)
        return errno;

    got_adb = get_adb(dbe, &adb);
    if (got_adb && adb.policy != NULL)
        policy = adb.policy;
    else
        policy = "";
    ret = writefield(h, "%s", policy);
    if (ret < 0) {
        ret = errno;
        goto cleanup;
    }
    if (writefield(h, "%d", mkvno) < 0) {
        ret = errno;
        goto cleanup;
    }
    if (writefield(h, "%d", adb.admin_history_kvno) < 0) {
        ret = errno;
        goto cleanup;
    }
    if (endrec(h) < 0)
        ret = errno;
    else
        ret = 0;

cleanup:
    kdb_free_entry(NULL, NULL, &adb);
    return ret;
}
Beispiel #9
0
void keycheck ()
{
	if(s1_push&&key_push)

		{
			TH0=256-60;
			bxxz=0;
			TR0=1;
			LCD1602_init();
			write_com(0x80);  
			for(a=0;a<8;a++)
			{		
				write_date(table1[a]);
				delayms(1);
			}
			write_com(0x80+0x40);
			for(a=0;a<7;a++)
			{
				write_date(table65[a]);
				delayms(5);
			}							//虽然s1_push&&key_push为一个低电平触发变量,但由于以上延时,			
										//使这个操作只被执行一次
		}
	
	if(s2_push&&key_push)

		{
		  	TH0=256-60;
			bxxz=0;
			TR0=1;
			LCD1602_init();
			write_com(0x80);
			for(a=0;a<8;a++)
			{		
				write_date(table2[a]);
				delayms(1);
			}
			write_com(0x80+0x40);
			for(a=0;a<8;a++)
			{
				write_date(table260[a]);
				delayms(5);
			}
				
		}

	if(s3_push&&key_push)

		{
		  	TH0=256-60;
			bxxz=0;
			TR0=1;
			LCD1602_init();
			write_com(0x80);
			for(a=0;a<8;a++)
			{		
				write_date(table4[a]);
				delayms(1);
			}
			write_com(0x80+0x40);
			for(a=0;a<8;a++)
			{
				write_date(table260[a]);
				delayms(5);
			}
				
		}
	
	if(s4_push&&key_push)
	{
		TH0=256-60;
		bxxz=0;
		TR0=1;
		LCD1602_init();
		write_com(0x80);
		for(a=0;a<10;a++)
		{		
			write_date(table3[a]);
			delayms(1);
		}
		write_com(0x80+0x40);
		for(a=0;a<7;a++)
		{
			write_date(table65[a]);
			delayms(5);
		}
	}
	if(s5_push&&key_push)
	{
		TH0=256-60;
		bxxz=0;
		TR0=1;
		LCD1602_init();
		write_com(0x80);
		for(a=0;a<10;a++)
		{		
			write_date(table10[a]);
			delayms(1);
		}
		write_com(0x80+0x40);
		for(a=0;a<7;a++)
		{
			write_date(table65[a]);
			delayms(5);
		}
	}
//	delayms(10);
//	while(!s1&&!s2&&!s3&&!s4);
/*	if (s6==0)
	{
		delayms(10);
		if(s6==0)
		{
//			s5_push=1;
			
			f_choose();
			while(!s6);
		}	
	}
//	else
//		s5_push=0;
*/	
}
Beispiel #10
0
void f_choose()
{	if(s6_push)
	{
	 	bxxz++;		
		switch(bxxz)
			{
				case 1:
					TH0=250-80;
					if(s1_push|s4_push|s5_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<7;a++)
						{
							write_date(table49[a]);
							delayms(5);
						}
					}
					if(s2_push|s3_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<8;a++)
						{
							write_date(table195[a]);
							delayms(5);
						}
					}
					break;
				case 2:
					TH0=250-100;
					if(s1_push|s4_push|s5_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<7;a++)
						{
							write_date(table39[a]);
							delayms(5);
						}
					}
					if(s2_push|s3_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<8;a++)
						{
							write_date(table156[a]);
							delayms(5);
						}
					}
					break;
				case 3:
					TH0=250-120;
						if(s1_push|s4_push|s5_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<7;a++)
						{
							write_date(table33[a]);
							delayms(5);
						}
					}
					if(s2_push|s3_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<8;a++)
						{
							write_date(table130[a]);
							delayms(5);
						}
					}
					break;
				case 4:
					TH0=250-140;
						if(s1_push|s4_push|s5_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<7;a++)
						{
							write_date(table28[a]);
							delayms(5);
						}
					}
					if(s2_push|s3_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<8;a++)
						{
							write_date(table112[a]);
							delayms(5);
						}
					}
					break;
				case 5:
					TH0=250-160;
						if(s1_push|s4_push|s5_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<7;a++)
						{
							write_date(table24[a]);
							delayms(5);
						}
					}
					if(s2_push|s3_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<8;a++)
						{
							write_date(table98[a]);
							delayms(5);
						}
					}
					break;
				case 6:
					TH0=250-180;
					if(s1_push|s4_push|s5_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<7;a++)
						{
							write_date(table22[a]);
							delayms(5);
						}
					}
					if(s2_push|s3_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<8;a++)
						{
							write_date(table87[a]);
							delayms(5);
						}
					}
					break;
				case 7:
					TH0=250-200;
				if(s1_push|s4_push|s5_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<7;a++)
						{
							write_date(table20[a]);
							delayms(5);
						}
					}
					if(s2_push|s3_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<8;a++)
						{
							write_date(table78[a]);
							delayms(5);
						}
					}
					break;
				case 8:
					TH0=250-220;
					if(s1_push|s4_push|s5_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<7;a++)
						{
							write_date(table18[a]);
							delayms(5);
						}
					}
					if(s2_push|s3_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<8;a++)
						{
							write_date(table71[a]);
							delayms(5);
						}
					}
					break;
				case 9:
					TH0=250-240;
					if(s1_push|s4_push|s5_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<7;a++)
						{
							write_date(table16[a]);
							delayms(5);
						}
					}
					if(s2_push|s3_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<7;a++)
						{
							write_date(table65[a]);
							delayms(5);
						}
					}
					break;
				case 10:
					TH0=250-60;
					if(s1_push|s4_push|s5_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<7;a++)
						{
							write_date(table65[a]);
							delayms(5);
						}
					}
					if(s2_push|s3_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<8;a++)
						{
							write_date(table260[a]);
							delayms(5);
						}
					}
					break;
									
		}
		if(bxxz==11)
			bxxz=0;
		if(!s1_push&&!s2_push&&!s3_push&&!s4_push&&!s5_push)
			{
				LCD1602_init();
				write_com(0x80);
				for(a=0;a<6;a++)
				{
					write_date(table7[a]);
					delayms(5);
				}
				write_com(0x80+0x40);
				for(a=0;a<12;a++)
				{		
					write_date(table6[a]);
					delayms(5);
				}		
			}
		
	}
	if(s7_push)
	{
		if(bxxz==0)
			bxxz=10;
		bxxz--;		
		switch(bxxz)
			{
				case 0:
					TH0=250-60;
					if(s1_push|s4_push|s5_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<7;a++)
						{
							write_date(table65[a]);
							delayms(5);
						}
					}
					if(s2_push|s3_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<8;a++)
						{
							write_date(table260[a]);
							delayms(5);
						}
					}
					break;
				case 1:
					TH0=250-80;
					if(s1_push|s4_push|s5_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<7;a++)
						{
							write_date(table49[a]);
							delayms(5);
						}
					}
					if(s2_push|s3_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<8;a++)
						{
							write_date(table195[a]);
							delayms(5);
						}
					}
					break;
				case 2:
					TH0=250-100;
					if(s1_push|s4_push|s5_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<7;a++)
						{
							write_date(table39[a]);
							delayms(5);
						}
					}
					if(s2_push|s3_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<8;a++)
						{
							write_date(table156[a]);
							delayms(5);
						}
					}
					break;
				case 3:
					TH0=250-120;
						if(s1_push|s4_push|s5_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<7;a++)
						{
							write_date(table33[a]);
							delayms(5);
						}
					}
					if(s2_push|s3_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<8;a++)
						{
							write_date(table130[a]);
							delayms(5);
						}
					}
					break;
				case 4:
					TH0=250-140;
						if(s1_push|s4_push|s5_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<7;a++)
						{
							write_date(table28[a]);
							delayms(5);
						}
					}
					if(s2_push|s3_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<8;a++)
						{
							write_date(table112[a]);
							delayms(5);
						}
					}
					break;
				case 5:
					TH0=250-160;
						if(s1_push|s4_push|s5_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<7;a++)
						{
							write_date(table24[a]);
							delayms(5);
						}
					}
					if(s2_push|s3_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<8;a++)
						{
							write_date(table98[a]);
							delayms(5);
						}
					}
					break;
				case 6:
					TH0=250-180;
					if(s1_push|s4_push|s5_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<7;a++)
						{
							write_date(table22[a]);
							delayms(5);
						}
					}
					if(s2_push|s3_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<8;a++)
						{
							write_date(table87[a]);
							delayms(5);
						}
					}
					break;
				case 7:
					TH0=250-200;
				if(s1_push|s4_push|s5_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<7;a++)
						{
							write_date(table20[a]);
							delayms(5);
						}
					}
					if(s2_push|s3_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<8;a++)
						{
							write_date(table78[a]);
							delayms(5);
						}
					}
					break;
				case 8:
					TH0=250-220;
					if(s1_push|s4_push|s5_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<7;a++)
						{
							write_date(table18[a]);
							delayms(5);
						}
					}
					if(s2_push|s3_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<8;a++)
						{
							write_date(table71[a]);
							delayms(5);
						}
					}
					break;
				case 9:
					TH0=250-240;
					if(s1_push|s4_push|s5_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<7;a++)
						{
							write_date(table16[a]);
							delayms(5);
						}
					}
					if(s2_push|s3_push)
					{
						write_com(0x80+0x40);
						for(a=0;a<7;a++)
						{
							write_date(table65[a]);
							delayms(5);
						}
					}
					break;
										
				}
		if(!s1_push&&!s2_push&&!s3_push&&!s4_push&&!s5_push)
			{
				LCD1602_init();
				write_com(0x80);
				for(a=0;a<6;a++)
				{
					write_date(table7[a]);
					delayms(5);
				}
				write_com(0x80+0x40);
				for(a=0;a<12;a++)
				{		
					write_date(table6[a]);
					delayms(5);
				}		
			}
		
	}
	

} 
Beispiel #11
0
void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length)
{
    GPtrArray *objects = NULL;
    GHashTable *ref_table = NULL;
    struct serialize_s ser_s;
    uint8_t offset_size = 0;
    uint8_t dict_param_size = 0;
    uint64_t num_objects = 0;
    uint64_t root_object = 0;
    uint64_t offset_table_index = 0;
    GByteArray *bplist_buff = NULL;
    uint64_t i = 0;
    uint8_t *buff = NULL;
    uint64_t *offsets = NULL;
    uint8_t pad[6] = { 0, 0, 0, 0, 0, 0 };
    uint8_t trailer[BPLIST_TRL_SIZE];
    //for string
    glong len = 0;
    int type = 0;
    glong items_read = 0;
    glong items_written = 0;
    GError *error = NULL;
    gunichar2 *unicodestr = NULL;

    //check for valid input
    if (!plist || !plist_bin || *plist_bin || !length)
        return;

    //list of objects
    objects = g_ptr_array_new();
    //hashtable to write only once same nodes
    ref_table = g_hash_table_new(plist_data_hash, plist_data_compare);

    //serialize plist
    ser_s.objects = objects;
    ser_s.ref_table = ref_table;
    serialize_plist(plist, &ser_s);

    //now stream to output buffer
    offset_size = 0;			//unknown yet
    dict_param_size = get_needed_bytes(objects->len);
    num_objects = objects->len;
    root_object = 0;			//root is first in list
    offset_table_index = 0;		//unknown yet

    //setup a dynamic bytes array to store bplist in
    bplist_buff = g_byte_array_new();

    //set magic number and version
    g_byte_array_append(bplist_buff, BPLIST_MAGIC, BPLIST_MAGIC_SIZE);
    g_byte_array_append(bplist_buff, BPLIST_VERSION, BPLIST_VERSION_SIZE);

    //write objects and table
    offsets = (uint64_t *) malloc(num_objects * sizeof(uint64_t));
    for (i = 0; i < num_objects; i++)
    {

        plist_data_t data = plist_get_data(g_ptr_array_index(objects, i));
        offsets[i] = bplist_buff->len;

        switch (data->type)
        {
        case PLIST_BOOLEAN:
            buff = (uint8_t *) malloc(sizeof(uint8_t));
            buff[0] = data->boolval ? BPLIST_TRUE : BPLIST_FALSE;
            g_byte_array_append(bplist_buff, buff, sizeof(uint8_t));
            free(buff);
            break;

        case PLIST_UINT:
            write_int(bplist_buff, data->intval);
            break;

        case PLIST_REAL:
            write_real(bplist_buff, data->realval);
            break;

        case PLIST_KEY:
        case PLIST_STRING:
            len = strlen(data->strval);
            if ( is_ascii_string(data->strval, len) )
            {
                write_string(bplist_buff, data->strval);
            }
            else
            {
                unicodestr = g_utf8_to_utf16(data->strval, len, &items_read, &items_written, &error);
                write_unicode(bplist_buff, unicodestr, items_written);
                g_free(unicodestr);
            }
            break;
        case PLIST_DATA:
            write_data(bplist_buff, data->buff, data->length);
        case PLIST_ARRAY:
            write_array(bplist_buff, g_ptr_array_index(objects, i), ref_table, dict_param_size);
            break;
        case PLIST_DICT:
            write_dict(bplist_buff, g_ptr_array_index(objects, i), ref_table, dict_param_size);
            break;
        case PLIST_DATE:
            write_date(bplist_buff, data->timeval.tv_sec + (double) data->timeval.tv_usec / G_USEC_PER_SEC);
            break;
        default:
            break;
        }
    }

    //free intermediate objects
    g_hash_table_foreach_remove(ref_table, free_index, NULL);
    g_ptr_array_free(objects, TRUE);
    g_hash_table_destroy(ref_table);

    //write offsets
    offset_size = get_needed_bytes(bplist_buff->len);
    offset_table_index = bplist_buff->len;
    for (i = 0; i < num_objects; i++)
    {
        uint8_t *offsetbuff = (uint8_t *) malloc(offset_size);

#if G_BYTE_ORDER == G_BIG_ENDIAN
	offsets[i] = offsets[i] << ((sizeof(uint64_t) - offset_size) * 8);
#endif

        memcpy(offsetbuff, &offsets[i], offset_size);
        byte_convert(offsetbuff, offset_size);
        g_byte_array_append(bplist_buff, offsetbuff, offset_size);
        free(offsetbuff);
    }

    //experimental pad to reflect apple's files
    g_byte_array_append(bplist_buff, pad, 6);

    //setup trailer
    num_objects = GUINT64_FROM_BE(num_objects);
    root_object = GUINT64_FROM_BE(root_object);
    offset_table_index = GUINT64_FROM_BE(offset_table_index);

    memcpy(trailer + BPLIST_TRL_OFFSIZE_IDX, &offset_size, sizeof(uint8_t));
    memcpy(trailer + BPLIST_TRL_PARMSIZE_IDX, &dict_param_size, sizeof(uint8_t));
    memcpy(trailer + BPLIST_TRL_NUMOBJ_IDX, &num_objects, sizeof(uint64_t));
    memcpy(trailer + BPLIST_TRL_ROOTOBJ_IDX, &root_object, sizeof(uint64_t));
    memcpy(trailer + BPLIST_TRL_OFFTAB_IDX, &offset_table_index, sizeof(uint64_t));

    g_byte_array_append(bplist_buff, trailer, BPLIST_TRL_SIZE);

    //duplicate buffer
    *plist_bin = (char *) malloc(bplist_buff->len);
    memcpy(*plist_bin, bplist_buff->data, bplist_buff->len);
    *length = bplist_buff->len;

    g_byte_array_free(bplist_buff, TRUE);
    free(offsets);
}
Beispiel #12
0
void keyscan()   //按键函数
{
	if(key1==0)	
	{
		delay(5);
		if(key1==0)
		{	keyflag++;   //键一按下,标志位加一
			while(!key1);
			if(keyflag==1)   
			{
				TR0=0;  //关中断
				write_com(0x80+0x40+14);   //调整秒
				write_com(0x0f);   //光标闪烁
			}  
			if(keyflag==2)
			{
				write_com(0x80+0x40+11);  //调整分
			}
			if(keyflag==3)
			{
				write_com(0x80+0x40+8);  //调整时
			}
			if(keyflag==4)
			{
				write_com(0x80+14);  //调整日	
			}
			if(keyflag==5)
			{
				write_com(0x80+11);	//调整月
			}
			if(keyflag==6)
			{
				write_com(0x80+8);	//调整年
			}
			if(keyflag==7)
			{
				keyflag=0;   //标志位复位
				write_com(0x0c);   //关闭光标的闪烁
				TR0=1;   //重新开启中断,走秒
			}	
		}
	}
		if(keyflag!=0)
		{
			if(key2==0)
			{
				delay(5);   //松手检测
				if(key2==0)   //按键二对所调整的数值加一
				{
					while(!key2);
					if(keyflag==1)
					{
						sec++;
						if(sec==60)
							sec=0;
						write_time(14,sec);
						write_com(0x80+0x40+14);
					}
					if(keyflag==2)
					{
						min++;
						if(min==60)
							min=0;
						write_time(11,min);
						write_com(0x80+0x40+11);
					}
					if(keyflag==3)
					{
						hour++;
						if(hour==24)
							hour=0;
						write_time(8,hour);
						write_com(0x80+0x40+8);
					}
					if(keyflag==4)
					{
						day++;
						if(day==32)
							day=0;
						write_date(14,day);
						write_com(0x80+14);
					}
					if(keyflag==5)
					{
						month++;
						if(month==13)
							month=0;
						write_date(11,month);
						write_com(0x80+11);
					}
					if(keyflag==6)
					{
						year++;
						if(year==100)
							year=0;
						write_date(8,year);
						write_com(0x80+8);
					}
				}
			}
		}
			if(key3==0)
			{
				delay(5);
				if(key3==0)   //按键三对所调整的数值减一
				{ 
					while(!key3);
					if(keyflag==1)
					{
						sec--;
						if(sec==-1)
							sec=59;
						write_time(14,sec);
						write_com(0x80+0x40+14);
					}
					if(keyflag==2)
					{
						min--;
						if(min==-1)
							min=59;
						write_time(11,min);
						write_com(0x80+0x40+11);
					}
					if(keyflag==3)
					{
						hour--;
						if(hour==-1)
							hour=23;
						write_time(8,hour);
						write_com(0x80+0x40+8);
					}
					if(keyflag==4)
					{
						day--;
						if(day==0)
							day=31;
						write_date(14,day);
						write_com(0x80+15);
					}
					if(keyflag==5)
					{
						month--;
						if(month==0)
							month=12;
						write_date(11,month);
						write_com(0x80+11);
					}
					if(keyflag==6)
					{
						year--;
						if(year==-1)
							year=99;
						write_date(8,year);
						write_com(0x80+8);
					}
				}
			}
}
Beispiel #13
0
static void cmd_create_offline_device(char *dev, int format, int pid, int sock)
//Create a new flow
//dev = device
//if = IPC id used to send ack message back to client
{
	struct mapiipcbuf buf;
	mapidrv *drv, *drv2, *lok;
	int err;
	int file;
	struct client *cl;
	char *format_;
	long file_size;

	//Get file descriptor
	buf.mtype = pid;
	buf.cmd = SEND_FD;
	mapiipc_daemon_write((struct mapiipcbuf *) &buf, sock);
	file = mapiipc_read_fd(sock);

	//Decide which driver to use
	for (drv = drvlist; drv != NULL; drv = drv->next) {
		if (drv->format == format) {
			DEBUG_CMD(Debug_Message("Using driver %s for %s", drv->name, dev));
			break;
		}
	}

	if (drv == NULL) {
		DEBUG_CMD(Debug_Message("ERROR: No driver found for %s", dev));
		report_error(MAPID_NO_DRIVER, pid, sock);
		return;
	}

	//Calls driver
	//First create new "device" for the file 
	drv2 = malloc(sizeof(mapidrv));
	drv2->device = malloc(strlen(dev)+7);
	sprintf(drv2->device, "%s@%d", dev, deviceid);
	lok=drvlist;

	while (lok->next!=NULL)
		lok = lok->next;
	lok->next = drv2;
	drv2->next=NULL;
	drv2->handle = drv->handle;
	drv2->name = strdup(drv->name);
	drv2->format = drv->format;
	drv2->devid = -deviceid++;
	drv2->offline = 1;
	drv2->active = 1;
	drv2->description = strdup(drv->description);
	drv2->offline_status = DEVICE_SETUP;

	mapidrv_add_device = get_drv_funct(drv->handle, "mapidrv_add_device");
	err = mapidrv_add_device(dev, file, drv2->devid, gflist,
			&drv2->offline_status);

	if (err != 0) {
		report_error(err, pid, sock);
		return;
	}

	// save a reference to the newly created flow to client's flow list
	cl = flist_get(clientlist, pid);
	if (cl == NULL) {
		cl = (struct client *) malloc(sizeof(struct client));
		cl->pid = pid;
		cl->sock = sock;
		// init the list that holds references to the flows of this client
		if ((cl->flowlist = malloc(sizeof(flist_t))) == NULL) {
			DEBUG_CMD(Debug_Message(
					"ERROR: cmd_create_flow - malloc new client struct: %s",
					strerror(errno)));
			exit(EXIT_FAILURE);
		}
		if ((cl->devicelist = malloc(sizeof(flist_t))) == NULL) {
			DEBUG_CMD(Debug_Message(
					"ERROR: cmd_create_flow - malloc new client struct: %s",
					strerror(errno)));
			exit(EXIT_FAILURE);
		}
		flist_init(cl->flowlist);
		flist_init(cl->devicelist);
		cl->numflows = 0;
		flist_append(clientlist, pid, cl);
	}

	flist_append(cl->devicelist, drv2->devid, drv->handle);
	cl->numdevs++;

	//Send ack back to user
	buf.mtype = pid;
	buf.cmd = CREATE_OFFLINE_DEVICE_ACK;
	strcpy((char *)buf.data, drv2->device);
	buf.fd = -1;

	if (format == 0)
		format_ = strdup("MFF_PCAP");
	else if (format == 1)
		format_ = strdup("MFF_RAW");
	else if (format == 2)
		format_ = strdup("MFF_DAG_ERF");
	else if (format == 4)
		format_ = strdup("MFF_NAPATECH");

	if (log_to_file) {
		file_size = acquire_write_lock(log_fd_info);
		write_to_file(
				log_fd_info,
				"MAPID: new offline device was created ( tracefile: %s, format: %s, device name returned: %s ) at ",
				dev, format_, buf.data);
		write_date(log_fd_info);
		write_newline(log_fd_info, "\n");
		release_write_lock(log_fd_info, file_size);
	}
	if (log_to_syslog)
		log_message(
				"new offline device was created ( tracefile: %s, format: %s, device name returned: %s )",
				dev, format_, buf.data);

	free(format_);
	mapiipc_daemon_write((struct mapiipcbuf *) &buf, sock);
}
Beispiel #14
0
static void cmd_create_flow(char *device, int pid, uid_t uid, int sock) /*removed id, id==pid here */
//Create a new flow
//dev = device
//if = IPC id used to send ack message back to client
{
	struct flow *fl = (struct flow *) malloc(sizeof(struct flow));
	struct client *cl;
	struct mapiipcbuf buf;
	char *devtype;
	mapidrv *drv;
	int err = 0;
	char* dev=device;
	long file_size;

	fl->id = pid;
	fl->fd = ++fdseed;
	fl->drv = NULL;
	fl->uid = uid;
	fl->offline = 0;

	if (running_shutdown)
		err = MAPI_SHUTTING_DOWN;

	//Decide which driver to use
	for (drv = drvlist; drv != NULL; drv = drv->next) {
		if (drv->device != NULL)
			if (strcmp(dev, drv->device) == 0) {
				fl->drv = drv;
				DEBUG_CMD(Debug_Message("Using driver %s for %s", drv->name,
						dev));
				break;
			}
	}

	if (fl->drv == NULL) {
		DEBUG_CMD(Debug_Message("No driver found for %s", dev));
		report_error(MAPID_NO_DRIVER, pid, sock);
		free(fl);
		return;
	}

	++flows; //total number of currently registered flows

	//Calls driver
	if (err == 0) {
		mapidrv_create_flow = get_drv_funct(fl->drv->handle,
				"mapidrv_create_flow");
		err = mapidrv_create_flow(drv->devid, fl->fd, &devtype);

	}

	if (err != 0) {
		/* flow wasn't created */
		/* we can't leave the flow in place, but we need it for errno... */
		/* cleanup? */
		flows--;
		report_error(err, pid, sock);
		free(fl);
		return;
	} else {
		flist_append(flowlist, fl->fd, fl);

		//check if this is the first time we hear from this client
		cl = flist_get(clientlist, pid);
		if (cl == NULL) {
			cl = (struct client *) malloc(sizeof(struct client));
			cl->pid = pid;
			cl->sock = sock;
			// init the list that holds references to the flows of this client
			if ((cl->flowlist = malloc(sizeof(flist_t))) == NULL) {
				DEBUG_CMD(Debug_Message(
						"ERROR: cmd_create_flow - malloc new client struct: %s",
						strerror(errno)));
				exit(EXIT_FAILURE);
			}
			flist_init(cl->flowlist);
			if ((cl->devicelist = malloc(sizeof(flist_t))) == NULL) {
				DEBUG_CMD(Debug_Message(
						"ERROR: cmd_create_flow - malloc new client struct: %s",
						strerror(errno)));
				exit(EXIT_FAILURE);
			}
			flist_init(cl->devicelist);
			cl->numflows = 0;
			cl->numdevs = 0;
			flist_append(clientlist, pid, cl);
		}

		// save a reference to the newly created flow to client's flow list
		cl->numflows++;
		flist_append(cl->flowlist, fl->fd, fl);

		//Send ack back to user
		buf.mtype = pid;
		strcpy((char *)buf.data, devtype);
		buf.cmd = CREATE_FLOW_ACK;
		buf.fd = fl->fd;

		if (log_to_file) {
			file_size = acquire_write_lock(log_fd_info);
			write_to_file(log_fd_info,
					"MAPID: new flow was created ( device: %s, fd: %d ) at ",
					device, fl->fd);
			write_date(log_fd_info);
			write_newline(log_fd_info, "\n");
			release_write_lock(log_fd_info, file_size);
		}
		if (log_to_syslog)
			log_message("new flow was created ( device: %s, fd: %d )", device,
					fl->fd);
	}

	mapiipc_daemon_write(&buf, sock);
}
Beispiel #15
0
static void cmd_apply_function(struct mapiipcbuf *qbuf, int pid, int sock)
//Apply function to flow
//qbuf = IPC buffer
//(this function should be changed so that it becomes IPC independent)
{
	int functionid;
	int fd;
	mapidrv *drv;
	mapiFunctArg *args = qbuf->data;
	char *argdescr = (char *)qbuf->argdescr;
	char *function;
	long file_size;

	while (strlen(argdescr) > 0) {
		switch (*argdescr) {
		case 's':
			args += strlen((char *)args) + 1;
			break;
		case 'S': // reference to flows and functions (e.g RES2FILE)
			args += strlen((char *)args) + 1;
			break;
		case 'i':
			args += sizeof(int);
			break;
		case 'r': // reference to a flow
			args += sizeof(int);
			break;
		case 'f': // reference to a fuction
			args += sizeof(int);
			break;
		case 'c':
			args += sizeof(char);
			break;
		case 'l':
			args += sizeof(unsigned long long);
			break;
		case 'u':
			args += sizeof(int);
			break;
		case 'p':
			args += strlen((char *)args) + 1;
			break;
		case 'w':
			qbuf->mtype = get_id(qbuf->fd);
			qbuf->cmd = SEND_FD;
			mapiipc_daemon_write((struct mapiipcbuf *) qbuf, sock);
			fd = mapiipc_read_fd(sock);
			addarg(&args, &fd, INT);
			break;

		default:
			break;
		}
		argdescr++; // move to the next arg
	}

	drv = get_drv(qbuf->fd);
	if (drv == NULL) {
		DEBUG_CMD(Debug_Message(
				"cmd_apply_function: no driver found for fd=%d", qbuf->fd));
		report_error(MAPI_INVALID_FLOW, pid, sock);
		return;
	}
	mapidrv_apply_function = get_drv_funct(drv->handle,
			"mapidrv_apply_function");

	function = strdup(qbuf->function);

	functionid = mapidrv_apply_function(drv->devid, qbuf->fd, APPLY_NORMAL,
			qbuf->function, qbuf->data);

	if (functionid == -1) {
		/* error in mapid */
		report_error(mapid_get_errno(qbuf->fd), pid, sock);
		return;
	}
	qbuf->mtype = get_id(qbuf->fd);
	qbuf->cmd = APPLY_FUNCTION_ACK;
	qbuf->fid = functionid;

	if (log_to_file) {
		file_size = acquire_write_lock(log_fd_info);
		write_to_file(log_fd_info,
				"MAPID: function %s was applyed to flow %d ( fid: %d ) at ",
				function, qbuf->fd, qbuf->fid);
		write_date(log_fd_info);
		write_newline(log_fd_info, "\n");
		release_write_lock(log_fd_info, file_size);
	}
	if (log_to_syslog)
		log_message("function %s was applyed to flow %d ( fid: %d )", function,
				qbuf->fd, qbuf->fid);

	free(function);
	mapiipc_daemon_write((struct mapiipcbuf *) qbuf, sock);
}