Beispiel #1
0
static void test_sockets_msgapi_tcp(int domain)
{
  #define BUF_SZ          (TCP_SND_BUF/4)
  #define TOTAL_DATA_SZ   (BUF_SZ*8) /* ~(TCP_SND_BUF*2) that accounts for integer rounding */
  #define NEED_TRAILER    (BUF_SZ % 4 != 0)
  int listnr, s1, s2, i, ret, opt;
  int bytes_written, bytes_read;
  struct sockaddr_storage addr_storage;
  socklen_t addr_size;
  struct iovec siovs[8];
  struct msghdr smsg;
  u8_t * snd_buf;
  struct iovec riovs[5];
  struct iovec riovs_tmp[5];
  struct msghdr rmsg;
  u8_t * rcv_buf;
  int    rcv_off;
  int    rcv_trailer = 0;
  u8_t val;

  test_sockets_init_loopback_addr(domain, &addr_storage, &addr_size);

  listnr = test_sockets_alloc_socket_nonblocking(domain, SOCK_STREAM);
  fail_unless(listnr >= 0);
  s1 = test_sockets_alloc_socket_nonblocking(domain, SOCK_STREAM);
  fail_unless(s1 >= 0);

  /* setup a listener socket on loopback with ephemeral port */
  ret = lwip_bind(listnr, (struct sockaddr*)&addr_storage, addr_size);
  fail_unless(ret == 0);
  ret = lwip_listen(listnr, 0);
  fail_unless(ret == 0);

  /* update address with ephemeral port */
  ret = lwip_getsockname(listnr, (struct sockaddr*)&addr_storage, &addr_size);
  fail_unless(ret == 0);

  /* connect, won't complete until we accept it */
  ret = lwip_connect(s1, (struct sockaddr*)&addr_storage, addr_size);
  fail_unless(ret == -1);
  fail_unless(errno == EINPROGRESS);

  while (tcpip_thread_poll_one());

  /* accept, creating the other side of the connection */
  s2 = lwip_accept(listnr, NULL, NULL);
  fail_unless(s2 >= 0);

  /* double check s1 is connected */
  ret = lwip_connect(s1, (struct sockaddr*)&addr_storage, addr_size);
  fail_unless(ret == -1);
  fail_unless(errno == EISCONN);

  /* set s2 to non-blocking, not inherited from listener */
  opt = lwip_fcntl(s2, F_GETFL, 0);
  fail_unless(opt == 6);
  opt = O_NONBLOCK;
  ret = lwip_fcntl(s2, F_SETFL, opt);
  fail_unless(ret == 0);

  /* we are done with listener, close it */
  ret = lwip_close(listnr);
  fail_unless(ret == 0);

  /* allocate a buffer for a stream of incrementing hex (0x00..0xFF) which we will use
     to create an input vector set that is larger than the TCP's send buffer. This will
     force execution of the partial IO vector send case */
  snd_buf = (u8_t*)mem_malloc(BUF_SZ);
  val = 0x00;
  fail_unless(snd_buf != NULL);
  for (i = 0; i < BUF_SZ; i++,val++) {
    snd_buf[i] = val;
  }

  /* send the buffer 8 times in one message, equating to TOTAL_DATA_SZ */
  for (i = 0; i < 8; i++) {
    siovs[i].iov_base = snd_buf;
    siovs[i].iov_len = BUF_SZ;
  }

  /* allocate a receive buffer, same size as snd_buf for easy verification */
  rcv_buf = (u8_t*)mem_calloc(1, BUF_SZ);
  fail_unless(rcv_buf != NULL);
  /* split across iovs */
  for (i = 0; i < 4; i++) {
    riovs[i].iov_base = &rcv_buf[i*(BUF_SZ/4)];
    riovs[i].iov_len = BUF_SZ/4;
  }
  /* handling trailing bytes if buffer doesn't evenly divide by 4 */
#if NEED_TRAILER
  if ((BUF_SZ % 4) != 0) {
    riovs[5].iov_base = &rcv_buf[4*(BUF_SZ/4)];
    riovs[5].iov_len = BUF_SZ - (4*(BUF_SZ/4));
    rcv_trailer = 1;
  }
#endif /* NEED_TRAILER */

  /* we use a copy of riovs since we'll be modifying base and len during
     receiving. This gives us an easy way to reset the iovs for next recvmsg */
  memcpy(riovs_tmp, riovs, sizeof(riovs));

  memset(&smsg, 0, sizeof(smsg));
  smsg.msg_iov = siovs;
  smsg.msg_iovlen = 8;

  memset(&rmsg, 0, sizeof(rmsg));
  rmsg.msg_iov = riovs_tmp;
  rmsg.msg_iovlen = (rcv_trailer ? 5 : 4);

  bytes_written = 0;
  bytes_read = 0;
  rcv_off = 0;

  while (bytes_written < TOTAL_DATA_SZ && (bytes_read < TOTAL_DATA_SZ)) {
    /* send data */
    if (bytes_written < TOTAL_DATA_SZ) {
      ret = lwip_sendmsg(s1, &smsg, 0);
      /* note: since we always receive after sending, there will be open
         space in the send buffer */
      fail_unless(ret > 0);
    
      bytes_written += ret;
      if (bytes_written < TOTAL_DATA_SZ) {
        test_sockets_msgapi_update_iovs(&smsg, (size_t)ret);
      }
    }

    while (tcpip_thread_poll_one());

    /* receive and verify data */
    do {
      if (bytes_read < TOTAL_DATA_SZ) {
        ret = lwip_recvmsg(s2, &rmsg, 0);
        fail_unless(ret > 0 || (ret == -1 && errno == EWOULDBLOCK));

        if (ret > 0) {
          rcv_off += ret;
          /* we have received a full buffer */
          if (rcv_off == BUF_SZ) {
            /* note: since iovs are just pointers, compare underlying buf */
            fail_unless(!memcmp(snd_buf, rcv_buf, BUF_SZ));
            bytes_read += BUF_SZ;
            /* reset receive state for next buffer */
            rcv_off = 0;
            memset(rcv_buf, 0, BUF_SZ);
            memcpy(riovs_tmp, riovs, sizeof(riovs));
            rmsg.msg_iov = riovs_tmp;
            rmsg.msg_iovlen = (rcv_trailer ? 5 : 4);
          } else { /* partial read */
            test_sockets_msgapi_update_iovs(&rmsg, (size_t)ret);
          }
        }
      } else {
        break;
      }
    } while(ret > 0);
  }
  
  ret = lwip_close(s1);
  fail_unless(ret == 0);
  ret = lwip_close(s2);
  fail_unless(ret == 0);
  mem_free(snd_buf);
  mem_free(rcv_buf);
}
static void init(struct fmt_main *self)
{
	size_t maxsize;

	/* Read LWS/GWS prefs from config or environment */
	opencl_get_user_preferences(OCL_CONFIG);

	if (!local_work_size)
		local_work_size = cpu(device_info[gpu_id]) ? 1 : 64;

	if (!global_work_size)
		global_work_size = MAX_KEYS_PER_CRYPT;

	opencl_init("$JOHN/kernels/sha512_kernel.cl", gpu_id, NULL);

	gkey = mem_calloc(global_work_size * sizeof(sha512_key));
	ghash = mem_calloc(global_work_size * sizeof(sha512_hash));

	///Allocate memory on the GPU
	mem_in =
		clCreateBuffer(context[gpu_id], CL_MEM_READ_ONLY, insize, NULL,
		&ret_code);
	HANDLE_CLERROR(ret_code,"Error while allocating memory for passwords");
	mem_out =
		clCreateBuffer(context[gpu_id], CL_MEM_WRITE_ONLY, outsize, NULL,
		&ret_code);
	HANDLE_CLERROR(ret_code,"Error while allocating memory for hashes");
	mem_binary =
		clCreateBuffer(context[gpu_id], CL_MEM_READ_ONLY, sizeof(uint64_t), NULL,
		&ret_code);
	HANDLE_CLERROR(ret_code,"Error while allocating memory for binary");
	mem_cmp =
		clCreateBuffer(context[gpu_id], CL_MEM_WRITE_ONLY, sizeof(uint32_t), NULL,
		&ret_code);
	HANDLE_CLERROR(ret_code,"Error while allocating memory for cmp_all result");

	///Assign crypt kernel parameters
	crypt_kernel = clCreateKernel(program[gpu_id], KERNEL_NAME, &ret_code);
	HANDLE_CLERROR(ret_code,"Error while creating crypt_kernel");
	clSetKernelArg(crypt_kernel, 0, sizeof(mem_in), &mem_in);
	clSetKernelArg(crypt_kernel, 1, sizeof(mem_out), &mem_out);

	///Assign cmp kernel parameters
	cmp_kernel = clCreateKernel(program[gpu_id], CMP_KERNEL_NAME, &ret_code);
	HANDLE_CLERROR(ret_code,"Error while creating cmp_kernel");
	clSetKernelArg(cmp_kernel, 0, sizeof(mem_binary), &mem_binary);
	clSetKernelArg(cmp_kernel, 1, sizeof(mem_out), &mem_out);
	clSetKernelArg(cmp_kernel, 2, sizeof(mem_cmp), &mem_cmp);

	/* Note: we ask for the kernel's max size, not the device's! */
	maxsize = get_kernel_max_lws(gpu_id, crypt_kernel);

	if (local_work_size > maxsize) {
		local_work_size = maxsize;
		global_work_size = (global_work_size + local_work_size - 1) / local_work_size * local_work_size;
	}

	self->params.max_keys_per_crypt = global_work_size;
	if (!local_work_size)
		opencl_find_best_workgroup(self);

	self->params.min_keys_per_crypt = local_work_size;

	if (options.verbosity > 2)
		fprintf(stderr, "Local worksize (LWS) %d, Global worksize (GWS) %d\n",(int)local_work_size, (int)global_work_size);
}
Beispiel #3
0
void http_send_header(struct connection *c)
{
    static unsigned char *accept_charset = NULL;
    struct http_connection_info *info;
    int http10 = http_bugs.http10;
    struct cache_entry *e = NULL;
    unsigned char *hdr;
    unsigned char *h, *u;
    int l = 0;
    int la;
    unsigned char *post;
    unsigned char *host;

    find_in_cache(c->url, &c->cache);

    host = upcase(c->url[0]) != 'P' ? c->url : get_url_data(c->url);
    set_timeout(c);
    info = mem_calloc(sizeof(struct http_connection_info));
    c->info = info;
    if ((h = get_host_name(host))) {
        info->bl_flags = get_blacklist_flags(h);
        mem_free(h);
    }
    if (info->bl_flags & BL_HTTP10) http10 = 1;
    info->http10 = http10;
    post = strchr(host, POST_CHAR);
    if (post) post++;
    hdr = init_str();
    if (!post) add_to_str(&hdr, &l, "GET ");
    else {
        add_to_str(&hdr, &l, "POST ");
        c->unrestartable = 2;
    }
    if (upcase(c->url[0]) != 'P') add_to_str(&hdr, &l, "/");
    if (!(u = get_url_data(c->url))) {
        mem_free(hdr);
        setcstate(c, S_BAD_URL);
        http_end_request(c, 0);
        return;
    }
    if (post && post < u) {
        mem_free(hdr);
        setcstate(c, S_BAD_URL);
        http_end_request(c, 0);
        return;
    }
    add_url_to_str(&hdr, &l, u);
    if (!http10) add_to_str(&hdr, &l, " HTTP/1.1\r\n");
    else add_to_str(&hdr, &l, " HTTP/1.0\r\n");
    if ((h = get_host_name(host))) {
        add_to_str(&hdr, &l, "Host: ");
        add_to_str(&hdr, &l, h);
        mem_free(h);
        if ((h = get_port_str(host))) {
            add_to_str(&hdr, &l, ":");
            add_to_str(&hdr, &l, h);
            mem_free(h);
        }
        add_to_str(&hdr, &l, "\r\n");
    }
    add_to_str(&hdr, &l, "User-Agent: ");
    if (!(*http_bugs.fake_useragent)) {
        add_to_str(&hdr, &l, "Links (" VERSION_STRING "; ");
        add_to_str(&hdr, &l, system_name);
        if (!F && !list_empty(terminals)) {
            struct terminal *t = terminals.prev;
            if (!t->spec->braille) {
                add_to_str(&hdr, &l, "; ");
                add_num_to_str(&hdr, &l, t->x);
                add_to_str(&hdr, &l, "x");
                add_num_to_str(&hdr, &l, t->y);
            } else {
                add_to_str(&hdr, &l, "; braille");
            }
        }
#ifdef G
        if (F && drv) {
            add_to_str(&hdr, &l, "; ");
            add_to_str(&hdr, &l, drv->name);
        }
#endif
        add_to_str(&hdr, &l, ")\r\n");
    }
    else {
        add_to_str(&hdr, &l, http_bugs.fake_useragent);
        add_to_str(&hdr, &l, "\r\n");
    }
    switch (http_bugs.referer)
    {
    case REFERER_FAKE:
        add_to_str(&hdr, &l, "Referer: ");
        add_to_str(&hdr, &l, http_bugs.fake_referer);
        add_to_str(&hdr, &l, "\r\n");
        break;

    case REFERER_SAME_URL:
        add_to_str(&hdr, &l, "Referer: ");
        add_url_to_str(&hdr, &l, host);
        add_to_str(&hdr, &l, "\r\n");
        break;

    case REFERER_REAL_SAME_SERVER:
    {
        unsigned char *h, *j;
        int brk = 1;
        if ((h = get_host_name(host))) {
            if ((j = get_host_name(c->prev_url))) {
                if (!strcasecmp(h, j)) brk = 0;
                mem_free(j);
            }
            mem_free(h);
        }
        if (brk) break;
        /* fall through */
    }
    case REFERER_REAL:
    {
        unsigned char *ref;
        unsigned char *user, *ins;
        int ulen;
        if (!(c->prev_url)) break;   /* no referrer */

        ref = stracpy(c->prev_url);
        if (!parse_url(ref, NULL, &user, &ulen, NULL, NULL, &ins, NULL, NULL, NULL, NULL, NULL, NULL) && ulen && ins) {
            memmove(user, ins, strlen(ins) + 1);
        }
        add_to_str(&hdr, &l, "Referer: ");
        add_url_to_str(&hdr, &l, ref);
        add_to_str(&hdr, &l, "\r\n");
        mem_free(ref);
    }
    break;
    }

    add_to_str(&hdr, &l, "Accept: */*\r\n");
#if defined(HAVE_ZLIB) || defined(HAVE_BZIP2)
    if (!http_bugs.no_compression && !(info->bl_flags & BL_NO_COMPRESSION)) {
        int q = strlen(c->url);
        if (q >= 2 && !strcasecmp(c->url + q - 2, ".Z")) goto skip_compress;
        if (q >= 3 && !strcasecmp(c->url + q - 3, ".gz")) goto skip_compress;
        if (q >= 4 && !strcasecmp(c->url + q - 4, ".bz2")) goto skip_compress;
        add_to_str(&hdr, &l, "Accept-Encoding: ");
#if defined(HAVE_ZLIB)
        add_to_str(&hdr, &l, "gzip, deflate, ");
#endif
#if defined(HAVE_BZIP2)
        add_to_str(&hdr, &l, "bzip2, ");
#endif
        hdr[l-2] = '\r';
        hdr[l-1] = '\n';
skip_compress:
        ;
    }
#endif
    if (!(accept_charset)) {
        int i;
        unsigned char *cs, *ac;
        int aclen = 0;
        ac = init_str();
        for (i = 0; (cs = get_cp_mime_name(i)); i++) {
            if (aclen) add_to_str(&ac, &aclen, ", ");
            else add_to_str(&ac, &aclen, "Accept-Charset: ");
            add_to_str(&ac, &aclen, cs);
        }
        if (aclen) add_to_str(&ac, &aclen, "\r\n");
        if ((accept_charset = malloc(strlen(ac) + 1))) strcpy(accept_charset, ac);
        else accept_charset = "";
        mem_free(ac);
    }
    if (!(info->bl_flags & BL_NO_CHARSET) && !http_bugs.no_accept_charset) add_to_str(&hdr, &l, accept_charset);
    if (!(info->bl_flags & BL_NO_ACCEPT_LANGUAGE)) {
        add_to_str(&hdr, &l, "Accept-Language: ");
        la = l;
        add_to_str(&hdr, &l, _(TEXT(T__ACCEPT_LANGUAGE), NULL));
        add_to_str(&hdr, &l, ", ");
        if (!strstr(hdr + la, "en,") && !strstr(hdr + la, "en;")) add_to_str(&hdr, &l, "en;q=0.2, ");
        add_to_str(&hdr, &l, "*;q=0.1\r\n");
    }
    if (!http10) {
        if (upcase(c->url[0]) != 'P') add_to_str(&hdr, &l, "Connection: ");
        else add_to_str(&hdr, &l, "Proxy-Connection: ");
        if (!post || !http_bugs.bug_post_no_keepalive) add_to_str(&hdr, &l, "Keep-Alive\r\n");
        else add_to_str(&hdr, &l, "close\r\n");
    }
    if ((e = c->cache)) {
        int code, vers;
        if (get_http_code(e->head, &code, &vers) || code >= 400) goto skip_ifmod_and_range;
        if (!e->incomplete && e->head && c->no_cache <= NC_IF_MOD) {
            unsigned char *m;
            if (e->last_modified) m = stracpy(e->last_modified);
            else if ((m = parse_http_header(e->head, "Date", NULL))) ;
            else if ((m = parse_http_header(e->head, "Expires", NULL))) ;
            else goto skip_ifmod;
            add_to_str(&hdr, &l, "If-Modified-Since: ");
            add_to_str(&hdr, &l, m);
            add_to_str(&hdr, &l, "\r\n");
            mem_free(m);
        }
skip_ifmod:
        ;
    }
    if (c->from && (c->est_length == -1 || c->from < c->est_length) && c->no_cache < NC_IF_MOD && !(info->bl_flags & BL_NO_RANGE)) {
        /* If the cached entity is compressed and we turned off compression,
           request the whole file */
        if ((info->bl_flags & BL_NO_COMPRESSION || http_bugs.no_compression) && e) {
            unsigned char *d;
            if ((d = parse_http_header(e->head, "Transfer-Encoding", NULL))) {
                mem_free(d);
                goto skip_range;
            }
        }
        add_to_str(&hdr, &l, "Range: bytes=");
        add_num_to_str(&hdr, &l, c->from);
        add_to_str(&hdr, &l, "-\r\n");
skip_range:
        ;
    }
skip_ifmod_and_range:
    if (c->no_cache >= NC_PR_NO_CACHE) add_to_str(&hdr, &l, "Pragma: no-cache\r\nCache-Control: no-cache\r\n");
    if ((h = get_auth_string(c->url))) {
        add_to_str(&hdr, &l, h);
        mem_free(h);
    }
    if (post) {
        unsigned char *pd = strchr(post, '\n');
        if (pd) {
            add_to_str(&hdr, &l, "Content-Type: ");
            add_bytes_to_str(&hdr, &l, post, pd - post);
            add_to_str(&hdr, &l, "\r\n");
            post = pd + 1;
        }
        add_to_str(&hdr, &l, "Content-Length: ");
        add_num_to_str(&hdr, &l, strlen(post) / 2);
        add_to_str(&hdr, &l, "\r\n");
    }
    send_cookies(&hdr, &l, host);
    add_to_str(&hdr, &l, "\r\n");
    if (post) {
        while (post[0] && post[1]) {
            int h1, h2;
            h1 = post[0] <= '9' ? (unsigned)post[0] - '0' : post[0] >= 'A' ? upcase(post[0]) - 'A' + 10 : 0;
            if (h1 < 0 || h1 >= 16) h1 = 0;
            h2 = post[1] <= '9' ? (unsigned)post[1] - '0' : post[1] >= 'A' ? upcase(post[1]) - 'A' + 10 : 0;
            if (h2 < 0 || h2 >= 16) h2 = 0;
            add_chr_to_str(&hdr, &l, h1 * 16 + h2);
            post += 2;
        }
    }
    write_to_socket(c, c->sock1, hdr, l, http_get_header);
    mem_free(hdr);
    setcstate(c, S_SENT);
}
Beispiel #4
0
struct auth_entry *add_auth_entry( struct uri *uri, unsigned char *realm, unsigned char *nonce, unsigned char *opaque, unsigned int digest )
{
  int eax;
  int edx;
  struct auth_entry *entry;
  if ( find_auth_entry( uri, realm ) == 0 )
  {
    entry = (struct auth_entry*)mem_calloc( 1, 116 );
    if ( mem_calloc( 1, 116 ) == 0 )
    {
      return &entry[0];
    }
    uri->object.refcount = uri->object.refcount;
    *(int*)(mem_calloc( 1, 116 ) + 12) = uri[0];
    if ( realm )
    {
      *(int*)(mem_calloc( 1, 116 ) + 16) = stracpy( realm );
      if ( mem_calloc( 1, 116 ) + 16 == 0 )
      {
        mem_free( &ecx );
        return &entry[0];
      }
    }
    set_auth_user( &ecx, &uri[0] );
    set_auth_password( ebp_28, &uri[0] );
    *(int*)(ebp_28 + 28) = eax;
    if ( ebp_28 + 28 == 0 )
    {
      done_auth_entry( &ecx );
      return &entry[0];
    }
    *(int*)(ecx + 4) = auth_entry_list.next;
    ecx = auth_entry_list.next;
    auth_entry_list.next = &ecx;
    *(int*)(ecx + 4) = ecx;
    if ( nonce )
    {
      auth_entry_list.next[6] = stracpy( nonce );
      if ( auth_entry_list.next + 4 + 20 == 0 )
      {
        del_auth_entry( &ecx );
        return &entry[0];
      }
    }
    if ( opaque )
    {
      *(int*)(ebp_28 + 24) = stracpy( opaque );
      if ( ebp_28 + 24 == 0 )
      {
        del_auth_entry( &ecx );
        return &entry[0];
      }
    }
    auth_entry_list.next[29] = ( *(char*)(auth_entry_list.next + 4 + 112) & -5 ) | ( ( (int)digest/*.1_1of4*/ & 1 ) << 2 );
  }
  else
  {
    if ( ( ( *(char*)(find_auth_entry( uri, realm ) + 112) & 1 ) & 255 ) == 0 )
    {
      if ( (unsigned char)( realm != 0 ) == ( *(int*)(entry[0].next + 16) != 0 ) )
      {
        if ( ( ( realm != 0 ) & 255 ) && ebp_41 && stracpy( opaque ) )
          entry->realm[0] = entry->realm;
        else
        {
          if ( entry->user[0] && uri->user && uri->bits_at_40/*.3_4of4*/ )
          {
            errfile = "/home/naftali/source/elinks-0.12~pre5/src/protocol/auth/auth.c";
            errline = 185;
            if ( elinks_strlcmp( &entry->user[0], -1, uri->user, uri->bits_at_40/*.3_4of4*/ ) == 0 )
            {
              if ( entry->password[0] && uri->password && uri->bits_at_44/*.1_2of4*/ )
              {
                errfile = "/home/naftali/source/elinks-0.12~pre5/src/protocol/auth/auth.c";
                errline = 192;
                if ( elinks_strlcmp( &entry->password[0], -1, uri->password, (int)uri->bits_at_44/*.1_2of4*/ ) )
                  goto B36;
              }
B36:              entry->bits_at_112/*.1_1of4*/ &= 253;
              set_auth_password( &entry[0], &uri[0] );
            }
          }
          entry->bits_at_112/*.1_1of4*/ &= 253;
          set_auth_user( &entry[0], &uri[0] );
        }
      }
      entry->bits_at_112/*.1_1of4*/ = (int)entry->bits_at_112/*.1_1of4*/ & -3;
      if ( entry->realm )
        mem_free( (void*)entry->realm );
      entry->realm = 0;
      if ( ( realm != 0 ) & 255 )
      {
        entry->realm = stracpy( realm );
        if ( entry->realm )
        {
          if ( nonce )
          {
            if ( entry->nonce )
              mem_free( (void*)entry->nonce );
            entry->nonce = stracpy( nonce );
            if ( entry->nonce == 0 )
              goto B23;
          }
          if ( opaque )
          {
            if ( entry->opaque )
              mem_free( (void*)entry->opaque );
            entry->opaque = stracpy( opaque );
            if ( entry->opaque == 0 )
            {
              del_auth_entry( &entry[0] );
              uri = &uri[0];
              return 0;
            }
          }
          entry->bits_at_112/*.1_1of4*/ = ( *(char*)(entry[0].next + 112) & -5 ) | ( ( (int)digest/*.1_1of4*/ & 1 ) << 2 );
        }
B23:        &entry[0] = 0;
        del_auth_entry( &entry[0] );
        return &entry[0];
      }
    }
    else
    {
      return 0;
    }
  }
  if ( !( ( entry->bits_at_112/*.1_1of4*/ & 2 ) & 255 ) && entry->realm )
  {
    add_questions_entry( &do_auth_dialog, (void*)entry[0].next );
    return &entry[0];
  }
  return &entry[0];
}
Beispiel #5
0
/*!
 ************************************************************************
 * \brief
 *    read the memory control operations
 ************************************************************************
 */
