コード例 #1
0
ファイル: hasp_vm_demo_md5.c プロジェクト: SlavaC1/ControlSW
int main(void)
{
   hasp_status_t   status;
   hasp_handle_t   handle;
   hasp_u32_t      vm_returncode = 0;
   hasp_size_t     iolength = 0;
   unsigned char   iobuffer[256] = { 0 };
   char            md5ResultBuffer[64] ={ 0 };
   VM_IO_BUFFER_T  iobuffer_cxt = { 0 }; 
   char *  szmd5str = "this is md5 test";
   const char* scope = 
                        "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
                        "<haspscope>"
                        "    <hasp type=\"HASP-HL\" >"
                        "        <license_manager hostname=\"localhost\" />"
                        "    </hasp>"
                        "</haspscope>";
						

   printf("A simple demo program for the Sentinel LDK licensing functions\n");
   printf("Copyright (C) SafeNet, Inc. All rights reserved.\n\n");
   /*
   Access Direct Mode (-4 mode) [TEST-ONLY]
   This mode force the API to always access directly DriverLess keys even if the local LM is recent enough to provide such support.
   To enable this special mode, you must use the undocumented call hasp_login(-4, 0, 0) before any other hasp functions. 
   */
   hasp_login(-4, 0, 0);

   /************************************************************************
   * hasp_login_scope
   *   establishes a context for HASP services
   *   allows specification of several restrictions
   */

   printf("restricting the license to 'local':\n");

   status = hasp_login_scope(HASP_DEFAULT_FID,
                    scope,
                    (hasp_vendor_code_t *)vendor_code,
                    &handle);
   switch (status)
   {
   case HASP_STATUS_OK:
      printf("OK\n");
      break;

   case HASP_FEATURE_NOT_FOUND:
      printf("login to default feature failed\n");
      break;

   case HASP_CONTAINER_NOT_FOUND:
      printf("no sentinel key with vendor code DEMOMA found\n");
      break;

   case HASP_OLD_DRIVER:
      printf("outdated driver version installed\n");
      break;

   case HASP_NO_DRIVER:
      printf("sentinel driver not installed\n");
      break;

   case HASP_INV_VCODE:
      printf("invalid vendor code\n");
      break;

   case HASP_INV_SCOPE:
      printf("invalid XML scope\n");
      break;

   default:
      printf("login to default feature failed with status %d\n", status);
   }
   if (status) {
      exit(-1);
   }


   /************************************************************************
   * Initlialize vm engine 
   */
   //md5 test
   status = hasp_vm_init(handle, VM_RESOURCE_ID);
   if (status) {
      hasp_logout(handle);
      printf("hasp_vm_init failed: %d!\n", status);
      exit(-1);
   }
   else
   {
      printf("hasp_vm_init succeeded!\n");
   }       

   /************************************************************************
   /* Prepare input buffer and to invoke the method of vm resource */
   iobuffer_cxt.cmdBuff = iobuffer;
   iobuffer_cxt.rspBuff = iobuffer;

   put_byte_array(&iobuffer_cxt, szmd5str, strlen(szmd5str));
   put_byte_array(&iobuffer_cxt, md5ResultBuffer, 16);

   iolength = iobuffer_cxt.cmdSize;

   printf("public static void MD5Hash( String p1, byte[] p2 )\n");
   status = hasp_vm_invoke(handle,
      VM_METHOD_ID,//method id      
      iobuffer, 
      &iolength,
      &vm_returncode);
   if (status) {
      hasp_logout(handle);
      printf("hasp_vm_invoke failed: %d!\n", status);
      exit(-1);
   }
   else
   {
      printf("hasp_vm_invoke succeeded!\n");
   }

   get_byte_array(&iobuffer_cxt, md5ResultBuffer, 16);

   dump(md5ResultBuffer, 16, "    ");
   
   /************************************************************************
   /* hasp_vm_close must be called to free vm engine for other processes or threads usage*/
   status = hasp_vm_close(handle);
   if (status) {
      hasp_logout(handle);
      printf("hasp_vm_close failed: %d!\n", status);
      exit(-1);
   }
   else
   {
      printf("hasp_vm_close succeeded!\n");
   }

   /************************************************************************
   * hasp_logout
   *   closes established session and releases allocated memory
   */
   printf("\nlogout                           : ");
   status = hasp_logout(handle);

   switch (status)
   {
   case HASP_STATUS_OK:
      printf("OK\n");
      break;

   case HASP_INV_HND:
      printf("failed: handle not active\n");
      break;

   default:
      printf("failed\n");
   }
   if (status) {
      exit(-1);
   }

   /***********************************************************************/

   wait4key("to close the sample");

   return 0;

} /* main */
コード例 #2
0
ファイル: yaku.c プロジェクト: CecilHarvey/netmaj
void
ui_result (global_t * gp)
{
  int p, i;
  int iy[4];
  char buf[1024];
  int n = 0;

  if (flag_pause && !auto_play && !BUILD4)
    {
      wait4key ();
    }
  if (!point)
    make_point ();
  if (BUILD4)
    wrap_widgets ();

  snd (audioplay_yaku ());
  flag_not_needredraw = 0;
  point_clear ();

  memcpy (hora_global, gp, sizeof (global_t));
  hora_reset ();

  for (p = 0; p < 4; p++)
    {
      if (result[p].flag == 0)
        {
          continue;
        }
      n++;
    }
  for (p = 0; p < 4; p++)
    {
      if (result[p].flag == 0)
        {
          continue;
        }

      if (result[p].flag != RESULT_RYUKYOKU && (result[p].who != -1))
        {
          hora_set (hora_global, result[p].who);
        }
      else
        {
          hora_set (hora_global, -1);
        }

      result_cvt_to_int (result + p, iy);
      pmcontainer_print (point_results, pm_result_name[result[p].flag]);

      for (i = 0; i < 4; i++)
        {
          integer_t color;
          pmcontainer_print (point_home[i], pm_home_names[i]);
          print_yakupoint (point_home_point[i], result[p].points[i]);

          widget_configure (point_home_user[i], resource_text,
                            player[pplayer[i]].name);
          color = point_color (result[p].points[i]);
          widget_configure (point_home_user[i], resource_textfont, MEDIUMJP);
          widget_configure (point_home_user[i], resource_textcolor, color);
          {
            extern integer_t *tblpos;
            color = point_bgcolor (result[p].points[i]);
            widget_model_change (name_frame[tblpos[i]], color, white, white,
                                 white);
          }
        }

      if (result[p].fu)
        {
          widget_configure (point_fubase, resource_invisible, 0);
          print_yakupoint (point_fu, result[p].fu);
          print_yakupoint (point_fan, result[p].fan);
        }
      else
        {
          widget_configure (point_fubase, resource_invisible, 1);
        }

#define yaku_idx(idx)  		\
		if (!point_yaku[idx]) { goto YAKUEND; }

      {
        integer_t idx = 0;
        for (i = 0; i < Y_MAX; i++)
          {
            if (Y_GET (iy, i))
              {
                char buf[128];
                int len, n;

                yaku_idx (idx);

                strcpy (buf, result_str[i]);
                len = strlen (buf);

                if (buf[len - 1] == ')' && buf[len - 3] == '(')
                  {
                    buf[len - 3] = buf[len - 1] = 0;
                    n = buf[len - 2] - '0';
                    print_yakupoint (point_yaku_point[idx], n);
                  }
                else
                  {
                    widget_configure (point_yaku_point[idx], resource_text,
                                      "");
                  }
                widget_configure (point_yaku[idx], resource_text, buf);
                idx++;
              }
          }

        if (result[p].dora)
          {
            yaku_idx (idx);
            widget_configure (point_yaku[idx], resource_text, dora_str);
            print_yakupoint (point_yaku_point[idx], result[p].dora);
            idx++;
          }
        if (result[p].uradora)
          {
            yaku_idx (idx);
            widget_configure (point_yaku[idx], resource_text, uradora_str);
            print_yakupoint (point_yaku_point[idx], result[p].uradora);
            idx++;
          }
        if (result[p].akadora)
          {
            yaku_idx (idx);
            widget_configure (point_yaku[idx], resource_text, akadora_str);
            print_yakupoint (point_yaku_point[idx], result[p].akadora);
            idx++;
          }
        for (; idx < 30; idx++)
          {
            if (!point_yaku[idx])
              {
                continue;
              }
            widget_configure (point_yaku[idx], resource_text, "");
            widget_configure (point_yaku_point[idx], resource_text, "");
          }
      }
    YAKUEND:
      draw_hora ();
      {
        extern widget_t board;
        if (!BUILD4)
          {
            widget_unmap (board);
          }
        widget_map (point);
        widget_display (point);
        widget_flush (point);
        {
          for (i = 0; i < 4; i++)
            {
              widget_display (name_frame[i]);
              widget_flush (name_frame[i]);
            }
        }

        if (!auto_play)
          wait_key ();

        hora_reset ();
      }
    }

  linepos_clear ();
  for (i = 0; i < 4; i++)
    {
      widget_model_change (name_frame[i], get_basiccolorpixel (), white,
                           white, white);
    }
  if (!BUILD4)
    {
      widget_unmap (point);
    }
  else
    {
      unwrap_widgets ();
    }
  board_reset ();
  board_redraw (1);

  if (logfile)
    log_play (gp, logfile);
}