Exemplo n.º 1
0
void hime_im_client_clear_flags(HIME_client_handle *handle, int flags, int *ret_flag)
{
  HIME_req req;

  if (!handle)
    return;

  if (is_special_user)
    return;

  if (!gen_req(handle, HIME_req_set_flags, &req))
    return;

  req.flag &= ~flags;

  flags_backup = req.flag;

  if (handle_write(handle, &req, sizeof(req)) <=0) {
    error_proc(handle,"hime_im_client_set_flags error");
  }

  if (handle_read(handle, ret_flag, sizeof(int)) <= 0) {
    error_proc(handle, "cannot read reply str from hime server");
  }
}
Exemplo n.º 2
0
static int hime_im_client_forward_key_event(HIME_client_handle *handle,
                                          HIME_req_t event_type,
                                          KeySym key, u_int state,
                                          char **rstr)
{
  HIME_reply reply;
  HIME_req req;

  *rstr = NULL;

  if (is_special_user) {
      return 0;
  }

  if (!gen_req(handle, event_type, &req))
    return 0;

  req.keyeve.key = key;
  to_hime_endian_4(&req.keyeve.key);
  req.keyeve.state = state;
  to_hime_endian_4(&req.keyeve.state);


  if (handle_write(handle, &req, sizeof(req)) <= 0) {
    error_proc(handle, "cannot write to hime server");
    return FALSE;
  }

  bzero(&reply, sizeof(reply));
  if (handle_read(handle, &reply, sizeof(reply)) <=0) {
    error_proc(handle, "cannot read reply from hime server");
    return FALSE;
  }

  to_hime_endian_4(&reply.datalen);
  to_hime_endian_4(&reply.flag);

  if (reply.datalen > 0) {
    *rstr = (char *)malloc(reply.datalen);
    if (handle_read(handle, *rstr, reply.datalen) <= 0) {
      free(*rstr); *rstr = NULL;
      error_proc(handle, "cannot read reply str from hime server");
      return FALSE;
    }
  }

//  dbg("hime_im_client_forward_key_event %x\n", reply.flag);

  return reply.flag;
}
Exemplo n.º 3
0
void hime_im_client_focus_out2(HIME_client_handle *handle, char **rstr)
{
  HIME_req req;
  HIME_reply reply;

  if (rstr)
    *rstr = NULL;

  if (!handle)
    return;

  if (is_special_user)
    return;

#if DBG
  dbg("hime_im_client_focus_out2\n");
#endif
  handle->flag &= ~FLAG_HIME_client_handle_has_focus;

  if (!gen_req(handle, HIME_req_focus_out2, &req))
    return;

  if (handle_write(handle, &req, sizeof(req)) <=0) {
    error_proc(handle,"hime_im_client_focus_out error");
  }

  bzero(&reply, sizeof(reply));
  if (handle_read(handle, &reply, sizeof(reply)) <=0) {
    error_proc(handle, "cannot read reply from hime server");
    return;
  }

  to_hime_endian_4(&reply.datalen);
  to_hime_endian_4(&reply.flag);

  if (reply.datalen > 0) {
    *rstr = (char *)malloc(reply.datalen);
    if (handle_read(handle, *rstr, reply.datalen) <= 0) {
      free(*rstr); *rstr = NULL;
      error_proc(handle, "cannot read reply str from hime server");
      return;
    }
  }

//  dbg("hime_im_client_forward_key_event %x\n", reply.flag);

  return;
}
Exemplo n.º 4
0
void hime_im_client_focus_out(HIME_client_handle *handle)
{
  if (!handle)
    return;
  if (is_special_user)
    return;

  HIME_req req;
//  dbg("hime_im_client_focus_out\n");
  handle->flag &= ~FLAG_HIME_client_handle_has_focus;

  if (!gen_req(handle, HIME_req_focus_out, &req))
    return;

  if (handle_write(handle, &req, sizeof(req)) <=0) {
    error_proc(handle,"hime_im_client_focus_out error");
  }
}
Exemplo n.º 5
0
void hime_im_client_reset(HIME_client_handle *handle)
{
  if (!handle)
    return;

  if (is_special_user)
    return;

  HIME_req req;
#if DBG
  dbg("hime_im_client_reset\n");
#endif
  if (!gen_req(handle, HIME_req_reset, &req))
    return;

  if (handle_write(handle, &req, sizeof(req)) <=0) {
    error_proc(handle,"hime_im_client_reset error");
  }
}
Exemplo n.º 6
0
void hime_im_client_focus_in(HIME_client_handle *handle)
{
  if (!handle)
    return;
  if (is_special_user)
    return;

  HIME_req req;
//  dbg("hime_im_client_focus_in\n");
  handle->flag |= FLAG_HIME_client_handle_has_focus;

  if (!gen_req(handle, HIME_req_focus_in, &req))
    return;

  if (handle_write(handle, &req, sizeof(req)) <=0) {
    error_proc(handle,"hime_im_client_focus_in error");
  }

  hime_im_client_set_cursor_location(handle, handle->spot_location.x,
     handle->spot_location.y);
}
Exemplo n.º 7
0
void hime_im_client_message(HIME_client_handle *handle, char *message)
{
  HIME_req req;
  short len;
#if DBG
  dbg("hime_im_client_message\n");
#endif
  if (!gen_req(handle, HIME_req_message, &req))
    return;

  if (handle_write(handle, &req, sizeof(req)) <=0) {
    error_proc(handle,"hime_im_client_message error 1");
  }

  len = strlen(message)+1;
  if (handle_write(handle, &len, sizeof(len)) <=0) {
    error_proc(handle,"hime_im_client_message error 2");
  }

  if (handle_write(handle, message, len) <=0) {
    error_proc(handle,"hime_im_client_message error 2");
  }
}
Exemplo n.º 8
0
void hime_im_client_set_cursor_location(HIME_client_handle *handle, int x, int y)
{
  if (!handle)
    return;
  if (is_special_user)
    return;

//  dbg("hime_im_client_set_cursor_location %d   %d,%d\n", handle->flag, x, y);

  HIME_req req;
  handle->spot_location.x = x;
  handle->spot_location.y = y;

  if (!BITON(handle->flag, FLAG_HIME_client_handle_has_focus))
    return;

  if (!gen_req(handle, HIME_req_set_cursor_location, &req))
    return;

  if (handle_write(handle, &req, sizeof(req)) <=0) {
    error_proc(handle,"hime_im_client_set_cursor_location error");
  }
}
Exemplo n.º 9
0
int hime_im_client_get_preedit(HIME_client_handle *handle, char **str, HIME_PREEDIT_ATTR att[], int *cursor ,int *sub_comp_len)
{
  *str=NULL;
  if (!handle)
    return 0;

  if (is_special_user)
    return 0;

  int attN, tcursor, str_len;
#if DBG
  dbg("hime_im_client_get_preedit\n");
#endif
  HIME_req req;
  if (!gen_req(handle, HIME_req_get_preedit, &req)) {
err_ret:
#if DBG
    dbg("aaaaaaaaaaaaa %x\n", str);
#endif
    if (cursor)
      *cursor=0;
    *str=strdup("");
    return 0;
  }

  if (handle_write(handle, &req, sizeof(req)) <=0) {
    error_proc(handle,"hime_im_client_get_preedit error");
    goto err_ret;
  }

  str_len=-1; // str_len includes \0
  if (handle_read(handle, &str_len, sizeof(str_len))<=0)
    goto err_ret; // including \0

  *str = (char *)malloc(str_len);

  if (handle_read(handle, *str, str_len)<=0)
    goto err_ret;
#if DBG
  dbg("hime_im_client_get_preedit len:%d '%s' \n", str_len, *str);
#endif
  attN = -1;
  if (handle_read(handle, &attN, sizeof(attN))<=0) {
    goto err_ret;
  }

//  dbg("attrN:%d\n", attN);

  if (attN>0 && handle_read(handle, att, sizeof(HIME_PREEDIT_ATTR)*attN)<=0) {
    goto err_ret;
  }


  tcursor=0;
  if (handle_read(handle, &tcursor, sizeof(tcursor))<=0) {
    goto err_ret;
  }

  if (cursor)
    *cursor = tcursor;

  int tsub_comp_len;
  tsub_comp_len=0;
  if (handle_read(handle, &tsub_comp_len, sizeof(tsub_comp_len))<=0) {
    goto err_ret;
  }
  if (sub_comp_len)
	*sub_comp_len = tsub_comp_len;

#if DBG
  dbg("jjjjjjjjj %d tcursor:%d\n", attN, tcursor);
#endif
  return attN;
}
Exemplo n.º 10
0
int main ()
{
  int sizeT = POW2(24); 	// n, as denoted by Coelho et al.
  int depth = 20; 	// l, as denoted by Coelho et al.
  int seed = 528;
    clock_t cstart, cend;
  double t_gen, t_req, t_res, t_ver;

  int *T = (int *)malloc(sizeof(int)*sizeT);

  int time0 = time(NULL);

  cstart = clock();

  int i, j;
  for(i = 0; i < sizeT; i++)	// initialize permutation table to each index holding the value of the index
  { 
  	T[i] = i;
  	//printf("%d\n", T[i]);
  }
  //printf("\n\n"); */
  
  gen_permTable(T, sizeT, seed);  // generate the permutation table, which can be used by both the server and client
  
  cend = clock();

  t_gen = (cend - cstart)/(double)CLOCKS_PER_SEC;

  // generate the challenge sequence
  int *v;
  int *w;
  myReq server_chal;

  
  int timeT = time(NULL);
  cstart = clock();
  
  server_chal = gen_req(sizeT, depth, T, seed, v, w);

  cend = clock();

  t_req = (cend - cstart)/(double)CLOCKS_PER_SEC;
  
  int time1 = time(NULL);

  cstart = clock();
  
  int resp = solve_req(server_chal, server_chal.init_cond, server_chal.init_cond, 0, T);  
  
  cend = clock();

  t_res = (cend - cstart)/(double)CLOCKS_PER_SEC;

  cstart = clock();

  int verif = verify_req(server_chal, resp, T);
  
  cend = clock();

  int time2 = time(NULL);
  
  t_ver = (cend - cstart)/(double)CLOCKS_PER_SEC;

  
  printf("Verification results is %d\n", verif);
  
  printf("Total time was %lg, with time spent on solving %lg\ngen table: %lg\ngen req: %lg\nver: %lg\n", t_gen+t_req+t_res+t_ver, t_res, t_gen, t_req, t_ver);
  
  for(i = 0; i < sizeT; i++)
  { 
  	//printf("%x\t%x\n", i, T[i]);
  }
  //printf("\n"); 
  
  free(T);


} // main()