void dec_ref_pic_marking(VideoParameters *p_Vid, Bitstream *currStream, Slice *pSlice)
{
  int val;

  DecRefPicMarking_t *tmp_drpm,*tmp_drpm2;

  // free old buffer content
  while (pSlice->dec_ref_pic_marking_buffer)
  {
    tmp_drpm=pSlice->dec_ref_pic_marking_buffer;

    pSlice->dec_ref_pic_marking_buffer=tmp_drpm->Next;
    mem_free (tmp_drpm);
  }

#if (MVC_EXTENSION_ENABLE)
  if ( pSlice->idr_flag || (pSlice->svc_extension_flag == 0 && pSlice->NaluHeaderMVCExt.non_idr_flag == 0) )
#else
  if (pSlice->idr_flag)
#endif
  {
    pSlice->no_output_of_prior_pics_flag = read_u_1("SH: no_output_of_prior_pics_flag", currStream, &p_Dec->UsedBits);
    p_Vid->no_output_of_prior_pics_flag = pSlice->no_output_of_prior_pics_flag;
    pSlice->long_term_reference_flag = read_u_1("SH: long_term_reference_flag", currStream, &p_Dec->UsedBits);
  }
  else
  {
    pSlice->adaptive_ref_pic_buffering_flag = read_u_1("SH: adaptive_ref_pic_buffering_flag", currStream, &p_Dec->UsedBits);
    if (pSlice->adaptive_ref_pic_buffering_flag)
    {
      // read Memory Management Control Operation
      do
      {
        tmp_drpm=(DecRefPicMarking_t*)mem_calloc (1,sizeof (DecRefPicMarking_t));
        tmp_drpm->Next=NULL;

        val = tmp_drpm->memory_management_control_operation = read_ue_v("SH: memory_management_control_operation", currStream, &p_Dec->UsedBits);

        if ((val==1)||(val==3))
        {
          tmp_drpm->difference_of_pic_nums_minus1 = read_ue_v("SH: difference_of_pic_nums_minus1", currStream, &p_Dec->UsedBits);
        }
        if (val==2)
        {
          tmp_drpm->long_term_pic_num = read_ue_v("SH: long_term_pic_num", currStream, &p_Dec->UsedBits);
        }

        if ((val==3)||(val==6))
        {
          tmp_drpm->long_term_frame_idx = read_ue_v("SH: long_term_frame_idx", currStream, &p_Dec->UsedBits);
        }
        if (val==4)
        {
          tmp_drpm->max_long_term_frame_idx_plus1 = read_ue_v("SH: max_long_term_pic_idx_plus1", currStream, &p_Dec->UsedBits);
        }

        // add command
        if (pSlice->dec_ref_pic_marking_buffer==NULL)
        {
          pSlice->dec_ref_pic_marking_buffer=tmp_drpm;
        }
        else
        {
          tmp_drpm2=pSlice->dec_ref_pic_marking_buffer;
          while (tmp_drpm2->Next!=NULL) tmp_drpm2=tmp_drpm2->Next;
          tmp_drpm2->Next=tmp_drpm;
        }

      }
      while (val != 0);
    }
  }
}
static void init(struct fmt_main *self)
{
	cl_int cl_error;
	char *temp;
	char build_opts[64];
	cl_ulong maxsize;

	snprintf(build_opts, sizeof(build_opts),
	         "-DKEYLEN=%d -DSALTLEN=%d -DOUTLEN=%d",
	         PLAINTEXT_LENGTH,
	         (int)sizeof(currentsalt.salt),
	         (int)sizeof(outbuffer->v));
	opencl_init_opt("$JOHN/kernels/pbkdf2_hmac_sha1_unsplit_kernel.cl",
	                ocl_gpu_id, build_opts);

	if ((temp = getenv("LWS")))
		local_work_size = atoi(temp);
	else
		local_work_size = cpu(device_info[ocl_gpu_id]) ? 1 : 64;

	if ((temp = getenv("GWS")))
		global_work_size = atoi(temp);
	else
		global_work_size = MAX_KEYS_PER_CRYPT;

	crypt_kernel = clCreateKernel(program[ocl_gpu_id], "derive_key", &cl_error);
	HANDLE_CLERROR(cl_error, "Error creating kernel");

	/* Note: we ask for the kernels' max sizes, not the device's! */
	HANDLE_CLERROR(clGetKernelWorkGroupInfo(crypt_kernel, devices[ocl_gpu_id], CL_KERNEL_WORK_GROUP_SIZE, sizeof(maxsize), &maxsize, NULL), "Query max workgroup size");

	while (local_work_size > maxsize)
		local_work_size >>= 1;

	/// Allocate memory
	inbuffer =
		(zip_password *) mem_calloc(sizeof(zip_password) *
		                            global_work_size);
	outbuffer =
	    (zip_hash *) mem_alloc(sizeof(zip_hash) * global_work_size);

	cracked = mem_calloc(sizeof(*cracked) * global_work_size);

	/// Allocate memory
	mem_in =
	    clCreateBuffer(context[ocl_gpu_id], CL_MEM_READ_ONLY, insize, NULL,
	    &cl_error);
	HANDLE_CLERROR(cl_error, "Error allocating mem in");
	mem_setting =
	    clCreateBuffer(context[ocl_gpu_id], CL_MEM_READ_ONLY, settingsize,
	    NULL, &cl_error);
	HANDLE_CLERROR(cl_error, "Error allocating mem setting");
	mem_out =
	    clCreateBuffer(context[ocl_gpu_id], CL_MEM_WRITE_ONLY, outsize, NULL,
	    &cl_error);
	HANDLE_CLERROR(cl_error, "Error allocating mem out");

	HANDLE_CLERROR(clSetKernelArg(crypt_kernel, 0, sizeof(mem_in),
		&mem_in), "Error while setting mem_in kernel argument");
	HANDLE_CLERROR(clSetKernelArg(crypt_kernel, 1, sizeof(mem_out),
		&mem_out), "Error while setting mem_out kernel argument");
	HANDLE_CLERROR(clSetKernelArg(crypt_kernel, 2, sizeof(mem_setting),
		&mem_setting), "Error while setting mem_salt kernel argument");

	self->params.max_keys_per_crypt = global_work_size;
	if (!local_work_size)
		opencl_find_best_workgroup(self);

	self->params.min_keys_per_crypt = local_work_size;

	if (options.verbosity > 2)
		fprintf(stderr, "Local worksize (LWS) %d, Global worksize (GWS) %d\n", (int)local_work_size, (int)global_work_size);
}
Beispiel #7
0
/*
 * menu_create_datainfo - メニュー情報にデータを展開
 */
static BOOL menu_create_datainfo(DATA_INFO *set_di,
								MENU_ITEM_INFO *mii, int menu_index, int *id,
								const int step, const int min, const int max)
{
	DATA_INFO *di;
	DATA_INFO *cdi;
	MENU_ITEM_INFO *cmi;
	TCHAR buf[BUF_SIZE * 2];
	TCHAR tmp[BUF_SIZE];
	TCHAR *p;
	int cnt;
	int i, j;
	int m, n;

	// 初期位置移動
	for (m = 0; set_di != NULL && min > 0 && m < min - 1; set_di = set_di->next, m++)
		;
	if (step < 0) {
		// 降順
		for (di = set_di, i = 0, n = m; di != NULL && (max <= 0 || n < max); di = di->next, i++, n++)
			;
		i += menu_index - 1;
	} else {
		// 昇順
		i = menu_index;
	}

	for (di = set_di,j = 0; di != NULL && (max <= 0 || m < max); di = di->next, i += step, m++) {
		(mii + i)->id = ID_MENUITEM_DATA + ((*id)++);
		(mii + i)->item = (LPCTSTR)(mii + i);
		(mii + i)->set_di = di;

		switch (di->type) {
		case TYPE_FOLDER:
			// 階層表示
			(mii + i)->flag = MF_POPUP | MF_OWNERDRAW;
			(mii + i)->show_di = di;

			for (cdi = di->child, cnt = 0; cdi != NULL; cdi = cdi->next, cnt++)
				;
			// メニュー項目情報の確保
			if ((cmi = mem_calloc(sizeof(MENU_ITEM_INFO) * cnt)) == NULL) {
				return FALSE;
			}
			(mii + i)->mii = cmi;
			(mii + i)->mii_cnt = cnt;
			menu_create_datainfo(di->child, cmi, 0, id, step, 0, 0);
			break;

		case TYPE_ITEM:
			// アイテム
			(mii + i)->flag = MF_OWNERDRAW;
			(mii + i)->show_di = format_get_priority_highest(di);
			break;

		case TYPE_DATA:
			// データ
			(mii + i)->flag = MF_OWNERDRAW;
			(mii + i)->show_di = di;
			break;
		}

		// メニューに表示するタイトルを取得
		format_get_menu_title((mii + i)->show_di);
		// タイトルを設定
		if (di->title != NULL) {
			if (lstrcmp(di->title, TEXT("-")) == 0) {
				// 区切り
				(mii + i)->id = 0;
				(mii + i)->flag = MF_SEPARATOR | MF_OWNERDRAW;
				(mii + i)->item = (LPCTSTR)(mii + i);
				continue;
			} else if (option.menu_intact_item_title == 0) {
				menu_create_text(j++, di->title, buf);
				(mii + i)->text = alloc_copy(buf);
			} else {
				(mii + i)->text = alloc_copy(di->title);
			}

		} else if ((mii + i)->show_di->menu_title != NULL) {
			menu_create_text(j++, (mii + i)->show_di->menu_title, buf);
			(mii + i)->text = alloc_copy(buf);

		} else if ((mii + i)->show_di->format_name != NULL) {
			// 形式名
			p = tmp;
			*(p++) = TEXT('(');
			lstrcpyn(p, (mii + i)->show_di->format_name, BUF_SIZE - 3);
			p += lstrlen(p);
			*(p++) = TEXT(')');
			*(p++) = TEXT('\0');
			menu_create_text(j++, tmp, buf);
			(mii + i)->text = alloc_copy(buf);
			(mii + i)->show_format = TRUE;

		} else {
			(mii + i)->text = alloc_copy(TEXT(""));
		}

		if (option.menu_show_hotkey == 1) {
			// ホットキー取得
			(mii + i)->hkey = menu_get_keyname(di->op_modifiers, di->op_virtkey);
		}

		if (option.menu_show_icon == 1) {
			// メニューに表示するアイコンを取得
			format_get_menu_icon((mii + i)->show_di);
			if ((mii + i)->show_di->menu_icon == NULL) {
				(mii + i)->icon = (di->type == TYPE_FOLDER) ? icon_menu_folder : icon_menu_default;
			} else {
				(mii + i)->icon = (mii + i)->show_di->menu_icon;
			}
			(mii + i)->free_icon = FALSE;

			// メニューに表示するビットマップを取得
			if (option.menu_show_bitmap == 1) {
				format_get_menu_bitmap((mii + i)->show_di);
			}
			(mii + i)->show_bitmap = (option.menu_show_bitmap == 1 &&
				(mii + i)->show_di->menu_bitmap != NULL) ? TRUE : FALSE;
		}
	}
	return TRUE;
}
static void *get_salt(char *ciphertext)
{
	int i;
	my_salt salt, *psalt;
	static unsigned char *ptr;
	/* extract data from "ciphertext" */
	u8 *copy_mem = (u8*)strdup(ciphertext);
	u8 *cp, *p;

	if (!ptr) ptr = mem_alloc_tiny(sizeof(my_salt*),sizeof(my_salt*));
	p = copy_mem + TAG_LENGTH+1; /* skip over "$zip2$*" */
	memset(&salt, 0, sizeof(salt));
	p = pkz_GetFld(p, &cp); // type
	salt.v.type = atoi((const char*)cp);
	p = pkz_GetFld(p, &cp); // mode
	salt.v.mode = atoi((const char*)cp);
	p = pkz_GetFld(p, &cp); // file_magic enum (ignored)
	p = pkz_GetFld(p, &cp); // salt
	for (i = 0; i < SALT_LENGTH(salt.v.mode); i++)
		salt.salt[i] = (atoi16[ARCH_INDEX(cp[i<<1])]<<4) | atoi16[ARCH_INDEX(cp[(i<<1)+1])];
	p = pkz_GetFld(p, &cp);	// validator
	salt.passverify[0] = (atoi16[ARCH_INDEX(cp[0])]<<4) | atoi16[ARCH_INDEX(cp[1])];
	salt.passverify[1] = (atoi16[ARCH_INDEX(cp[2])]<<4) | atoi16[ARCH_INDEX(cp[3])];
	p = pkz_GetFld(p, &cp);	// data len
	sscanf((const char *)cp, "%x", &salt.comp_len);

	// later we will store the data blob in our own static data structure, and place the 64 bit LSB of the
	// MD5 of the data blob into a field in the salt. For the first POC I store the entire blob and just
	// make sure all my test data is small enough to fit.

	p = pkz_GetFld(p, &cp);	// data blob

	// Ok, now create the allocated salt record we are going to return back to John, using the dynamic
	// sized data buffer.
	psalt = (my_salt*)mem_calloc(1, sizeof(my_salt) + salt.comp_len);
	psalt->v.type = salt.v.type;
	psalt->v.mode = salt.v.mode;
	psalt->comp_len = salt.comp_len;
	psalt->dsalt.salt_alloc_needs_free = 1;  // we used mem_calloc, so JtR CAN free our pointer when done with them.
	memcpy(psalt->salt, salt.salt, sizeof(salt.salt));
	psalt->passverify[0] = salt.passverify[0];
	psalt->passverify[1] = salt.passverify[1];

	// set the JtR core linkage stuff for this dyna_salt
	psalt->dsalt.salt_cmp_offset = SALT_CMP_OFF(my_salt, comp_len);
	psalt->dsalt.salt_cmp_size = SALT_CMP_SIZE(my_salt, comp_len, datablob, psalt->comp_len);


	if (strcmp((const char*)cp, "ZFILE")) {
	for (i = 0; i < psalt->comp_len; i++)
		psalt->datablob[i] = (atoi16[ARCH_INDEX(cp[i<<1])]<<4) | atoi16[ARCH_INDEX(cp[(i<<1)+1])];
	} else {
		u8 *Fn, *Oh, *Ob;
		long len;
		uint32_t id;
		FILE *fp;

		p = pkz_GetFld(p, &Fn);
		p = pkz_GetFld(p, &Oh);
		p = pkz_GetFld(p, &Ob);

		fp = fopen((const char*)Fn, "rb");
		if (!fp) {
			psalt->v.type = 1; // this will tell the format to 'skip' this salt, it is garbage
			goto Bail;
		}
		sscanf((const char*)Oh, "%lx", &len);
		if (fseek(fp, len, SEEK_SET)) {
			fclose(fp);
			psalt->v.type = 1;
			goto Bail;
		}
		id = fget32LE(fp);
		if (id != 0x04034b50U) {
			fclose(fp);
			psalt->v.type = 1;
			goto Bail;
		}
		sscanf((const char*)Ob, "%lx", &len);
		if (fseek(fp, len, SEEK_SET)) {
			fclose(fp);
			psalt->v.type = 1;
			goto Bail;
		}
		if (fread(psalt->datablob, 1, psalt->comp_len, fp) != psalt->comp_len) {
			fclose(fp);
			psalt->v.type = 1;
			goto Bail;
		}
		fclose(fp);
	}
Bail:
	MEM_FREE(copy_mem);

	memcpy(ptr, &psalt, sizeof(my_salt*));
	return (void*)ptr;
}
Beispiel #9
0
/*
 * tooltip_proc - ツールチップ
 */
static LRESULT CALLBACK tooltip_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	NONCLIENTMETRICS ncMetrics;
	PAINTSTRUCT ps;
	DRAWTEXTPARAMS dtp;
	RECT rect;
	POINT pt;
	HDC hdc;
	HFONT hRetFont;
	TOOLTIP_INFO *ti;

	switch (msg) {
	case WM_CREATE:
		if ((ti = mem_calloc(sizeof(TOOLTIP_INFO))) == NULL) {
			return -1;
		}
		if (*option.tooltip_font_name != TEXT('\0')) {
			// フォント作成
			ti->hfont = font_create(option.tooltip_font_name,
				option.tooltip_font_size, option.tooltip_font_charset, option.tooltip_font_weight,
				(option.tooltip_font_italic == 0) ? FALSE : TRUE, FALSE);
		} else {
			ncMetrics.cbSize = sizeof(NONCLIENTMETRICS);
			if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
				sizeof(NONCLIENTMETRICS), &ncMetrics, 0) == TRUE) {
				// デフォルトのフォント作成
				ti->hfont = CreateFontIndirect(&ncMetrics.lfStatusFont);
			}
		}
		// tooltip info to window long
		SetWindowLong(hWnd, GWL_USERDATA, (LPARAM)ti);
		break;

	case WM_CLOSE:
		DestroyWindow(hWnd);
		break;

	case WM_DESTROY:
		if ((ti = (TOOLTIP_INFO *)GetWindowLong(hWnd, GWL_USERDATA)) != NULL) {
			if (ti->hfont != NULL) {
				DeleteObject(ti->hfont);
				ti->hfont = NULL;
			}
			if (ti->buf != NULL) {
				mem_free(&ti->buf);
			}
			mem_free(&ti);
		}
		return DefWindowProc(hWnd, msg, wParam, lParam);

	case WM_SETTINGCHANGE:
		if ((ti = (TOOLTIP_INFO *)GetWindowLong(hWnd, GWL_USERDATA)) == NULL ||
			*option.tooltip_font_name != TEXT('\0') ||
			wParam != SPI_SETNONCLIENTMETRICS) {
			break;
		}
		if (ti->hfont != NULL) {
			DeleteObject(ti->hfont);
			ti->hfont = NULL;
		}
		ncMetrics.cbSize = sizeof(NONCLIENTMETRICS);
		if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
			sizeof(NONCLIENTMETRICS), &ncMetrics, 0) == TRUE) {
			// デフォルトのフォント作成
			ti->hfont = CreateFontIndirect(&ncMetrics.lfStatusFont);
		}
		break;

#ifdef TOOLTIP_ANIMATE
	case WM_PRINT:
		// テキスト描画
		if ((ti = (TOOLTIP_INFO *)GetWindowLong(hWnd, GWL_USERDATA)) == NULL) {
			break;
		}
		// 非クライアントエリアの描画
		DefWindowProc(hWnd, msg, wParam, lParam);

		// ツールチップの描画
		GetClientRect(hWnd, (LPRECT)&rect);
		SetRect(&rect, rect.left + 1, rect.top + 1, rect.right + 1, rect.bottom + 1);
		tooltip_draw_text(ti, (HDC)wParam, &rect);
		break;
#endif

	case WM_PAINT:
		// テキスト描画
		if ((ti = (TOOLTIP_INFO *)GetWindowLong(hWnd, GWL_USERDATA)) == NULL) {
			break;
		}
		hdc = BeginPaint(hWnd, &ps);

		// ツールチップの描画
		GetClientRect(hWnd, (LPRECT)&rect);
		tooltip_draw_text(ti, hdc, &rect);

		EndPaint(hWnd, &ps);
		break;

	case WM_MOUSEMOVE:
	case WM_LBUTTONDOWN:
	case WM_MBUTTONDOWN:
	case WM_RBUTTONDOWN:
	case WM_SETCURSOR:
	case WM_TOOLTIP_HIDE:
		// ツールチップ非表示
		KillTimer(hWnd, ID_SHOW_TIMER);
		KillTimer(hWnd, ID_MOUSE_TIMER);
		ShowWindow(hWnd, SW_HIDE);

		if ((ti = (TOOLTIP_INFO *)GetWindowLong(hWnd, GWL_USERDATA)) != NULL && ti->buf != NULL) {
			mem_free(&ti->buf);
		}
		break;

	case WM_TOOLTIP_SHOW:
		// ツールチップ表示
		KillTimer(hWnd, ID_SHOW_TIMER);
		KillTimer(hWnd, ID_MOUSE_TIMER);
		ShowWindow(hWnd, SW_HIDE);
		if (lParam == 0 ||
			((TOOLTIP_INFO *)lParam)->buf == NULL || *((TOOLTIP_INFO *)lParam)->buf == TEXT('\0')) {
			break;
		}
		if ((ti = (TOOLTIP_INFO *)GetWindowLong(hWnd, GWL_USERDATA)) == NULL) {
			break;
		}

		// 座標設定
		ti->top = ((TOOLTIP_INFO *)lParam)->top;
		ti->pt.x = ((TOOLTIP_INFO *)lParam)->pt.x;
		ti->pt.y = ((TOOLTIP_INFO *)lParam)->pt.y;

		// ウィンドウ取得
		if (ti->pt.x == 0 && ti->pt.y == 0) {
			GetCursorPos(&pt);
			ti->hWnd = WindowFromPoint(pt);
		} else {
			ti->hWnd = NULL;
		}

		// テキスト設定
		if (ti->buf != NULL) {
			mem_free(&ti->buf);
		}
		ti->buf = alloc_copy(((TOOLTIP_INFO *)lParam)->buf);

		// ツールチップ表示
		SetTimer(hWnd, ID_SHOW_TIMER, wParam, NULL);
		break;

	case WM_TIMER:
		switch (wParam) {
		case ID_SHOW_TIMER:
			KillTimer(hWnd, wParam);
			if ((ti = (TOOLTIP_INFO *)GetWindowLong(hWnd, GWL_USERDATA)) == NULL || ti->buf == NULL) {
				SendMessage(hWnd, WM_TOOLTIP_HIDE, 0, 0);
				break;
			}

			// 表示位置取得 (マウス位置)
			if (ti->pt.x == 0 && ti->pt.y == 0) {
				GetCursorPos(&ti->pt);
				ti->top = tooltip_get_cursor_height(GetCursor()) + 1;
				if (ti->hWnd != WindowFromPoint(ti->pt)) {
					SendMessage(hWnd, WM_TOOLTIP_HIDE, 0, 0);
					break;
				}
			}

			// サイズ取得
			hdc = GetDC(hWnd);
			hRetFont = SelectObject(hdc, (ti->hfont != NULL) ? ti->hfont : GetStockObject(DEFAULT_GUI_FONT));
			SetRectEmpty(&rect);

			ZeroMemory(&dtp, sizeof(DRAWTEXTPARAMS));
			dtp.cbSize = sizeof(DRAWTEXTPARAMS);
			dtp.iTabLength = option.tooltip_tab_length;
			DrawTextEx(hdc, ti->buf, lstrlen(ti->buf), &rect,
				DT_CALCRECT | DT_EDITCONTROL | DT_NOCLIP | DT_EXPANDTABS | DT_TABSTOP | DT_NOPREFIX, &dtp);

			SelectObject(hdc, hRetFont);
			ReleaseDC(hWnd, hdc);

			// ウィンドウサイズ設定
			SetRect(&rect,
				ti->pt.x,
				ti->pt.y + ti->top,
				rect.right + (option.tooltip_margin_x * 2) + 2,
				rect.bottom + (option.tooltip_margin_y * 2) + 2);

			// 横位置の補正
			if (rect.left + rect.right > GetSystemMetrics(SM_CXSCREEN)) {
				rect.left = GetSystemMetrics(SM_CXSCREEN) - rect.right;
			}
			if (rect.left < 0) {
				rect.left = 0;
			}

			// 縦位置の補正
			if (rect.top + rect.bottom > GetSystemMetrics(SM_CYSCREEN)) {
				rect.top = ti->pt.y - rect.bottom;
			}
			if (rect.top < 0) {
				rect.top = GetSystemMetrics(SM_CYSCREEN) - rect.bottom;
			}
			if (rect.top < 0) {
				rect.top = 0;
			}

			// ウィンドウの位置とサイズを設定
			SetWindowPos(hWnd, HWND_TOPMOST,
				rect.left, rect.top, rect.right, rect.bottom,
				SWP_NOACTIVATE);

#ifdef TOOLTIP_ANIMATE
			{
				HANDLE user32_lib;
				FARPROC AnimateWindow;
				BOOL effect_flag;

				// ウィンドウ表示
				SystemParametersInfo(SPI_GETTOOLTIPANIMATION, 0, &effect_flag, 0);
				if (effect_flag == TRUE) {
					SystemParametersInfo(SPI_GETTOOLTIPFADE, 0, &effect_flag, 0);
					user32_lib = LoadLibrary(TEXT("user32.dll"));
					if (user32_lib != NULL) {
						AnimateWindow = GetProcAddress(user32_lib, "AnimateWindow");
						if (AnimateWindow != NULL) {
							// アニメーション表示
							AnimateWindow(hWnd, 200, (effect_flag == TRUE) ? AW_BLEND : (AW_SLIDE | AW_VER_POSITIVE));
						}
						FreeLibrary(user32_lib);
					}
				}
			}
#endif
			ShowWindow(hWnd, SW_SHOWNOACTIVATE);
			SetTimer(hWnd, ID_MOUSE_TIMER, MOUSE_INTERVAL, NULL);
			break;

		case ID_MOUSE_TIMER:
			if ((ti = (TOOLTIP_INFO *)GetWindowLong(hWnd, GWL_USERDATA)) == NULL ||
				ti->hWnd == NULL || IsWindowVisible(hWnd) == FALSE) {
				KillTimer(hWnd, wParam);
				break;
			}
			// マウスの下のウィンドウをチェック
			GetCursorPos(&pt);
			if (ti->pt.x != pt.x && ti->pt.y != pt.y && ti->hWnd != WindowFromPoint(pt)) {
				SendMessage(hWnd, WM_TOOLTIP_HIDE, 0, 0);
				break;
			}
			break;
		}
		break;

	default:
		return DefWindowProc(hWnd, msg, wParam, lParam);
	}
	return 0;
}
Beispiel #10
0
void g_put_chars(struct g_part *p, unsigned char *s, int l)
{
	struct g_object_text *t = NULL;
	struct link *link;
	if (putchars_link_ptr) {
		link = NULL;
		goto check_link;
	}
	while (par_format.align != AL_NO && p->cx == -1 && l && *s == ' ') s++, l--;
	if (!l) return;
	g_nobreak = 0;
	if (p->cx < par_format.leftmargin * G_HTML_MARGIN) p->cx = par_format.leftmargin * G_HTML_MARGIN;
	if (html_format_changed) {
		if (memcmp(&ta_cache, &format, sizeof(struct text_attrib_beginning)) || xstrcmp(cached_font_face, format.fontface) || cached_font_face == to_je_ale_prasarna ||
	xstrcmp(format.link, last_link) || xstrcmp(format.target, last_target) ||
	    xstrcmp(format.image, last_image) || format.form != last_form
	    || ((format.js_event || last_js_event) && compare_js_event_spec(format.js_event, last_js_event))	) {
			/*if (!html_format_changed) internal("html_format_changed not set");*/
			flush_pending_text_to_line(p);
			if (xstrcmp(cached_font_face, format.fontface) || cached_font_face == to_je_ale_prasarna) {
				if (cached_font_face && cached_font_face != to_je_ale_prasarna) mem_free(cached_font_face);
				cached_font_face = stracpy(format.fontface);
			}
			memcpy(&ta_cache, &format, sizeof(struct text_attrib_beginning));
			if (p->current_style) g_free_style(p->current_style);
			p->current_style = get_style_by_ta(&format);
		}
		html_format_changed = 0;
	}
	/*if (p->cx <= par_format.leftmargin * G_HTML_MARGIN && *s == ' ' && par_format.align != AL_NO) s++, l--;*/
	if (!p->text) {
		link = NULL;
		t = mem_calloc(sizeof(struct g_object_text) + ALLOC_GR);
		t->mouse_event = g_text_mouse;
		t->draw = g_text_draw;
		t->destruct = g_text_destruct;
		t->get_list = NULL;
		/*t->style = get_style_by_ta(format);*/
		t->style = g_clone_style(p->current_style);
		t->bg = NULL; /* FIXME!!! */
		t->yw = t->style->height;
		/*t->xw = 0;
		t->y = 0;*/
		if (format.baseline) {
			if (format.baseline < 0) t->y = -(t->style->height / 3);
			if (format.baseline > 0) t->y = get_real_font_size(format.baseline) - (t->style->height / 2);
		}
		check_link:
		if (last_link || last_image || last_form || format.link || format.image || format.form 
		|| format.js_event || last_js_event
		) goto process_link;
		back_link:
		if (putchars_link_ptr) {
			*putchars_link_ptr = link;
			return;
		}

		if (!link) t->link_num = -1;
		else {
			t->link_num = link - p->data->links;
			t->link_order = link->obj_order++;
		}

		t->text[0] = 0;
		p->pending_text_len = 0;
		p->text = t;
	}
	if (p->pending_text_len == -1) {
		p->pending_text_len = strlen(p->text->text);
		goto a1;
	}
	if ((p->pending_text_len & ~(ALLOC_GR - 1)) != ((p->pending_text_len + l) & ~(ALLOC_GR - 1))) a1:{
		struct g_object_text *t;
		if ((unsigned)l > MAXINT) overalloc();
		if ((unsigned)p->pending_text_len + (unsigned)l > MAXINT - ALLOC_GR) overalloc();
		t = mem_realloc(p->text, sizeof(struct g_object_text) + ((p->pending_text_len + l + ALLOC_GR) & ~(ALLOC_GR - 1)));
		if (p->w.last_wrap >= p->text->text && p->w.last_wrap < p->text->text + p->pending_text_len) p->w.last_wrap += (unsigned char *)t - (unsigned char *)p->text;
		if (p->w.last_wrap_obj == p->text) p->w.last_wrap_obj = t;
		p->text = t;
	}
	memcpy(p->text->text + p->pending_text_len, s, l), p->text->text[p->pending_text_len += l] = 0;
	p->text->xw += g_text_width(p->text->style, p->text->text + p->pending_text_len - l); /* !!! FIXME: move to g_wrap_text */
	if (par_format.align != AL_NO) {
		p->w.text = p->text->text + p->pending_text_len - l;
		p->w.style = p->text->style;
		p->w.obj = p->text;
		p->w.width = rm(par_format) - par_format.leftmargin * G_HTML_MARGIN;
		if (p->w.width < 0) p->w.width = 0;
		if (!g_wrap_text(&p->w)) {
			split_line_object(p, p->w.last_wrap_obj, p->w.last_wrap);
		}
	}
	return;

	/* !!! WARNING: THE FOLLOWING CODE IS SHADOWED IN HTML_R.C */

	process_link:
	if ((last_link /*|| last_target*/ || last_image || last_form) &&
	    !putchars_link_ptr &&
	    !xstrcmp(format.link, last_link) && !xstrcmp(format.target, last_target) &&
	    !xstrcmp(format.image, last_image) && format.form == last_form
	    && ((!format.js_event && !last_js_event) || !compare_js_event_spec(format.js_event, last_js_event))) {
		if (!p->data) goto back_link;
		if (!p->data->nlinks) {
			internal("no link");
			goto back_link;
		}
		link = &p->data->links[p->data->nlinks - 1];
		goto back_link;
	} else {
		if (last_link) mem_free(last_link);
		if (last_target) mem_free(last_target);
		if (last_image) mem_free(last_image);
		free_js_event_spec(last_js_event);
		last_link = last_target = last_image = NULL;
		last_form = NULL;
		last_js_event = NULL;
		if (!(format.link || format.image || format.form || format.js_event)) goto back_link;
		/*if (d_opt->num_links) {
			unsigned char s[64];
			unsigned char *fl = format.link, *ft = format.target, *fi = format.image;
			struct form_control *ff = format.form;
			struct js_event_spec *js = format.js_event;
			format.link = format.target = format.image = NULL;
			format.form = NULL;
			format.js_event = NULL;
			s[0] = '[';
			snzprint(s + 1, 62, p->link_num);
			strcat(s, "]");
			g_put_chars(p, s, strlen(s));
			if (ff && ff->type == FC_TEXTAREA) g_line_break(p);
			if (p->cx < par_format.leftmargin * G_HTML_MARGIN) p->cx = par_format.leftmargin * G_HTML_MARGIN;
			format.link = fl, format.target = ft, format.image = fi;
			format.form = ff;
			format.js_event = js;
		}*/
		p->link_num++;
		last_link = stracpy(format.link);
		last_target = stracpy(format.target);
		last_image = stracpy(format.image);
		last_form = format.form;
		copy_js_event_spec(&last_js_event, format.js_event);
		if (!p->data) goto back_link;
		if (!(link = new_link(p->data))) goto back_link;
		link->num = p->link_num - 1;
		link->pos = DUMMY;
		copy_js_event_spec(&link->js_event, format.js_event);
		if (!last_form) {
			link->type = L_LINK;
			link->where = stracpy(last_link);
			link->target = stracpy(last_target);
		} else {
			link->type = last_form->type == FC_TEXT || last_form->type == FC_PASSWORD || last_form->type == FC_FILE ? L_FIELD : last_form->type == FC_TEXTAREA ? L_AREA : last_form->type == FC_CHECKBOX || last_form->type == FC_RADIO ? L_CHECKBOX : last_form->type == FC_SELECT ? L_SELECT : L_BUTTON;
			link->form = last_form;
			link->target = stracpy(last_form->target);
		}
		link->where_img = stracpy(last_image);
		link->sel_color = 0;
		link->n = 0;
	}
	goto back_link;
}
Beispiel #11
0
/** Construct the struct itrm of this process, make ::ditrm point to it,
 * set up select() handlers, and send the initial interlink packet.
 *
 * The first five parameters are file descriptors that this function
 * saves in submembers of struct itrm, and for which this function may
 * set select() handlers.  Please see the definitions of struct
 * itrm_in and struct itrm_out for further explanations.
 *
 * @param std_in	itrm_in.std: read tty device (or pipe)
 * @param std_out	itrm_out.std: write tty device (or pipe)
 * @param sock_in	itrm_in.sock
 *			- If master: == @a std_out (masterhood flag)
 *			- If slave: read socket from master
 * @param sock_out	itrm_out.sock
 *			- If master: write pipe to same process
 *			- If slave: write socket to master
 * @param ctl_in	itrm_in.ctl: control tty device
 *
 * The remaining three parameters control the initial interlink packet.
 *
 * @param init_string	A string to be passed to the master process.  Need
 *			not be null-terminated.  If @a remote == 0, this is
 *			a URI.  Otherwise, this is a remote command.
 * @param init_len	The length of init_string, in bytes.
 * @param remote	= 0 if asking the master to start a new session
 *			and display it via this process.  Otherwise,
 *			enum ::remote_session_flags.  */
void
handle_trm(int std_in, int std_out, int sock_in, int sock_out, int ctl_in,
	   void *init_string, int init_len, int remote)
{
	struct itrm *itrm;
	struct terminal_info info;
	struct interlink_event_size *size = &info.event.info.size;
	unsigned char *ts;

	memset(&info, 0, sizeof(info));

	get_terminal_size(ctl_in, &size->width, &size->height);
	info.event.ev = EVENT_INIT;
	info.system_env = get_system_env();
	info.length = init_len;

	if (remote) {
		info.session_info = remote;
		info.magic = INTERLINK_REMOTE_MAGIC;
	} else {
		info.session_info = get_cmd_opt_int("base-session");
		info.magic = INTERLINK_NORMAL_MAGIC;
	}

	itrm = mem_calloc(1, sizeof(*itrm));
	if (!itrm) return;

	itrm->in.queue.data = mem_calloc(1, ITRM_IN_QUEUE_SIZE);
	if (!itrm->in.queue.data) {
		mem_free(itrm);
		return;
	}

	ditrm = itrm;
	itrm->in.std = std_in;
	itrm->out.std = std_out;
	itrm->in.sock = sock_in;
	itrm->out.sock = sock_out;
	itrm->in.ctl = ctl_in;
	itrm->timer = TIMER_ID_UNDEF;
	itrm->remote = !!remote;

	/* If the master does not tell which charset it's using in
	 * this terminal, assume it's some ISO 8859.  Because that's
	 * what older versions of ELinks did.  */
	itrm->title_codepage = get_cp_index("ISO-8859-1");

	/* FIXME: Combination altscreen + xwin does not work as it should,
	 * mouse clicks are reportedly partially ignored. */
	if (info.system_env & (ENV_SCREEN | ENV_XWIN))
		itrm->altscreen = 1;

	if (!remote) {
		if (ctl_in >= 0) setraw(itrm, 1);
		send_init_sequence(std_out, itrm->altscreen);
		handle_terminal_resize(ctl_in, resize_terminal);
#ifdef CONFIG_MOUSE
		enable_mouse();
#endif
		handle_itrm_stdin(itrm);
	} else {
		/* elinks -remote may not have a valid stdin if not run from a tty (bug 938) */
		if (std_in >= 0) handle_itrm_stdin(itrm);
	}

	if (sock_in != std_out)
		set_handlers(sock_in, (select_handler_T) in_sock,
			     NULL, (select_handler_T) free_itrm, itrm);

	get_terminal_name(info.name);

	ts = get_cwd();
	if (ts) {
		memcpy(info.cwd, ts, int_min(strlen(ts), MAX_CWD_LEN));
		mem_free(ts);
	}

	itrm_queue_event(itrm, (char *) &info, TERMINAL_INFO_SIZE);
	itrm_queue_event(itrm, (char *) init_string, init_len);
}
Beispiel #12
0
void *g_html_special(struct g_part *p, int c, ...)
{
	va_list l;
	unsigned char *t;
	struct form_control *fc;
	struct frameset_param *fsp;
	struct frame_param *fp;
	struct image_description *im;
	struct g_object_tag *tag;
	struct refresh_param *rp;
	struct hr_param *hr;
	va_start(l, c);
	switch (c) {
		case SP_TAG:
			t = va_arg(l, unsigned char *);
			va_end(l);
			/*html_tag(p->data, t, X(p->cx), Y(p->cy));*/
			tag = mem_calloc(sizeof(struct g_object_tag) + strlen(t) + 1);
			tag->mouse_event = g_dummy_mouse;
			tag->draw = g_dummy_draw;
			tag->destruct = g_tag_destruct;
			strcpy(tag->name, t);
			flush_pending_text_to_line(p);
			add_object_to_line(p, &p->line, (struct g_object *)tag);
			break;
		case SP_CONTROL:
			fc = va_arg(l, struct form_control *);
			va_end(l);
			g_html_form_control(p, fc);
			break;
		case SP_TABLE:
			va_end(l);
			return convert_table;
		case SP_USED:
			va_end(l);
			return (void *)(my_intptr_t)!!p->data;
		case SP_FRAMESET:
			fsp = va_arg(l, struct frameset_param *);
			va_end(l);
			return create_frameset(p->data, fsp);
		case SP_FRAME:
			fp = va_arg(l, struct frame_param *);
			va_end(l);
			create_frame(fp);
			break;
		case SP_SCRIPT:
			t = va_arg(l, unsigned char *);
			va_end(l);
			if (p->data) process_script(p->data, t);
			break;
		case SP_IMAGE:
			im = va_arg(l, struct image_description *);
			va_end(l);
			do_image(p, im);
			break;
		case SP_NOWRAP:
			va_end(l);
			break;
		case SP_REFRESH:
			rp = va_arg(l, struct refresh_param *);
			va_end(l);
			html_process_refresh(p->data, rp->url, rp->time);
			break;
		case SP_SET_BASE:
			t = va_arg(l, unsigned char *);
			va_end(l);
			if (p->data) set_base(p->data, t);
			break;
		case SP_HR:
			hr = va_arg(l, struct hr_param *);
			va_end(l);
			g_hr(p, hr);
			break;
		default:
			va_end(l);
			internal("html_special: unknown code %d", c);
	}
	return NULL;
}
Beispiel #13
0
void split_line_object(struct g_part *p, struct g_object_text *text, unsigned char *ptr)
{
	struct g_object_text *t2;
	struct g_object_line *l2;
	int n;
	int esp;
	if (!ptr) {
		if (p->line && p->line->n_entries && (struct g_object *)text == p->line->entries[p->line->n_entries - 1]) {
			flush_pending_line_to_obj(p, 0);
			goto wwww;
		}
		t2 = NULL;
		goto nt2;
	}
	t2 = mem_calloc(sizeof(struct g_object_text) + strlen(ptr) + 1);
	t2->mouse_event = g_text_mouse;
	t2->draw = g_text_draw;
	t2->destruct = g_text_destruct;
	t2->get_list = NULL;
	esp = 1;
	if (*ptr == ' ') {
		strcpy(t2->text, ptr + 1);
		*ptr = 0;
		/*debug("split: (%s)(%s)", text->text, ptr + 1);*/
	} else {
		strcpy(t2->text, ptr);
		ptr[0] = '-';
		ptr[1] = 0;
		esp = 0;
	}
	t2->y = text->y;
	t2->style = g_clone_style(text->style);
	t2->bg = text->bg;
	t2->link_num = text->link_num;
	t2->link_order = text->link_order;
	text->xw = g_text_width(text->style, text->text);
	nt2:
	if (p->line) for (n = 0; n < p->line->n_entries; n++) if (p->line->entries[n] == (struct g_object *)text) goto found;
	if (text != p->text) {
		internal("split_line_object: bad wrap");
		t2->destruct(t2);
		mem_free(t2);
		return;
	}
	if (0) {
		int nn;
		found:
		n += !ptr;
		l2 = mem_calloc(sizeof(struct g_object_line) + (p->line->n_entries - n) * sizeof(struct g_object_text *));
		l2->mouse_event = g_line_mouse;
		l2->draw = g_line_draw;
		l2->destruct = g_line_destruct;
		l2->get_list = g_line_get_list;
		l2->bg = p->root->bg;
		l2->n_entries = p->line->n_entries - n;
		l2->entries[0] = (struct g_object *)t2;
		memcpy(&l2->entries[!!ptr], p->line->entries + n + !!ptr, (l2->n_entries - !!ptr) * sizeof(struct g_object_text *));
		p->line->n_entries = n + !!ptr;
		flush_pending_line_to_obj(p, 0);
		p->line = l2;
		if (ptr) {
			t2->xw = g_text_width(t2->style, t2->text);
			t2->yw = text->yw;
			p->w.pos = 0;
		}
		for (nn = 0; nn < l2->n_entries; nn++) {
			p->w.pos += l2->entries[nn]->xw;	/* !!! FIXME: nastav last_wrap */
			/*debug("a1: %d (%s)", l2->entries[nn]->xw, tt->text);*/
		}
		wwww:
		if (p->text) p->w.pos += g_text_width(p->text->style, p->text->text);
		/*debug("%d", p->w.pos);*/
	} else {
		flush_pending_text_to_line(p);
		flush_pending_line_to_obj(p, 0);
		p->line = NULL;
		t2->xw = g_text_width(t2->style, t2->text);
		t2->yw = text->yw;
		p->text = t2;
		p->pending_text_len = -1;
		p->w.pos = t2->xw;
		p->cx += g_char_width(t2->style, ' ');
	}
	p->w.last_wrap = NULL;
	p->w.last_wrap_obj = NULL;
	t2 = p->text;
	if (t2 && *t2->text && t2->text[strlen(t2->text) - 1] == ' ') {
		p->w.last_wrap = &t2->text[strlen(t2->text) - 1];
		p->w.last_wrap_obj = t2;
	}
}
Beispiel #14
0
int init_record_cache( Irregular_Context itx, int maxbytes, float *ratio )
{
   int i, j;
   int numfloatvars, numcharvars, numberofchars; 
   int recordsize;
   int soundingsize;
   int totalnumrecs;

   /* dyamically allocate memory for RecordTable since */
   /* MAXTIMES*MAXRECS is way too large                */
   for (i = 0; i < itx->NumTimes; i++){
/* 01Feb06  Phil McDonald */
      itx->RecordTable[i] = (struct irreg_rec *) mem_calloc
                            (itx->NumRecs[i], sizeof (struct irreg_rec));
/* end PM */
   }

   ALLOC_LOCK(itx->Mutex);

   /*********************************/
   /* figure out size of one record */
   /*********************************/
   numfloatvars = 0;
   numcharvars = 0;
   numberofchars = 0;
   soundingsize = 0;
   for (i = 0; i < itx->NumVars; i++){
      if (itx->Variable[i]->VarType == NUMERICAL_VAR_1D ){
         numfloatvars++;
      }
      else if (itx->Variable[i]->VarType == NUMERICAL_VAR_2D ){
         soundingsize += itx->Levels;
      }
      else if (itx->Variable[i]->VarType == CHARACTER_VAR){
         numberofchars += itx->Variable[i]->CharVarLength;
         numcharvars++;
      }
      else{
         printf("Error in init_record_cache\n");
         return -1;
      }
   }
   if (itx->Type == SOUNDING){
      recordsize = numfloatvars * sizeof(double) +
                   soundingsize * sizeof(double) +
                   itx->Levels  * sizeof(float)  +
                   numberofchars  * sizeof(char);
   }
   else{
      recordsize = numfloatvars * sizeof(double) +
                   soundingsize * sizeof(double) +
                   numberofchars  * sizeof(char);
   }
   itx->CharArrayLength = numberofchars;


   /****************************************************/   
   /* figure out how many records can be put in memory */
   /****************************************************/
   itx->MaxCachedRecs = (int) maxbytes / recordsize;


   /**********************/
   /* get total num recs */
   /**********************/
   totalnumrecs = 0;
   for (i = 0; i < itx->NumTimes; i++){
      totalnumrecs += itx->NumRecs[i];
   }

   if (itx->MaxCachedRecs >= totalnumrecs){
      /* all records can be cached */
      itx->MaxCachedRecs = totalnumrecs;
      printf("Reading all records\n");
      *ratio = 1.0;
   }
   else{
      *ratio = ((float) itx->MaxCachedRecs)
             / ((float) totalnumrecs);
   }

   itx->NumCachedRecs = 0;

   printf("Cache size: %d records\n", itx->MaxCachedRecs);

   /****************************/
   /* allocate irregular cache */
   /****************************/
   itx->RecordCache = (struct cache_irreg_rec *) i_allocate( itx, itx->MaxCachedRecs
                                                 * sizeof(struct cache_irreg_rec) ); 

   /************/   
   /* check it */
   /************/
   if (!itx->RecordCache){
      printf("Error1: out of memory.  Couldn't allocate cache space.\n");
      return 0;
   }

   
   /******************************************************************/
   /* allocate memory for RecGeoPosition, this simply contains the   */
   /* lat, lon, alt for all the records.  This was removed from the  */
   /* cache_irreg_rec becuase if all the records can not fit into    */
   /* the cache, they will have to be loaded at some point in time   */
   /* into the cache in order to see whether or not to be used in a  */
   /* graphic, by loading all the lat, lon, and alts and keeping them*/
   /* this will eliminate this problem and the record cache will be  */
   /* more effective                                                 */
   /******************************************************************/

   for (i = 0; i < itx->NumTimes; i++){
      itx->RecGeoPosition[i] = (struct rec_geo_position *) i_allocate( itx,
                                                   itx->NumRecs[i] *
                                                   sizeof(struct rec_geo_position) );
      if (!itx->RecGeoPosition[i]){
         printf("Not enough memory to allocate for RecGeoPosition\n");
         return 0;
      }
   }


   itx->CacheClock = 1;

   for (i=0;i<itx->MaxCachedRecs;i++){
      /************************/
      /* alloc DataType array */
      /************************/
      itx->RecordCache[i].DataType =
                            i_allocate( itx, itx->NumVars*sizeof(int));
      /************/            
      /* check it */
      /************/
      if (!itx->RecordCache[i].DataType){
         printf("Error3: out of memory.  Couldn't allocate cache space.\n");
         return 0;
      }

      /***************/
      /* alloc Value */
      /***************/
      itx->RecordCache[i].Value =
                            i_allocate( itx, itx->NumVars*sizeof(double));
      /************/                        
      /* check it */
      /************/            
      if (!itx->RecordCache[i].Value){
         printf("Error4: out of memory.  Couldn't allocate cache space.\n");
         return 0;
      }

      /*************************/
      /* alloc Sounding Values */
      /*************************/
      if (soundingsize){
         itx->RecordCache[i].SoundingValue =
                           i_allocate( itx, soundingsize * sizeof(double));
         /************/
         /* check it */
         /************/
         if (!itx->RecordCache[i].SoundingValue){
            printf("Error5: out of memory.  Couldn't allocate cache space.\n");
            return 0;
         }
         itx->RecordCache[i].SoundingLevel = 
                           i_allocate( itx, itx->Levels * sizeof(float));
         if(!itx->RecordCache[i].SoundingLevel){
            printf("Error6: out of memory.  Couldn't allocate cache space.\n");
            return 0;
         }
      }

      /***********************/            
      /* Alloc char var data */
      /***********************/
      itx->RecordCache[i].CharData =
                            i_allocate( itx, numberofchars*sizeof(char ));

      /************/                                    
      /* check it */            
      /************/                        
      if (!itx->RecordCache[i].CharData){
         printf("Error7: out of memory.  Couldn't allocate cache space.\n");
         return 0;
      }


      itx->RecordCache[i].Locked = 0;
      itx->RecordCache[i].Timestep = 0;
   }


   for (i=0; i<itx->NumTimes; i++){
      for (j = 0; j < itx->NumRecs[i]; j++){
         itx->RecordTable[i][j].CachePos = -1;
         itx->RecordTable[i][j].DataType = NULL;
         itx->RecordTable[i][j].Value = NULL;
         itx->RecordTable[i][j].SoundingValue = NULL;
         itx->RecordTable[i][j].SoundingLevel = NULL;
         itx->RecordTable[i][j].CharData = NULL;
      }
   }
   return 1;
}
Beispiel #15
0
Datei: util.c Projekt: Phoul/shim
// XXX should this do more to sanitize the url?
struct url *
url_tokenize(const char *str)
{
	struct url *url;
	size_t ntokens;
	char *p;
	struct token_list tokens;
	struct token *scheme, *slash, *hostport, *path;
	size_t len;
	int port = -1;
	char *pathstr;

	url = NULL;	
	TAILQ_INIT(&tokens);

	ntokens = tokenize(str, "/", 3, &tokens);

	/* just a path? */
	if (ntokens >= 1 && TAILQ_FIRST(&tokens)->token[0] == '\0') {
		url = mem_calloc(1, sizeof(*url));
		url->path = mem_strdup(str);
		goto out;
	}

	if (ntokens < 3)
		goto out;

	scheme = TAILQ_FIRST(&tokens);
	len = strlen(scheme->token);
	if (len	< 2 || scheme->token[len - 1] != ':')
		goto out;
	scheme->token[len - 1] = '\0';

	slash = TAILQ_NEXT(scheme, next);	
	if (slash->token[0] != '\0')
		goto out;

	hostport = TAILQ_NEXT(slash, next);
	if (hostport->token[0] == '\0')
		goto out;
	// XXX this could break IPv6 addresses
	p = strrchr(hostport->token, ':');
	if (p == hostport->token)
		goto out;
	if (p && p[1] != '\0') {
		*p++ = '\0';
		port = get_port(p);
		if (port < 0)
			goto out;
	}

	if (ntokens > 3) {
		// XXX maybe urlencode?
		assert(ntokens == 4);
		path = TAILQ_NEXT(hostport, next);
		len = strlen(path->token);
		pathstr = mem_calloc(1, 2 + len);
		pathstr[0] = '/';
		memcpy(pathstr + 1, path->token, len);
	} else
		pathstr = mem_strdup("/");
	

	url = mem_calloc(1, sizeof(*url));
	url->scheme = scheme->token;
	url->host = hostport->token;
	url->port = port;
	url->path = pathstr;

	scheme->token = NULL;
	hostport->token = NULL;

out:
	token_list_clear(&tokens);

	return url;
}	
err_t tcp_client_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
{
	struct pbuf *q;
	struct tcp_client_app_arg *appcmd = (struct tcp_client_app_arg *)arg;
	uint16_t i = 0;
	uint8_t ip[4];
	char* str;
	struct tm mytime;

	const char* cmd1 = "hello";
	const char* cmd2 = "echo name";
	const char* cmd3 = "echo log";
	const char* cmd4 = "echo IP";
	const char* cmd5 = "bye";
	const char* cmd6 = "time calibration"; //命令格式:time calibration:YY MM DD HH MM SS

	//printf("tcp client recv\n");
	print_client_pcb_state(pcb);
		
	/* We perform here any necessary processing on the pbuf */
	if (p != NULL) 
	{        
		/* We call this function to tell the LwIp that we have processed the data */
		/* This lets the stack advertise a larger window, so more data can be received*/
		tcp_recved(pcb, p->tot_len);
		
		/* Check the name if NULL, no data passed, return withh illegal argument error */
		if(appcmd == NULL) 
		{
		  pbuf_free(p);
		  return ERR_ARG;
		}
		/*
		for(q=p; q != NULL; q = q->next) 
		{
			
			c = q->payload;
			for(i=0; i<q->len && !done; i++) 
			{
				done = ((c[i] == '\r') || (c[i] == '\n'));
				if(name->length < MAX_NAME_SIZE) 
				{
				  name->bytes[name->length++] = c[i];
				}
			}
			
		}
		*/
		appcmd->dataptr = (char*)mem_calloc(sizeof(uint8_t), p->tot_len);
		if(appcmd->dataptr == NULL){
			printf("Memory error\n");
			return ERR_MEM;
		}
		appcmd->textlen = p->tot_len;
		for(q=p; q!=NULL; q=q->next){
			memcpy((uint8_t*)&appcmd->dataptr[i], q->payload, q->len);  //同一个数据包会存在一个pbuf链表中
			i = i + q->len;
		}
		//应用层代码
		switch(appcmd->app_state){
			case CLIENT_CONNECTED:
			case CLIENT_WAITING_FOR_CMD: {
				if(memcmp(appcmd->dataptr, cmd1, strlen(cmd1)) == 0){
					str = "hello\n";
					//tcp_write(pcb, (uint8_t*)str, strlen(str), 1);
				}
				else if(memcmp(appcmd->dataptr, cmd2, strlen(cmd2)) == 0){
					str = "lwip\n";
				}
				else if(memcmp(appcmd->dataptr, cmd3, strlen(cmd3)) == 0){
					str = "log is ...\n";
				}
				else if(memcmp(appcmd->dataptr, cmd4, strlen(cmd4)) == 0){
					ip[0] = pcb->remote_ip.addr>>24;
					ip[1] = pcb->remote_ip.addr>>16;
					ip[2] = pcb->remote_ip.addr>>8;
					ip[3] = pcb->remote_ip.addr;
					str = mem_calloc(sizeof(uint8_t), 30);
					sprintf((char*)str, "ipaddr:%d,%d,%d,%d\n", ip[3], ip[2], ip[1], ip[0]);
					tcp_write(pcb, (uint8_t *)str, strlen(str), 1);
					mem_free(str);
					break;
				}
				else if(memcmp(appcmd->dataptr, cmd5, strlen(cmd5)) == 0){
					appcmd->app_state = CLIENT_CLOSE;
					//goto get_close;
					break;
				}
				else if(memcmp(appcmd->dataptr, cmd6, strlen(cmd6)) == 0){
					sscanf(appcmd->dataptr, "%*[^:]:%d%d%d%d%d%d", &mytime.tm_year, &mytime.tm_mon, &mytime.tm_mday, &mytime.tm_hour, &mytime.tm_min, &mytime.tm_sec);
					if(mytime.tm_year<100&&mytime.tm_mon-1<12&&mytime.tm_mday<32&&mytime.tm_hour<24&&mytime.tm_min<60&&mytime.tm_sec<60&&mytime.tm_mon>0){
						str = "time calibration success\n";
						DS1302_SetSec(mytime.tm_sec, DISABLE);
						DS1302_SetMin(mytime.tm_min);
						DS1302_SetHour(mytime.tm_hour, DISABLE);
						DS1302_SetDate(mytime.tm_mday);
						DS1302_SetMon(mytime.tm_mon-1);
						DS1302_SetYear(mytime.tm_year);
						
						mytime.tm_year += 2000; 
						mytime.tm_mon --;
						RTC_WaitForLastTask();
						RTC_ITConfig(RTC_IT_SEC, DISABLE);  
						Time_SetCalendarTime(mytime);  
						RTC_ITConfig(RTC_IT_SEC, ENABLE);

						time_update_status = DS1302_SYN_SUL;
						  
						appcmd->app_state = CLIENT_CLOSE;
					}
					else{
						str = "time calibratioin failed\n";
						time_update_status = DS1302_SYN_FAIL;
					}
					tcp_write(pcb, (uint8_t *)str, strlen(str), 1);
					break;
				}
				else{
					str = "unknown cmd\n";
					//tcp_write(pcb, (uint8_t*)str, strlen(str), 1);
				}
				tcp_write(pcb, (uint8_t *)str, strlen(str), 1);
				break;
			}
Beispiel #17
0
/**
 * This function reads all the data from a connection into a buffer which it returns.
 * It will return an empty buffer if something doesn't go as planned
 *
 * @param s32 connection The connection identifier to suck the response out of
 * @return block A 'block' struct (see http.h) in which the buffer is located
 */
struct block read_message(s32 connection, const char *fname)
{
	//Create a block of memory to put in the response
	struct block buffer;
	FILE *f = NULL;
	bool found = false;
	unsigned char *buffer_found;

	buffer_found = mem_calloc(HTTP_BUFFER_SIZE);
	buffer.data = mem_calloc(HTTP_BUFFER_SIZE);
	buffer.filesize = 0;
	buffer.size = HTTP_BUFFER_SIZE;
	int progress_count = 0;

	if(buffer.data == NULL) {
		return emptyblock;
	}
	
	if (fname != NULL)
	{
		if ((f = fopen(fname,"wb")) == NULL) return emptyblock;
	}

	//The offset variable always points to the first byte of memory that is free in the buffer
	u32 offset = 0;
	
	while(1)
	{
		//Fill the buffer with a new batch of bytes from the connection,
		//starting from where we left of in the buffer till the end of the buffer
		s32 bytes_read;
		
		if (!found)
			bytes_read = net_read(connection, buffer.data + offset, buffer.size - offset);
		else
			bytes_read = net_read(connection, buffer_found, HTTP_BUFFER_SIZE);
		
		//Anything below 0 is an error in the connection
		if(bytes_read < 0)
		{
			printf(gt("Connection error from net_read()  Errorcode: %i"), bytes_read);
			printf("\n");
			return emptyblock;
		}
		
		//No more bytes were read into the buffer,
		//we assume this means the HTTP response is done
		if(bytes_read == 0)
		{
			break;
		}
		
		if (fname != NULL) {
			if (!found) {
				int i;
				for (i=0; i < bytes_read; i++) {
					int off = offset + i - 3;
					if (off >= 0) {
						if (memcmp(buffer.data+off, "\r\n\r\n", 4) == 0) {
							found = true;
							offset = off + 4;
							break;
						}
					}
				}
				if (found) {
					fwrite(buffer.data + offset, 1, bytes_read - offset, f);
					buffer.filesize += bytes_read-i;
				} else {
					offset += bytes_read;
				}
			} else {
				fwrite(buffer_found, 1, bytes_read, f);
				buffer.filesize += bytes_read;
			}
		} else {
			offset += bytes_read;
		}

		//Check if we have enough buffer left over,
		//if not expand it with an additional HTTP_BUFFER_GROWTH worth of bytes
		if(offset >= buffer.size)
		{
			buffer.size += HTTP_BUFFER_GROWTH;
			buffer.data = mem_realloc(buffer.data, buffer.size);
			
			if(buffer.data == NULL)
			{
				return emptyblock;
			}
		}

		// display progress
		if (http_progress) {
			if (fname == NULL) {
				while (offset / http_progress >= progress_count) {
					printf(".");
					progress_count++;
				}
			} else {
				while (buffer.filesize / http_progress >= progress_count) {
					printf(".");
					progress_count++;
				}
			}
		}
	}

	//At the end of above loop offset should be precisely the amount of bytes that were read from the connection
	buffer.size = offset;
	SAFE_FREE(buffer_found);
	if (fname != NULL)
		fclose(f);
		
	//Shrink the size of the buffer so the data fits exactly in it
	buffer.data = mem_realloc(buffer.data, buffer.size);
	if(buffer.data == NULL)
	{	
		return emptyblock;
	}
	
	return buffer;
}
Beispiel #18
0
/*
 * clipboard_copy_data - クリップボードデータのコピーを作成
 */
HANDLE clipboard_copy_data(const UINT format, const HANDLE data, DWORD *ret_size)
{
	HANDLE ret = NULL;
	BYTE *from_mem, *to_mem;
	LOGPALETTE *lpal;
	WORD pcnt;

	if (data == NULL) {
		return NULL;
	}

	switch (format) {
	case CF_PALETTE:
		// パレット
		pcnt = 0;
		if (GetObject(data, sizeof(WORD), &pcnt) == 0) {
			return NULL;
		}
		if ((lpal = mem_calloc(sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * pcnt))) == NULL) {
			return NULL;
		}
		lpal->palVersion = 0x300;
		lpal->palNumEntries = pcnt;
		if (GetPaletteEntries(data, 0, pcnt, lpal->palPalEntry) == 0) {
			mem_free(&lpal);
			return NULL;
		}

		ret = CreatePalette(lpal);
		*ret_size = sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * pcnt);

		mem_free(&lpal);
		break;

	case CF_DSPBITMAP:
	case CF_BITMAP:
		// ビットマップ
		if ((to_mem = bitmap_to_dib(data, ret_size)) == NULL) {
			return NULL;
		}
		ret = dib_to_bitmap(to_mem);
		mem_free(&to_mem);
		break;

	case CF_OWNERDISPLAY:
		*ret_size = 0;
		break;

	case CF_DSPMETAFILEPICT:
	case CF_METAFILEPICT:
		// コピー元ロック
		if ((from_mem = GlobalLock(data)) == NULL) {
			return NULL;
		}
		// メタファイル
		if ((ret = GlobalAlloc(GHND, sizeof(METAFILEPICT))) == NULL) {
			GlobalUnlock(data);
			return NULL;
		}
		// コピー先ロック
		if ((to_mem = GlobalLock(ret)) == NULL) {
			GlobalFree(ret);
			GlobalUnlock(data);
			return NULL;
		}
		CopyMemory(to_mem, from_mem, sizeof(METAFILEPICT));
		if ((((METAFILEPICT *)to_mem)->hMF = CopyMetaFile(((METAFILEPICT *)from_mem)->hMF, NULL)) != NULL) {
			*ret_size = sizeof(METAFILEPICT) + GetMetaFileBitsEx(((METAFILEPICT *)to_mem)->hMF, 0, NULL);
		}
		// ロック解除
		GlobalUnlock(ret);
		GlobalUnlock(data);
		break;

	case CF_DSPENHMETAFILE:
	case CF_ENHMETAFILE:
		// 拡張メタファイル
		if ((ret = CopyEnhMetaFile(data, NULL)) != NULL) {
			*ret_size = GetEnhMetaFileBits(ret, 0, NULL);
		}
		break;

	default:
		// その他
		// メモリチェック
		if (IsBadReadPtr(data, 1) == TRUE) {
			return NULL;
		}
		// サイズ取得
		if ((*ret_size = GlobalSize(data)) == 0) {
			return NULL;
		}
		// コピー元ロック
		if ((from_mem = GlobalLock(data)) == NULL) {
			return NULL;
		}

		// コピー先確保
		if ((ret = GlobalAlloc(GHND, *ret_size)) == NULL) {
			GlobalUnlock(data);
			return NULL;
		}
		// コピー先ロック
		if ((to_mem = GlobalLock(ret)) == NULL) {
			GlobalFree(ret);
			GlobalUnlock(data);
			return NULL;
		}

		// コピー
		CopyMemory(to_mem, from_mem, *ret_size);

		// ロック解除
		GlobalUnlock(ret);
		GlobalUnlock(data);
		break;
	}
	return ret;
}
Beispiel #19
0
void
menu_keys(struct terminal *term, void *d_, void *xxx)
{
	/* [gettext_accelerator_context(menu_keys)] */
	int d = (long) d_;

	/* We scale by main mapping because it has the most actions */
	action_id_T action_ids[MAIN_ACTIONS] = {
		ACT_MAIN_MENU,
		ACT_MAIN_QUIT,
		ACT_MAIN_MOVE_LINK_NEXT,
		ACT_MAIN_MOVE_LINK_PREV,
		ACT_MAIN_SCROLL_DOWN,
		ACT_MAIN_SCROLL_UP,
		ACT_MAIN_SCROLL_LEFT,
		ACT_MAIN_SCROLL_RIGHT,
		ACT_MAIN_HISTORY_MOVE_BACK,
		ACT_MAIN_GOTO_URL,
		ACT_MAIN_GOTO_URL_CURRENT,
		ACT_MAIN_DOCUMENT_INFO,
		ACT_MAIN_HEADER_INFO,
		ACT_MAIN_SEARCH,
		ACT_MAIN_SEARCH_BACK,
		ACT_MAIN_FIND_NEXT,
		ACT_MAIN_FIND_NEXT_BACK,
		ACT_MAIN_LINK_FOLLOW,
		ACT_MAIN_LINK_DOWNLOAD,
		ACT_MAIN_TOGGLE_HTML_PLAIN,

		ACT_MAIN_NONE,
	};
	struct string keys;
	struct keys_toggle_info *info;

	info = (struct keys_toggle_info *)mem_calloc(1, sizeof(*info));

	if (!info || !init_string(&keys)) {
		mem_free_if(info);
		return;
	}

	info->term = term;
	info->toggle = d;

	if (info->toggle) {
		int action_id;
		int keymap_id;

		for (action_id = 0; action_id < MAIN_ACTIONS - 1; action_id++) {
			action_ids[action_id] = action_id + 1;
		}

		for (keymap_id = 0; keymap_id < KEYMAP_MAX; keymap_id++) {
			add_actions_to_string(&keys, action_ids, keymap_id, term);
			if (keymap_id + 1 < KEYMAP_MAX)
				add_to_string(&keys, (const unsigned char *)"\n\n");

			/* Just a little reminder that the following code takes
			 * the easy way. */
			assert((int) MAIN_ACTIONS > (int) EDIT_ACTIONS);
			assert((int) EDIT_ACTIONS > (int) MENU_ACTIONS);

			if (keymap_id == KEYMAP_MAIN) {
				action_ids[EDIT_ACTIONS] = ACT_EDIT_NONE;
			} else if (keymap_id == KEYMAP_EDIT) {
				action_ids[MENU_ACTIONS] = ACT_MENU_NONE;
			}
		}
	} else {
		add_actions_to_string(&keys, action_ids, KEYMAP_MAIN, term);
	}

	msg_box(term, getml(info, (void *) NULL), MSGBOX_FREE_TEXT | MSGBOX_SCROLLABLE,
		N_("Keys"), ALIGN_LEFT,
		keys.source,
		info, 2,
		MSG_BOX_BUTTON(N_("~OK"), NULL, B_ENTER | B_ESC),
		MSG_BOX_BUTTON(N_("~Toggle display"), push_toggle_keys_display_button, B_ENTER));
}
Beispiel #20
0
/*
 * clipboard_data_to_bytes - データをバイト列に変換
 */
BYTE *clipboard_data_to_bytes(const DATA_INFO *di, DWORD *ret_size)
{
	BYTE *ret = NULL;
	BYTE *tmp;
	DWORD i;
	DWORD size = 0;

	if (di->data == NULL) {
		return NULL;
	}

	switch (di->format) {
	case CF_PALETTE:
		// パレット
		i = 0;
		GetObject(di->data, sizeof(WORD), &i);
		size = sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * i);
		if ((ret = mem_calloc(size)) == NULL) {
			break;
		}
		((LOGPALETTE *)ret)->palVersion = 0x300;
		((LOGPALETTE *)ret)->palNumEntries = (WORD)i;
		GetPaletteEntries(di->data, 0, i, ((LOGPALETTE *)ret)->palPalEntry);
		break;

	case CF_DSPBITMAP:
	case CF_BITMAP:
		// ビットマップ
		if ((ret = bitmap_to_dib(di->data, &size)) == NULL) {
			break;
		}
		break;

	case CF_OWNERDISPLAY:
		break;

	case CF_DSPMETAFILEPICT:
	case CF_METAFILEPICT:
		// メタファイル
		if ((tmp = GlobalLock(di->data)) == NULL) {
			break;
		}
		size = GetMetaFileBitsEx(((METAFILEPICT *)tmp)->hMF, 0, NULL);
		if ((ret = mem_alloc(size + sizeof(METAFILEPICT))) == NULL) {
			GlobalUnlock(di->data);
			break;
		}
		CopyMemory(ret, tmp, sizeof(METAFILEPICT));
		if (GetMetaFileBitsEx(((METAFILEPICT *)tmp)->hMF, size, ret + sizeof(METAFILEPICT)) == 0) {
			mem_free(&ret);
			GlobalUnlock(di->data);
			break;
		}
		size += sizeof(METAFILEPICT);
		GlobalUnlock(di->data);
		break;

	case CF_DSPENHMETAFILE:
	case CF_ENHMETAFILE:
		// 拡張メタファイル
		size = GetEnhMetaFileBits(di->data, 0, NULL);
		if ((ret = mem_alloc(size)) == NULL) {
			break;
		}
		if (GetEnhMetaFileBits(di->data, size, ret) == 0) {
			mem_free(&ret);
			break;
		}
		break;

	default:
		// その他
		if ((tmp = GlobalLock(di->data)) == NULL) {
			break;
		}
		size = di->size;
		if ((ret = mem_alloc(size)) == NULL) {
			GlobalUnlock(di->data);
			break;
		}
		CopyMemory(ret, tmp, size);
		GlobalUnlock(di->data);
		break;
	}
	if (ret_size != NULL) {
		*ret_size = size;
	}
	return ret;
}
Beispiel #21
0
/*
 * menu_create_info - メニュー情報の作成
 */
static MENU_ITEM_INFO *menu_create_info(MENU_INFO *menu_info, const int menu_cnt,
										DATA_INFO *history_di, DATA_INFO *regist_di,
										int *id, int *ret_cnt)
{
	MENU_ITEM_INFO *mii;
	DATA_INFO *di;
	int i, j, t;
	int cnt;

	// メニュー項目数の取得
	for (i = 0, *ret_cnt = 0; i < menu_cnt; i++) {
		switch ((menu_info + i)->content) {
		case MENU_CONTENT_SEPARATOR:
		case MENU_CONTENT_POPUP:
		case MENU_CONTENT_VIEWER:
		case MENU_CONTENT_OPTION:
		case MENU_CONTENT_CLIPBOARD_WATCH:
		case MENU_CONTENT_APP:
		case MENU_CONTENT_CANCEL:
		case MENU_CONTENT_EXIT:
			(*ret_cnt)++;
			break;

		case MENU_CONTENT_HISTORY:
		case MENU_CONTENT_HISTORY_DESC:
			for (di = history_di, cnt = 0; di != NULL &&
				(menu_info + i)->min > 0 && cnt < (menu_info + i)->min - 1; di = di->next, cnt++);
			for (; di != NULL &&
				((menu_info + i)->max <= 0 || cnt < (menu_info + i)->max); di = di->next, (*ret_cnt)++, cnt++);
			break;

		case MENU_CONTENT_REGIST:
		case MENU_CONTENT_REGIST_DESC:
			di = regist_path_to_item(regist_di, (menu_info + i)->path);
			for (; di != NULL; di = di->next, (*ret_cnt)++)
				;
			break;

		case MENU_CONTENT_TOOL:
			if ((menu_info + i)->path != NULL && *(menu_info + i)->path != TEXT('\0')) {
				if (tool_title_to_index((menu_info + i)->path) != -1) {
					(*ret_cnt)++;
				}
			} else {
				for (t = 0; t < option.tool_cnt; t++) {
					if ((option.tool_info + t)->call_type & CALLTYPE_MENU) {
						(*ret_cnt)++;
					}
				}
			}
			break;
		}
	}

	// メニュー項目情報の確保
	if ((mii = mem_calloc(sizeof(MENU_ITEM_INFO) * (*ret_cnt))) == NULL) {
		*ret_cnt = 0;
		return NULL;
	}

	// メニュー項目情報の作成
	for (i = 0, j = 0; i < menu_cnt; i++) {
		switch ((menu_info + i)->content) {
		case MENU_CONTENT_SEPARATOR:
			// 区切り
			(mii + j)->id = 0;
			(mii + j)->flag = MF_SEPARATOR | MF_OWNERDRAW;
			(mii + j)->item = (LPCTSTR)(mii + j);
			j++;
			break;

		case MENU_CONTENT_HISTORY:
			// 履歴 (昇順)
			if (menu_create_datainfo(history_di, mii, j, id, 1, (menu_info + i)->min, (menu_info + i)->max) == TRUE) {
				for (di = history_di, cnt = 0; di != NULL &&
					(menu_info + i)->min > 0 && cnt < (menu_info + i)->min - 1; di = di->next, cnt++);
				for (; di != NULL &&
					((menu_info + i)->max <= 0 || cnt < (menu_info + i)->max); di = di->next, j++, cnt++);
			}
			break;

		case MENU_CONTENT_HISTORY_DESC:
			// 履歴 (降順)
			if (menu_create_datainfo(history_di, mii, j, id, -1, (menu_info + i)->min, (menu_info + i)->max) == TRUE) {
				for (di = history_di, cnt = 0; di != NULL &&
					(menu_info + i)->min > 0 && cnt < (menu_info + i)->min - 1; di = di->next, cnt++)
					;
				for (; di != NULL &&
					((menu_info + i)->max <= 0 || cnt < (menu_info + i)->max); di = di->next, j++, cnt++)
					;
			}
			break;

		case MENU_CONTENT_REGIST:
			// 登録アイテム (昇順)
			di = regist_path_to_item(regist_di, (menu_info + i)->path);
			if (di != NULL && menu_create_datainfo(di, mii, j, id, 1, 0, 0) == TRUE) {
				for (; di != NULL; di = di->next, j++)
					;
			}
			break;

		case MENU_CONTENT_REGIST_DESC:
			// 登録アイテム (降順)
			di = regist_path_to_item(regist_di, (menu_info + i)->path);
			if (di != NULL && menu_create_datainfo(di, mii, j, id, -1, 0, 0) == TRUE) {
				for (; di != NULL; di = di->next, j++)
					;
			}
			break;

		case MENU_CONTENT_POPUP:
			// ポップアップメニュー
			(mii + j)->flag = MF_POPUP | MF_OWNERDRAW;
			(mii + j)->item = (LPCTSTR)(mii + j);
			(mii + j)->text = alloc_copy((menu_info + i)->title);
			(mii + j)->icon = menu_read_icon((menu_info + i)->icon_path, (menu_info + i)->icon_index, option.menu_icon_size);
			(mii + j)->free_icon = TRUE;
			(mii + j)->mii = menu_create_info(
				(menu_info + i)->mi, (menu_info + i)->mi_cnt,
				history_di, regist_di, id, &(mii + j)->mii_cnt);
			j++;
			break;

		case MENU_CONTENT_VIEWER:
			// ビューア
			(mii + j)->id = ID_MENUITEM_VIEWER;
			(mii + j)->flag = MF_OWNERDRAW;
			(mii + j)->item = (LPCTSTR)(mii + j);
			(mii + j)->text = alloc_copy(((menu_info + i)->title == NULL || *(menu_info + i)->title == TEXT('\0')) ?
				message_get_res(IDS_MENU_VIEWER) : (menu_info + i)->title);
			(mii + j)->icon = menu_read_icon((menu_info + i)->icon_path, (menu_info + i)->icon_index, option.menu_icon_size);
			(mii + j)->free_icon = TRUE;
			j++;
			break;

		case MENU_CONTENT_OPTION:
			// オプション
			(mii + j)->id = ID_MENUITEM_OPTION;
			(mii + j)->flag = MF_OWNERDRAW;
			(mii + j)->item = (LPCTSTR)(mii + j);
			(mii + j)->text = alloc_copy(((menu_info + i)->title == NULL || *(menu_info + i)->title == TEXT('\0')) ?
				message_get_res(IDS_MENU_OPTION) : (menu_info + i)->title);
			(mii + j)->icon = menu_read_icon((menu_info + i)->icon_path, (menu_info + i)->icon_index, option.menu_icon_size);
			(mii + j)->free_icon = TRUE;
			j++;
			break;

		case MENU_CONTENT_CLIPBOARD_WATCH:
			// クリップボード監視切り替え
			(mii + j)->id = ID_MENUITEM_CLIPBOARD_WATCH;
			(mii + j)->flag = MF_OWNERDRAW | ((option.main_clipboard_watch == 1) ? MF_CHECKED : 0);
			(mii + j)->item = (LPCTSTR)(mii + j);
			(mii + j)->text = alloc_copy(((menu_info + i)->title == NULL || *(menu_info + i)->title == TEXT('\0')) ?
				message_get_res(IDS_MENU_CLIPBOARD_WATCH) : (menu_info + i)->title);
			(mii + j)->icon = menu_read_icon((menu_info + i)->icon_path, (menu_info + i)->icon_index, option.menu_icon_size);
			(mii + j)->free_icon = TRUE;
			j++;
			break;

		case MENU_CONTENT_TOOL:
			// ツール
			if ((menu_info + i)->path != NULL && *(menu_info + i)->path != TEXT('\0')) {
				if ((t = tool_title_to_index((menu_info + i)->path)) != -1) {
					(mii + j)->id = ID_MENUITEM_DATA + ((*id)++);
					(mii + j)->flag = MF_OWNERDRAW;
					(mii + j)->item = (LPCTSTR)(mii + j);
					if ((menu_info + i)->title != NULL && *(menu_info + i)->title != TEXT('\0')) {
						(mii + j)->text = alloc_copy((menu_info + i)->title);
					} else {
						(mii + j)->text = alloc_copy((option.tool_info + t)->title);
					}
					if (option.menu_show_hotkey == 1) {
						(mii + j)->hkey = menu_get_keyname((option.tool_info + t)->modifiers, (option.tool_info + t)->virtkey);
					}
					(mii + j)->icon = menu_read_icon((menu_info + i)->icon_path, (menu_info + i)->icon_index, option.menu_icon_size);
					(mii + j)->free_icon = TRUE;
					(mii + j)->ti = option.tool_info + t;
					j++;
				}
			} else {
				for (t = 0; t < option.tool_cnt; t++) {
					if (!((option.tool_info + t)->call_type & CALLTYPE_MENU)) {
						continue;
					}
					if (lstrcmp((option.tool_info + t)->title, TEXT("-")) == 0) {
						(mii + j)->id = 0;
						(mii + j)->flag = MF_SEPARATOR | MF_OWNERDRAW;
						(mii + j)->item = (LPCTSTR)(mii + j);
					} else {
						(mii + j)->id = ID_MENUITEM_DATA + ((*id)++);
						(mii + j)->flag = MF_OWNERDRAW;
						(mii + j)->item = (LPCTSTR)(mii + j);
						(mii + j)->text = alloc_copy((option.tool_info + t)->title);
						if (option.menu_show_hotkey == 1) {
							(mii + j)->hkey = menu_get_keyname((option.tool_info + t)->modifiers, (option.tool_info + t)->virtkey);
						}
						(mii + j)->ti = option.tool_info + t;
					}
					j++;
				}
			}
			break;

		case MENU_CONTENT_APP:
			// アプリケーション実行
			(mii + j)->id = ID_MENUITEM_DATA + ((*id)++);
			(mii + j)->flag = MF_OWNERDRAW;
			(mii + j)->item = (LPCTSTR)(mii + j);
			(mii + j)->text = alloc_copy((menu_info + i)->title);
			if (*(menu_info + i)->icon_path != TEXT('\0')) {
				(mii + j)->icon = menu_read_icon((menu_info + i)->icon_path, (menu_info + i)->icon_index, option.menu_icon_size);
			} else {
				(mii + j)->icon = menu_read_icon((menu_info + i)->path, 0, option.menu_icon_size);
			}
			(mii + j)->free_icon = TRUE;
			// メニュー情報を設定
			(mii + j)->mi = menu_info + i;
			j++;
			break;

		case MENU_CONTENT_CANCEL:
			// キャンセル
			(mii + j)->id = IDCANCEL;
			(mii + j)->flag = MF_OWNERDRAW;
			(mii + j)->item = (LPCTSTR)(mii + j);
			(mii + j)->text = alloc_copy(((menu_info + i)->title == NULL || *(menu_info + i)->title == TEXT('\0')) ?
				message_get_res(IDS_MENU_CANCEL) : (menu_info + i)->title);
			(mii + j)->icon = menu_read_icon((menu_info + i)->icon_path, (menu_info + i)->icon_index, option.menu_icon_size);
			(mii + j)->free_icon = TRUE;
			j++;
			break;

		case MENU_CONTENT_EXIT:
			// 終了
			(mii + j)->id = ID_MENUITEM_EXIT;
			(mii + j)->flag = MF_OWNERDRAW;
			(mii + j)->item = (LPCTSTR)(mii + j);
			(mii + j)->text = alloc_copy(((menu_info + i)->title == NULL || *(menu_info + i)->title == TEXT('\0')) ?
				message_get_res(IDS_MENU_EXIT) : (menu_info + i)->title);
			(mii + j)->icon = menu_read_icon((menu_info + i)->icon_path, (menu_info + i)->icon_index, option.menu_icon_size);
			(mii + j)->free_icon = TRUE;
			j++;
			break;
		}
	}
	return mii;
}
Beispiel #22
0
static void
do_html_select(unsigned char *attr, unsigned char *html,
	       unsigned char *eof, unsigned char **end,
	       struct html_context *html_context)
{
	struct conv_table *ct = (struct conv_table *)html_context->special_f(html_context, SP_TABLE, NULL);
	struct form_control *fc;
	struct string lbl = NULL_STRING, orig_lbl = NULL_STRING;
	unsigned char **values = NULL;
	unsigned char **labels;
	unsigned char *name, *t_attr, *en;
	int namelen;
	int nnmi = 0;
	int order = 0;
	int preselect = -1;
	int group = 0;
	int i, max_width;
	int closing_tag;

	html_focusable(html_context, attr);
	init_menu(&lnk_menu);

se:
        en = html;

see:
        html = en;
	while (html < eof && *html != '<') html++;

	if (html >= eof) {

abort:
		*end = html;
		if (lbl.source) done_string(&lbl);
		if (orig_lbl.source) done_string(&orig_lbl);
		if (values) {
			int j;

			for (j = 0; j < order; j++)
				mem_free_if(values[j]);
			mem_free(values);
		}
		destroy_menu(&lnk_menu);
		*end = en;
		return;
	}

	if (lbl.source) {
		unsigned char *q, *s = en;
		int l = html - en;

		while (l && isspace(s[0])) s++, l--;
		while (l && isspace(s[l-1])) l--;
		q = convert_string(ct, s, l,
		                   html_context->options->cp,
		                   CSM_DEFAULT, NULL, NULL, NULL);
		if (q) add_to_string(&lbl, q), mem_free(q);
		add_bytes_to_string(&orig_lbl, s, l);
	}

	if (html + 2 <= eof && (html[1] == '!' || html[1] == '?')) {
		html = skip_comment(html, eof);
		goto se;
	}

	if (parse_element(html, eof, &name, &namelen, &t_attr, &en)) {
		html++;
		goto se;
	}

	if (!namelen) goto see;

	if (name[0] == '/') {
		namelen--;
		if (!namelen) goto see;
		name++;
		closing_tag = 1;
	} else {
		closing_tag = 0;
	}

	if (closing_tag && !c_strlcasecmp(name, namelen, (const unsigned char *)"SELECT", 6)) {
		add_select_item(&lnk_menu, &lbl, &orig_lbl, values, order, nnmi);
		goto end_parse;
	}

	if (!c_strlcasecmp(name, namelen, (const unsigned char *)"OPTION", 6)) {
		add_select_item(&lnk_menu, &lbl, &orig_lbl, values, order, nnmi);

		if (!closing_tag) {
			unsigned char *value, *label;

			if (has_attr(t_attr, (unsigned char *)"disabled", html_context->doc_cp))
				goto see;
			if (preselect == -1
			    && has_attr(t_attr, (unsigned char *)"selected", html_context->doc_cp))
				preselect = order;
			value = get_attr_val(t_attr, (unsigned char *)"value", html_context->doc_cp);

			if (!mem_align_alloc(&values, order, order + 1, 0xFF))
				goto abort;

			values[order++] = value;
			label = get_attr_val(t_attr, (unsigned char *)"label", html_context->doc_cp);
			if (label) new_menu_item(&lnk_menu, label, order - 1, 0);
			if (!value || !label) {
				init_string(&lbl);
				init_string(&orig_lbl);
				nnmi = !!label;
			}
		}

		goto see;
	}

	if (!c_strlcasecmp(name, namelen, (const unsigned char *)"OPTGROUP", 8)) {
		add_select_item(&lnk_menu, &lbl, &orig_lbl, values, order, nnmi);

		if (group) new_menu_item(&lnk_menu, NULL, -1, 0), group = 0;

		if (!closing_tag) {
			unsigned char *label;

			label = get_attr_val(t_attr, (unsigned char *)"label", html_context->doc_cp);

			if (!label) {
				label = stracpy((const unsigned char *)"");
				if (!label) goto see;
			}
			new_menu_item(&lnk_menu, label, -1, 0);
			group = 1;
		}
	}

	goto see;


end_parse:
	*end = en;
	if (!order) goto abort;

	labels = (unsigned char **)mem_calloc(order, sizeof(unsigned char *));
	if (!labels) goto abort;

	fc = init_form_control(FC_SELECT, attr, html_context);
	if (!fc) {
		mem_free(labels);
		goto abort;
	}

	fc->id = get_attr_val(attr, (unsigned char *)"id", html_context->doc_cp);
	fc->name = get_attr_val(attr, (unsigned char *)"name", html_context->doc_cp);
	fc->default_state = preselect < 0 ? 0 : preselect;
	fc->default_value = order ? stracpy(values[fc->default_state]) : stracpy((const unsigned char *)"");
	fc->nvalues = order;
	fc->values = values;
	fc->menu = detach_menu(&lnk_menu);
	fc->labels = labels;

	menu_labels(fc->menu, (unsigned char *)"", labels);
	put_chrs(html_context, (unsigned char *)"[", 1);
	html_stack_dup(html_context, ELEMENT_KILLABLE);
	format.form = fc;
	format.style.attr |= AT_BOLD;

	max_width = 0;
	for (i = 0; i < order; i++) {
		if (!labels[i]) continue;
#ifdef CONFIG_UTF8
		if (html_context->options->utf8)
			int_lower_bound(&max_width,
					utf8_ptr2cells(labels[i], NULL));
		else
#endif /* CONFIG_UTF8 */
			int_lower_bound(&max_width, strlen((const char *)labels[i]));
	}

	for (i = 0; i < max_width; i++)
		put_chrs(html_context, (unsigned char *)"_", 1);

	pop_html_element(html_context);
	put_chrs(html_context, (unsigned char *)"]", 1);
	html_context->special_f(html_context, SP_CONTROL, fc);
}
Beispiel #23
0
/*!
 ***********************************************************************
 * \brief
 *    Allocate the Input structure
 * \par  Output:
 *    Input Parameters InputParameters *p_Vid
 ***********************************************************************
 */
static void alloc_params( InputParameters **p_Inp )
{
  if ((*p_Inp = (InputParameters *) mem_calloc(1, sizeof(InputParameters)))==NULL) 
    no_mem_exit("alloc_params: p_Inp");
}
Beispiel #24
0
/*
 * set_filter_item_proc - フィルタの項目を設定
 */
static BOOL CALLBACK set_filter_item_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	HMENU hMenu;
	RECT button_rect;
	FILTER_INFO *fi;
	TCHAR buf[BUF_SIZE];
	DWORD ret;
	UINT format;
#ifdef OP_XP_STYLE
	static long hTheme;
#endif	// OP_XP_STYLE

	switch (uMsg) {
	case WM_INITDIALOG:
#ifdef OP_XP_STYLE
		// XP
		hTheme = open_theme(GetDlgItem(hDlg, IDC_BUTTON_FORMAT), L"SCROLLBAR");
#endif	// OP_XP_STYLE
		// スピンコントロールの設定
		SendDlgItemMessage(hDlg, IDC_SPIN_SIZE, UDM_SETRANGE, 0, (LPARAM)MAKELONG(UD_MAXVAL, 0));

		if (lParam == 0) {
			// 新規追加
			if (*cmd_filter != TEXT('\0')) {
				SendDlgItemMessage(hDlg, IDC_EDIT_FORMAT_NAME, WM_SETTEXT, 0, (LPARAM)cmd_filter);
				*cmd_filter = TEXT('\0');
			}
			CheckDlgButton(hDlg, IDC_RADIO_ADD, 1);
			SetDlgItemInt(hDlg, IDC_EDIT_SIZE, 0, FALSE);
			SetWindowLong(hDlg, GWL_USERDATA, 0);
			break;
		}
		fi = (FILTER_INFO *)lParam;

		SendDlgItemMessage(hDlg, IDC_EDIT_FORMAT_NAME, WM_SETTEXT, 0, (LPARAM)fi->format_name);
		if (fi->action == FILTER_ACTION_ADD) {
			CheckDlgButton(hDlg, IDC_RADIO_ADD, 1);
		} else {
			CheckDlgButton(hDlg, IDC_RADIO_IGNORE, 1);
		}
		CheckDlgButton(hDlg, IDC_CHECK_NOSAVE, !fi->save);
		SetDlgItemInt(hDlg, IDC_EDIT_SIZE, fi->limit_size, FALSE);

		EnableWindow(GetDlgItem(hDlg, IDC_CHECK_NOSAVE), IsDlgButtonChecked(hDlg, IDC_RADIO_ADD));
		EnableWindow(GetDlgItem(hDlg, IDC_EDIT_SIZE), IsDlgButtonChecked(hDlg, IDC_RADIO_ADD));

		SetWindowLong(hDlg, GWL_USERDATA, lParam);
		break;

	case WM_CLOSE:
#ifdef OP_XP_STYLE
		if (hTheme != 0) {
			close_theme(hTheme);
		}
#endif	// OP_XP_STYLE
		EndDialog(hDlg, FALSE);
		break;

	case WM_DRAWITEM:
		// ボタンの描画
#ifdef OP_XP_STYLE
		if (hTheme != 0) {
			draw_theme_scroll((LPDRAWITEMSTRUCT)lParam, DFCS_SCROLLRIGHT, hTheme);
		} else {
			draw_scroll_sontrol((LPDRAWITEMSTRUCT)lParam, DFCS_SCROLLRIGHT);
		}
#else	// OP_XP_STYLE
		draw_scroll_sontrol((LPDRAWITEMSTRUCT)lParam, DFCS_SCROLLRIGHT);
#endif	// OP_XP_STYLE
		break;

#ifdef OP_XP_STYLE
	case WM_THEMECHANGED:
		// テーマの変更
		if (hTheme != 0) {
			close_theme(hTheme);
		}
		hTheme = open_theme(GetDlgItem(hDlg, IDC_BUTTON_FORMAT), L"SCROLLBAR");
		break;
#endif	// OP_XP_STYLE

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDC_BUTTON_FORMAT:
			// 形式選択
			if (OpenClipboard(hDlg) == FALSE) {
				break;
			}
			// メニューの作成
			hMenu = CreatePopupMenu();
			format = 0;
			ret = 1;
			while ((format = EnumClipboardFormats(format)) != 0) {
				clipboard_get_format(format, buf);
				AppendMenu(hMenu, MF_STRING, ret++, buf);
			}
			CloseClipboard();
			if (ret == 1) {
				DestroyMenu(hMenu);
				break;
			}

			// メニューの表示
			GetWindowRect(GetDlgItem(hDlg, LOWORD(wParam)), (LPRECT)&button_rect);
			ret = TrackPopupMenu(hMenu, TPM_TOPALIGN | TPM_RETURNCMD, button_rect.right, button_rect.top, 0, hDlg, NULL);
			if (ret > 0) {
				GetMenuString(hMenu, ret, buf, BUF_SIZE - 1, MF_BYCOMMAND);
				SendDlgItemMessage(hDlg, IDC_EDIT_FORMAT_NAME, EM_REPLACESEL, 0, (LPARAM)buf);
			}
			DestroyMenu(hMenu);
			break;

		case IDC_RADIO_ADD:
		case IDC_RADIO_IGNORE:
			EnableWindow(GetDlgItem(hDlg, IDC_CHECK_NOSAVE), IsDlgButtonChecked(hDlg, IDC_RADIO_ADD));
			EnableWindow(GetDlgItem(hDlg, IDC_EDIT_SIZE), IsDlgButtonChecked(hDlg, IDC_RADIO_ADD));
			break;

		case IDOK:
			*buf = TEXT('\0');
			SendDlgItemMessage(hDlg, IDC_EDIT_FORMAT_NAME, WM_GETTEXT, BUF_SIZE - 1, (LPARAM)buf);
			if (*buf == TEXT('\0')) {
				MessageBox(hDlg, message_get_res(IDS_FILTER_ERR_NAME), WINDOW_TITLE, MB_ICONEXCLAMATION);
				SetFocus(GetDlgItem(hDlg, IDC_EDIT_FORMAT_NAME));
				break;
			}

			if ((fi = (FILTER_INFO *)GetWindowLong(hDlg, GWL_USERDATA)) == NULL) {
				fi = mem_calloc(sizeof(FILTER_INFO));
			}
			if (fi != NULL) {
				// 設定取得
				alloc_get_text(GetDlgItem(hDlg, IDC_EDIT_FORMAT_NAME), &fi->format_name);
				fi->action = IsDlgButtonChecked(hDlg, IDC_RADIO_IGNORE);
				fi->save = !IsDlgButtonChecked(hDlg, IDC_CHECK_NOSAVE);
				fi->limit_size = GetDlgItemInt(hDlg, IDC_EDIT_SIZE, NULL, FALSE);
			}

			if (GetWindowLong(hDlg, GWL_USERDATA) == 0) {
				// 新規
				HWND pWnd = PropSheet_GetCurrentPageHwnd(GetParent(hDlg));
				listview_set_filter(GetDlgItem(pWnd, IDC_LIST_FILTER), fi, FALSE);
			}
#ifdef OP_XP_STYLE
			if (hTheme != 0) {
				close_theme(hTheme);
			}
#endif	// OP_XP_STYLE
			EndDialog(hDlg, TRUE);
			break;

		case IDCANCEL:
#ifdef OP_XP_STYLE
			if (hTheme != 0) {
				close_theme(hTheme);
			}
#endif	// OP_XP_STYLE
			EndDialog(hDlg, FALSE);
			break;
		}
		break;

	default:
		return FALSE;
	}
	return TRUE;
}
Beispiel #25
0
tpool_t* tpool_create (int num_threads)
{
    int             i, ret;
    tpool_t         *tpool;
    pthread_attr_t  attr;

    tpool = mem_calloc (1, sizeof (tpool_t));
    if (tpool == NULL) 
        return NULL;

    tpool->num_threads = num_threads;
    tpool->num_workers = num_threads;

    tpool->args = (void **)mem_malloc (sizeof (void *) * num_threads);
    if (tpool->args == NULL) 
        goto fail_args;

    tpool->threads = (pthread_t *)mem_malloc (sizeof (pthread_t) * num_threads);
    if (tpool->threads == NULL) 
        goto fail_threads;

    tpool->thread_args = (thread_arg_t *)mem_malloc (
        sizeof (thread_arg_t) * num_threads);
    if (tpool->thread_args == NULL) 
        goto fail_thread_args;

    ret = sem_init (&tpool->sem_all_workers_done, 0, 0);
    if (ret != 0) 
        goto fail_all_workers_done;

    CHECK_ERROR (pthread_attr_init (&attr));
    CHECK_ERROR (pthread_attr_setscope (&attr, PTHREAD_SCOPE_SYSTEM));
    CHECK_ERROR (pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED));

    tpool->die = 0;
    for (i = 0; i < num_threads; ++i) {
        /* Initialize thread argument. */
        CHECK_ERROR (sem_init (&(tpool->thread_args[i].sem_run), 0, 0));
        tpool->thread_args[i].sem_all_workers_done = 
            &tpool->sem_all_workers_done;
        tpool->thread_args[i].num_workers_done = 
            &tpool->num_workers_done;
        tpool->thread_args[i].die = &tpool->die;
        tpool->thread_args[i].thread_func = &tpool->thread_func;
        tpool->thread_args[i].thread_func_arg = &tpool->args[i];
        tpool->thread_args[i].ret = (void **)mem_malloc (sizeof (void *));
        CHECK_ERROR (tpool->thread_args[i].ret == NULL);
        tpool->thread_args[i].num_workers = &tpool->num_workers;
        
        ret = liblock_thread_create (
            &tpool->threads[i], &attr, thread_loop, &tpool->thread_args[i]);
        if (ret) 
            goto fail_thread_create;
    }

    return tpool;

fail_thread_create:
    --i;
    while (i >= 0)
    {
        pthread_cancel (tpool->threads[i]);
        --i;
    }
fail_all_workers_done:
    mem_free (tpool->thread_args);
fail_thread_args:
    mem_free (tpool->threads);
fail_threads:
    mem_free (tpool->args);
fail_args:

    return NULL;
}
Beispiel #26
0
/*
 * select_tools_proc - ツール選択ウィンドウプロシージャ
 */
static BOOL CALLBACK select_tools_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	HWND pWnd;
	TOOL_INFO *ti;
	TCHAR buf[BUF_SIZE];
	static TCHAR lib_path[BUF_SIZE];
	int call_type;
	int i, j;
	static int old;

	switch (uMsg) {
	case WM_INITDIALOG:
		SetWindowText(hDlg, message_get_res(IDS_TOOL_SELECT_TITLE));
		SetWindowText(GetDlgItem(hDlg, IDC_STATIC_MSG), message_get_res(IDS_TOOL_SELECT_MSG));

		if (dll_to_list(hDlg, (TCHAR *)lParam, &old) == FALSE) {
			EndDialog(hDlg, FALSE);
			break;
		}
		// リストビューのスタイルの設定
		SetWindowLong(GetDlgItem(hDlg, IDC_LIST_HEADER), GWL_STYLE,
			GetWindowLong(GetDlgItem(hDlg, IDC_LIST_HEADER), GWL_STYLE) & ~LVS_SINGLESEL);

		lstrcpy(lib_path, (TCHAR *)lParam);

		EnableWindow(GetDlgItem(hDlg, IDOK), FALSE);
		break;

	case WM_CLOSE:
		EndDialog(hDlg, FALSE);
		break;

	case WM_NOTIFY:
		listview_notify_proc(hDlg, lParam, GetDlgItem(hDlg, IDC_LIST_HEADER));
		break;

	case WM_LV_EVENT:
		switch (wParam) {
		case LVN_ITEMCHANGED:
			if (ListView_GetSelectedCount(GetDlgItem(hDlg, IDC_LIST_HEADER)) <= 0) {
				EnableWindow(GetDlgItem(hDlg, IDOK), FALSE);
			} else {
				EnableWindow(GetDlgItem(hDlg, IDOK), TRUE);
			}
			break;
		}
		break;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDCANCEL:
			SendMessage(hDlg, WM_CLOSE, 0, 0);
			break;

		case IDC_BUTTON_EDIT:
		case IDOK:
			pWnd = PropSheet_GetCurrentPageHwnd(GetParent(hDlg));

			i = -1;
			while ((i = ListView_GetNextItem(GetDlgItem(hDlg, IDC_LIST_HEADER), i, LVNI_SELECTED)) != -1) {
				if ((ti = mem_calloc(sizeof(TOOL_INFO))) != NULL) {
					// 設定取得
					ti->lib_file_path = alloc_copy(lib_path);

					ListView_GetItemText(GetDlgItem(hDlg, IDC_LIST_HEADER), i, 0, buf, BUF_SIZE - 1);
					ti->title = alloc_copy(buf);
					ListView_GetItemText(GetDlgItem(hDlg, IDC_LIST_HEADER), i, 1, buf, BUF_SIZE - 1);
					ti->func_name = alloc_copy(buf);
					ListView_GetItemText(GetDlgItem(hDlg, IDC_LIST_HEADER), i, 2, buf, BUF_SIZE - 1);
					ti->cmd_line = alloc_copy(buf);

					call_type = listview_get_lparam(GetDlgItem(hDlg, IDC_LIST_HEADER), i);
					if (old == 1) {
						j = CALLTYPE_VIEWER;
						if (!(call_type & OLD_CALLTYPE_MENU)) {
							j |= CALLTYPE_MENU;
							ti->copy_paste = 1;
						}
						if (call_type & OLD_CALLTYPE_ADD_HISTORY) {
							j |= CALLTYPE_ADD_HISTORY;
						}
						if (call_type & OLD_CALLTYPE_ITEM_TO_CLIPBOARD) {
							j |= CALLTYPE_ITEM_TO_CLIPBOARD;
						}
						if (call_type & OLD_CALLTYPE_START) {
							j |= CALLTYPE_START;
						}
						if (call_type & OLD_CALLTYPE_END) {
							j |= CALLTYPE_END;
						}
						ti->call_type = j;
					} else {
						ti->copy_paste = (call_type & CALLTYPE_MENU_COPY_PASTE) ? 1 : 0;
						ti->call_type = call_type & ~CALLTYPE_MENU_COPY_PASTE;
					}
					ti->old = old;

					// 新規追加
					listview_set_tool(GetDlgItem(pWnd, IDC_LIST_TOOL), ti, FALSE);
				}
			}
			EndDialog(hDlg, TRUE);
			break;
		}
		break;

	case WM_GET_VERSION:
		// バージョン取得
		return APP_VAR;

	case WM_GET_WORKPATH:
		// 作業ディレクトリ取得
		if (lParam == 0) {
			break;
		}
		lstrcpy((TCHAR *)lParam, work_path);
		break;

	default:
		return FALSE;
	}
	return TRUE;
}
Beispiel #27
0
int  get_incr_sccs(CTXTdeclc Cell listterm) {
  Cell orig_listterm, intterm, node;
    long int node_num=0;
    int i = 0, dfn, component = 1;     int * dfn_stack; int dfn_top = 0, ret;
    SCCNode * nodes;
    struct hashtable_itr *itr;     struct hashtable* hasht; 
    XSB_Deref(listterm);
    hasht = create_hashtable1(HASH_TABLE_SIZE, hashid, equalkeys);
    orig_listterm = listterm;
    intterm = get_list_head(listterm);
    XSB_Deref(intterm);
    //    printf("listptr %p @%p\n",listptr,(CPtr) int_val(*listptr));
    insert_some(hasht,(void *) oint_val(intterm),(void *) node_num);
    node_num++; 

    listterm = get_list_tail(listterm);
    XSB_Deref(listterm);
    while (!isnil(listterm)) {
      intterm = get_list_head(listterm);
      XSB_Deref(intterm);
      node = oint_val(intterm);
      if (NULL == search_some(hasht, (void *)node)) {
	insert_some(hasht,(void *)node,(void *)node_num);
	node_num++;
      }
      listterm = get_list_tail(listterm);
      XSB_Deref(listterm);
    }
    nodes = (SCCNode *) mem_calloc(node_num, sizeof(SCCNode),OTHER_SPACE); 
    dfn_stack = (int *) mem_alloc(node_num*sizeof(int),OTHER_SPACE); 
    listterm = orig_listterm;; 
    //printf("listptr %p @%p\n",listptr,(void *)int_val(*(listptr)));
    intterm = get_list_head(listterm);
    XSB_Deref(intterm);
    nodes[0].node = (CPtr) oint_val(intterm);
    listterm = get_list_tail(listterm);
    XSB_Deref(listterm);
    i = 1;
    while (!isnil(listterm)) {
      intterm = get_list_head(listterm);
      XSB_Deref(intterm);
      node = oint_val(intterm);
      nodes[i].node = (CPtr) node;
      listterm = get_list_tail(listterm);
      XSB_Deref(listterm);
      i++;
    }
    itr = hashtable1_iterator(hasht);       
    //    do {
    //      printf("k %p val %p\n",hashtable1_iterator_key(itr),hashtable1_iterator_value(itr));
    //    } while (hashtable1_iterator_advance(itr));

    listterm = orig_listterm;
    //    printf("2: k %p v %p\n",(void *) int_val(*listptr),
    //	   search_some(hasht,(void *) int_val(*listptr)));

    //    while (!isnil(*listptr)) {  now all wrong...
    //      listptr = listptr + 1;
    //      node = int_val(*clref_val(listptr));
    //      printf("2: k %p v %p\n",(CPtr) node,search_some(hasht,(void *) node));
    //      listptr = listptr + 1;
    //    }
    dfn = 1;
    for (i = 0; i < node_num; i++) {
      if (nodes[i].dfn == 0) 
	xsb_compute_scc(nodes,dfn_stack,i,&dfn_top,hasht,&dfn,&component);
      //      printf("++component for node %d is %d (high %d)\n",i,nodes[i].component,component);
    }
    ret = return_scc_list(CTXTc  nodes, node_num);
    hashtable1_destroy(hasht,0);
    mem_dealloc(nodes,node_num*sizeof(SCCNode),OTHER_SPACE); 
    mem_dealloc(dfn_stack,node_num*sizeof(int),OTHER_SPACE); 
    return ret;
}
Beispiel #28
0
/*
 * set_tool_item_proc - ツールの項目を設定
 */
static BOOL CALLBACK set_tool_item_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	TOOL_INFO *ti;
	TCHAR buf[BUF_SIZE];
	int i;

	switch (uMsg) {
	case WM_INITDIALOG:
		if (lParam == 0) {
			// 新規追加
			SendMessage(hDlg, WM_COMMAND, IDC_CHECK_MENU, 0);
			SetWindowLong(hDlg, GWL_USERDATA, 0);
			break;
		}
		ti = (TOOL_INFO *)lParam;

		SendDlgItemMessage(hDlg, IDC_EDIT_TITLE, WM_SETTEXT, 0, (LPARAM)ti->title);
		SendDlgItemMessage(hDlg, IDC_EDIT_LIB_PATH, WM_SETTEXT, 0, (LPARAM)ti->lib_file_path);
		SendDlgItemMessage(hDlg, IDC_EDIT_HEADER, WM_SETTEXT, 0, (LPARAM)ti->func_name);
		SendDlgItemMessage(hDlg, IDC_EDIT_CMD_LINE, WM_SETTEXT, 0, (LPARAM)ti->cmd_line);

		set_call_type(hDlg, ti->call_type);
		CheckDlgButton(hDlg, IDC_CHECK_COPY_PATE, ti->copy_paste);
		CheckDlgButton(hDlg, IDC_CHECK_OLD, ti->old);

		i = 0;
		if (ti->modifiers & MOD_SHIFT) {
			i |= HOTKEYF_SHIFT;
		}
		if (ti->modifiers & MOD_CONTROL) {
			i |= HOTKEYF_CONTROL;
		}
		if (ti->modifiers & MOD_ALT) {
			i |= HOTKEYF_ALT;
		}
		if (ti->modifiers & MOD_WIN) {
			i |= HOTKEYF_WIN;
		}
		if (ti->virtkey != 0) {
			SendDlgItemMessage(hDlg, IDC_HOTKEY_TOOL, HKM_SETHOTKEY,
				(WPARAM)MAKEWORD(ti->virtkey, i), 0);
		}
		SendMessage(hDlg, WM_COMMAND, IDC_CHECK_MENU, 0);

		SetWindowLong(hDlg, GWL_USERDATA, lParam);
		break;

	case WM_CLOSE:
		EndDialog(hDlg, FALSE);
		break;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDC_CHECK_MENU:
			EnableWindow(GetDlgItem(hDlg, IDC_CHECK_COPY_PATE), IsDlgButtonChecked(hDlg, IDC_CHECK_MENU));
			EnableWindow(GetDlgItem(hDlg, IDC_HOTKEY_TOOL), IsDlgButtonChecked(hDlg, IDC_CHECK_MENU));
			break;

		case IDC_BUTTON_FILE_SELECT:
			// ファイル選択
			SetFocus(GetDlgItem(hDlg, IDC_EDIT_LIB_PATH));
			if (file_select(hDlg, TEXT("*.dll\0*.dll\0*.*\0*.*\0\0"), 1, buf) == -1) {
				break;
			}
			SendDlgItemMessage(hDlg, IDC_EDIT_LIB_PATH, WM_SETTEXT, 0, (LPARAM)buf);
			SendDlgItemMessage(hDlg, IDC_EDIT_HEADER, WM_SETTEXT, 0, (LPARAM)TEXT(""));

		case IDC_BUTTON_FUNC_SELECT:
			// ツール選択
			*buf = TEXT('\0');
			SendDlgItemMessage(hDlg, IDC_EDIT_LIB_PATH, WM_GETTEXT, BUF_SIZE - 1, (LPARAM)buf);
			if (DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_DIALOG_SELECT_FUNC), hDlg, select_tool_proc, (LPARAM)buf) == TRUE) {
				SendMessage(hDlg, WM_COMMAND, IDC_CHECK_MENU, 0);
			}
			break;

		case IDOK:
			*buf = TEXT('\0');
			SendDlgItemMessage(hDlg, IDC_EDIT_TITLE, WM_GETTEXT, BUF_SIZE - 1, (LPARAM)buf);
			if (*buf == TEXT('\0')) {
				MessageBox(hDlg, message_get_res(IDS_TOOL_ERR_TITLE), WINDOW_TITLE, MB_ICONEXCLAMATION);
				SetFocus(GetDlgItem(hDlg, IDC_EDIT_TITLE));
				break;
			}

			if ((ti = (TOOL_INFO *)GetWindowLong(hDlg, GWL_USERDATA)) == NULL) {
				ti = mem_calloc(sizeof(TOOL_INFO));
			}
			if (ti != NULL) {
				// 設定取得
				alloc_get_text(GetDlgItem(hDlg, IDC_EDIT_TITLE), &ti->title);
				alloc_get_text(GetDlgItem(hDlg, IDC_EDIT_LIB_PATH), &ti->lib_file_path);
				alloc_get_text(GetDlgItem(hDlg, IDC_EDIT_HEADER), &ti->func_name);
				alloc_get_text(GetDlgItem(hDlg, IDC_EDIT_CMD_LINE), &ti->cmd_line);
				
				ti->call_type = 0;
				ti->call_type |= (IsDlgButtonChecked(hDlg, IDC_CHECK_MENU) * CALLTYPE_MENU);
				ti->call_type |= (IsDlgButtonChecked(hDlg, IDC_CHECK_VIEWER) * CALLTYPE_VIEWER);
				ti->call_type |= (IsDlgButtonChecked(hDlg, IDC_CHECK_VIEWER_OPEN) * CALLTYPE_VIEWER_OPEN);
				ti->call_type |= (IsDlgButtonChecked(hDlg, IDC_CHECK_VIEWER_CLOSE) * CALLTYPE_VIEWER_CLOSE);
				ti->call_type |= (IsDlgButtonChecked(hDlg, IDC_CHECK_HISTORY) * CALLTYPE_ADD_HISTORY);
				ti->call_type |= (IsDlgButtonChecked(hDlg, IDC_CHECK_CLIPBOARD) * CALLTYPE_ITEM_TO_CLIPBOARD);
				ti->call_type |= (IsDlgButtonChecked(hDlg, IDC_CHECK_START) * CALLTYPE_START);
				ti->call_type |= (IsDlgButtonChecked(hDlg, IDC_CHECK_END) * CALLTYPE_END);

				ti->copy_paste = IsDlgButtonChecked(hDlg, IDC_CHECK_COPY_PATE);
				ti->old = IsDlgButtonChecked(hDlg, IDC_CHECK_OLD);

				i = SendDlgItemMessage(hDlg, IDC_HOTKEY_TOOL, HKM_GETHOTKEY, 0, 0);
				ti->virtkey = LOBYTE(i);
				i = HIBYTE(i);
				ti->modifiers = ((i & HOTKEYF_SHIFT) ? MOD_SHIFT : 0) |
					((i & HOTKEYF_CONTROL) ? MOD_CONTROL : 0) |
					((i & HOTKEYF_ALT) ? MOD_ALT : 0) |
					((i & HOTKEYF_WIN) ? MOD_WIN : 0);
			}

			if (GetWindowLong(hDlg, GWL_USERDATA) == 0) {
				// 新規
				HWND pWnd = PropSheet_GetCurrentPageHwnd(GetParent(hDlg));
				listview_set_tool(GetDlgItem(pWnd, IDC_LIST_TOOL), ti, FALSE);
			}
			EndDialog(hDlg, TRUE);
			break;

		case IDCANCEL:
			EndDialog(hDlg, FALSE);
			break;
		}
		break;

	default:
		return FALSE;
	}
	return TRUE;
}
Beispiel #29
0
char * filespecrootpath(char *filespec)
{
#if SUN || M_UNIX || M_XENIX || __linux__ || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __sun
#define DIRCHAR '/'
#endif
#if MSDOS || __OS2__ || __NT__ || _WIN32
#define DIRCHAR '\\'
#endif
#ifdef MPW
#define DIRCHAR ':'
#endif

    char *cwd, *cwd_t;
    char *p, *p2;

    if (!filespec)
        return filespec;
#if MSDOS || __OS2__ || __NT__ || _WIN32
    /* if already absolute (with \ or drive:) ... */
    if (*filespec == DIRCHAR || (isalpha((unsigned char)*filespec) && *(filespec+1) == ':'))
        return filespec;        /*      ... return input string */
#else
    if (*filespec == DIRCHAR)   /* already absolute ... */
        return filespec;        /*      ... return input string */
#endif

    /* get current working directory path */
#if SUN || M_UNIX || M_XENIX || __linux__ || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __sun
    cwd_t = (char *)getcwd(NULL, 256);
#endif
#if MSDOS || __OS2__ || __NT__ || _WIN32
    char cwd_d[132];
    if (getcwd(cwd_d, sizeof(cwd_d)))
       cwd_t = cwd_d;
    else
       cwd_t = NULL;
#endif

    if (cwd_t == NULL)
    {
        mem_free(filespec);
        return NULL;    /* error - path too long (more than 256 chars !)*/
    }
    cwd = mem_strdup(cwd_t);    /* convert cwd to mem package */
#if MSDOS
    assert(strlen(cwd) > 0);
    if (cwd[strlen(cwd) - 1] == DIRCHAR)
        cwd[strlen(cwd) - 1] = '\0';
#endif
#if SUN || M_UNIX || M_XENIX || __linux__ || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __sun
    free(cwd_t);
#endif
    p = filespec;
    while (p != NULL)
    {
        p2 = (char *)strchr(p, DIRCHAR);
        if (p2 != NULL)
        {
            *p2 = '\0';
            if (strcmp(p, "..") == 0)   /* move up cwd */
                /* remove last directory from cwd */
                *((char *)strrchr(cwd, DIRCHAR)) = '\0';
            else if (strcmp(p, ".") != 0) /* not current directory */
            {
                cwd_t = cwd;
                cwd = (char *)mem_calloc(strlen(cwd_t) + 1 + strlen(p) + 1);
#if SUN || M_UNIX || M_XENIX || __linux__ || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __sun
                sprintf(cwd, "%s/%s", cwd_t, p);  /* add relative directory */
#endif
#if MSDOS || __OS2__ || __NT__ || _WIN32
                sprintf(cwd, "%s\\%s", cwd_t, p);  /* add relative directory */
#endif
                mem_free(cwd_t);
            }
            /* else if ".", then ignore - it means current directory */
            *p2 = DIRCHAR;
            p2++;
        }
        else if (strcmp(p,"..") == 0)   /* move up cwd */
        {
            /* remove last directory from cwd */
            *((char *)strrchr(cwd, DIRCHAR)) = '\0';
        }
        else if (strcmp(p,".") != 0) /* no more subdirectories ... */
        {   /* ... save remaining string */
            cwd_t = cwd;
            cwd = (char *)mem_calloc(strlen(cwd_t) + 1 + strlen(p) + 1);
#if SUN || M_UNIX || M_XENIX || __linux__ || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __sun
            sprintf(cwd, "%s/%s", cwd_t, p);  /* add relative directory */
#endif
#if MSDOS || __OS2__ || __NT__ || _WIN32
            sprintf(cwd, "%s\\%s", cwd_t, p);  /* add relative directory */
#endif
            mem_free(cwd_t);
        }
        p = p2;
    }
    mem_free(filespec);

    return cwd;
#ifdef VMS
    assert(0);
#endif
}
Beispiel #30
0
char * my_strdup(const char * s) {
	char *buf = mem_calloc(strlen(s) + 1, sizeof(char));
	if (buf != NULL)
		strcpy(buf, s);
	return buf;
}