Exemplo n.º 1
0
/* send the initial data to a basic authenticator module */
static void
authenticateBasicStart(auth_user_request_t * auth_user_request, RH * handler, void *data)
{
    authenticateStateData *r = NULL;
    char buf[8192];
    char user[1024], pass[1024];
    basic_data *basic_auth;
    assert(auth_user_request);
    assert(handler);
    assert(auth_user_request->auth_user->auth_type == AUTH_BASIC);
    assert(auth_user_request->auth_user->scheme_data != NULL);
    basic_auth = auth_user_request->auth_user->scheme_data;
    debug(29, 9) ("authenticateStart: '%s:%s'\n", basic_auth->username,
	basic_auth->passwd);
    if (basicConfig->authenticate == NULL) {
	handler(data, NULL);
	return;
    }
    /* check to see if the auth_user already has a request outstanding */
    if (basic_auth->flags.credentials_ok == 2) {
	/* there is a request with the same credentials already being verified */
	auth_basic_queue_node *node;
	node = xmalloc(sizeof(auth_basic_queue_node));
	assert(node);
	/* save the details */
	node->next = basic_auth->auth_queue;
	basic_auth->auth_queue = node;
	node->handler = handler;
	node->data = data;
	cbdataLock(data);
	return;
    } else {
	r = cbdataAlloc(authenticateStateData);
	r->handler = handler;
	cbdataLock(data);
	r->data = data;
	r->auth_user_request = auth_user_request;
	authenticateAuthUserRequestLock(r->auth_user_request);
	/* mark the user as haveing verification in progress */
	basic_auth->flags.credentials_ok = 2;
	if (basicConfig->utf8) {
	    latin1_to_utf8(user, sizeof(user), basic_auth->username);
	    latin1_to_utf8(pass, sizeof(pass), basic_auth->passwd);
	    xstrncpy(user, rfc1738_escape(user), sizeof(user));
	    xstrncpy(pass, rfc1738_escape(pass), sizeof(pass));
	} else {
	    xstrncpy(user, rfc1738_escape(basic_auth->username), sizeof(user));
	    xstrncpy(pass, rfc1738_escape(basic_auth->passwd), sizeof(pass));
	}
	snprintf(buf, sizeof(buf), "%s %s\n", user, pass);
	helperSubmit(basicauthenticators, buf, authenticateBasicHandleReply, r);
    }
}
Exemplo n.º 2
0
char* erl_atom_ptr_utf8(Erl_Atom_data* a)
{
    if (a->utf8 == NULL) {
        erlang_char_encoding enc;
        a->lenU = latin1_to_utf8(NULL, a->latin1, a->lenL, a->lenL*2, &enc);
        if (enc == ERLANG_ASCII) {
            a->utf8 = a->latin1;
        }
        else {
            a->utf8 = malloc(a->lenU + 1);
            latin1_to_utf8(a->utf8, a->latin1, a->lenL, a->lenU, NULL);
            a->utf8[a->lenU] = '\0';
        }
    }
    return a->utf8;
}
Exemplo n.º 3
0
void
_wnck_get_wmclass (Window xwindow,
                   char **res_class,
                   char **res_name)
{
  XClassHint ch;
  char UNUSED_VARIABLE *retval;
  
  _wnck_error_trap_push ();

  ch.res_name = NULL;
  ch.res_class = NULL;

  XGetClassHint (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
                 xwindow,
                 &ch);

  _wnck_error_trap_pop ();
  
  retval = NULL;

  if (res_class)
    *res_class = NULL;

  if (res_name)
    *res_name = NULL;
  
  if (ch.res_name)
    {
      if (res_name)
        *res_name = latin1_to_utf8 (ch.res_name);
      
      XFree (ch.res_name);
    }

  if (ch.res_class)
    {
      if (res_class)
        *res_class = latin1_to_utf8 (ch.res_class);
      
      XFree (ch.res_class);
    }
}
Exemplo n.º 4
0
char* erl_atom_ptr_utf8(Erl_Atom_data* a)
{
    if (a->utf8 == NULL) {
	int dlen = a->lenL * 2; /* over estimation */
	a->utf8 = malloc(dlen + 1); 
	a->lenU = latin1_to_utf8(a->utf8, a->latin1, a->lenL, dlen, NULL);
	a->utf8[a->lenU] = '\0';
    }
    return a->utf8;

}
Exemplo n.º 5
0
/* derived from libwnck/xutils.c, comes as LGPLv2+ */
static void
_get_wmclass (Display *xdisplay,
              Window   xwindow,
              char   **res_class,
              char   **res_name)
{
  XClassHint ch;

  ch.res_name = NULL;
  ch.res_class = NULL;

  gdk_error_trap_push ();
  XGetClassHint (xdisplay, xwindow, &ch);
#if GTK_CHECK_VERSION (3, 0, 0)
  gdk_error_trap_pop_ignored ();
#else
  gdk_error_trap_pop ();
#endif

  if (res_class)
    *res_class = NULL;

  if (res_name)
    *res_name = NULL;

  if (ch.res_name)
    {
      if (res_name)
        *res_name = latin1_to_utf8 (ch.res_name);

      XFree (ch.res_name);
    }

  if (ch.res_class)
    {
      if (res_class)
        *res_class = latin1_to_utf8 (ch.res_class);

      XFree (ch.res_class);
    }
}
Exemplo n.º 6
0
/* derived from libwnck/xutils.c, comes as LGPLv2+ */
static void
_get_wmclass (Display *xdisplay,
              Window   xwindow,
              char   **res_class,
              char   **res_name)
{
  XClassHint ch;

  ch.res_name = NULL;
  ch.res_class = NULL;

  gdk_error_trap_push ();
  XGetClassHint (xdisplay, xwindow, &ch);
  gdk_error_trap_pop ();

  if (res_class)
    *res_class = NULL;

  if (res_name)
    *res_name = NULL;

  if (ch.res_name)
    {
      if (res_name)
        *res_name = latin1_to_utf8 (ch.res_name);

      XFree (ch.res_name);
    }

  if (ch.res_class)
    {
      if (res_class)
        *res_class = latin1_to_utf8 (ch.res_class);

      XFree (ch.res_class);
    }
}
Exemplo n.º 7
0
/* derived from libwnck/xutils.c, comes as LGPLv2+ */
void get_wmclass (GdkWindow* xwindow, char **res_class, char **res_name)
{
    XClassHint ch;

    ch.res_name = NULL;
    ch.res_class = NULL;

    gdk_error_trap_push ();
    XGetClassHint(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()),
                  GDK_WINDOW_XID(xwindow), &ch);
    gdk_error_trap_pop_ignored ();

    if (res_class) {
        *res_class = NULL;
    }

    if (res_name) {
        *res_name = NULL;
    }

    if (ch.res_name) {
        if (res_name) {
            *res_name = latin1_to_utf8 (ch.res_name);
        }

        XFree (ch.res_name);
    }

    if (ch.res_class) {
        if (res_class) {
            *res_class = latin1_to_utf8 (ch.res_class);
        }

        XFree (ch.res_class);
    }
}
Exemplo n.º 8
0
char *
sound_hash(const char *str, int len, enum sound_hash_type type)
{
  sqlite3 *sqldb = get_shared_db();
  sqlite3_stmt *hasher;
  char *utf8, *result = NULL;
  int ulen;
  int status;

  switch (type) {
  case HASH_SOUNDEX:
    /* Classic Penn soundex turns a leading ph into f. This makes
       sense but isn't typical. */
    hasher = prepare_statement(sqldb,
                               "VALUES (soundex(CASE WHEN ?1 LIKE 'ph%' THEN "
                               "printf('f%s', substr(?1, 3)) ELSE ?1 END))",
                               "hash.soundex");
    break;
  case HASH_PHONE:
    hasher =
      prepare_statement(sqldb, "VALUES (spellfix1_phonehash(?))", "hash.phone");
    break;
  default:
    return NULL;
  }

  utf8 = latin1_to_utf8(str, len, &ulen, "string");
  sqlite3_bind_text(hasher, 1, utf8, ulen, free_string);
  status = sqlite3_step(hasher);
  if (status == SQLITE_ROW) {
    result =
      mush_strdup((const char *) sqlite3_column_text(hasher, 0), "string");
  }
  sqlite3_reset(hasher);
  return result;
}
Exemplo n.º 9
0
void UI_NK2EDFwindow::SelectFileButton()
{
  FILE *inputfile=NULL,
       *outputfile=NULL,
       *logfile=NULL,
       *pntfile=NULL;

  int i, j, k,
      error,
      ctl_block_cnt,
      datablock_cnt,
      total_blocks,
      edfplus,
      n_logs=0,
      n_sublogs=0,
      total_logs=0,
      n_logblocks=0,
      ctlblock_address,
      wfmblock_address,
      logblock_address,
      read_subevents=0;

  char txt_string[2048],
       path[MAX_PATH_LENGTH],
       outputpath[MAX_PATH_LENGTH],
       logfilepath[MAX_PATH_LENGTH],
       pntfilepath[MAX_PATH_LENGTH],
       *log_buf=NULL,
       *sublog_buf=NULL,
       scratchpad[256];


  pushButton1->setEnabled(false);

  edfplus = checkBox1->checkState();

  total_elapsed_time = 0;

  strcpy(path, QFileDialog::getOpenFileName(0, "Select inputfile", QString::fromLocal8Bit(recent_opendir), "EEG files (*.eeg *.EEG)").toLocal8Bit().data());

  if(!strcmp(path, ""))
  {
    pushButton1->setEnabled(true);
    return;
  }

  get_directory_from_path(recent_opendir, path, MAX_PATH_LENGTH);

  inputfile = fopeno(path, "rb");
  if(inputfile==NULL)
  {
    snprintf(txt_string, 2048, "can not open file %s for reading.\n", path);
    textEdit1->append(QString::fromLocal8Bit(txt_string));
    pushButton1->setEnabled(true);
    return;
  }

/***************** check if the EEG file is valid ******************************/

  rewind(inputfile);
  if(fread(scratchpad, 16, 1, inputfile)!=1)
  {
    textEdit1->append("error reading .eeg file.\n");
    fclose(inputfile);
    pushButton1->setEnabled(true);
    return;
  }
  scratchpad[16] = 0;
  if(check_device(scratchpad))
  {
    snprintf(txt_string, 2048, "error, deviceblock has unknown signature: \"%s\"\n", scratchpad);
    textEdit1->append(txt_string);
    fclose(inputfile);
    pushButton1->setEnabled(true);
    return;
  }
  fseeko(inputfile, 0x0081LL, SEEK_SET);
  if(fread(scratchpad, 16, 1, inputfile)!=1)
  {
    textEdit1->append("error reading .eeg file.\n");
    fclose(inputfile);
    pushButton1->setEnabled(true);
    return;
  }
  scratchpad[16] = 0;
  if(check_device(scratchpad))
  {
    snprintf(txt_string, 2048, "error, controlblock has unknown signature: \"%s\"\n", scratchpad);
    textEdit1->append(txt_string);
    fclose(inputfile);
    pushButton1->setEnabled(true);
    return;
  }
  fseeko(inputfile, 0x17feLL, SEEK_SET);
  if(fgetc(inputfile)!=0x01)
  {
    snprintf(txt_string, 2048, "error, waveformdatablock has wrong signature.\n");
    textEdit1->append(txt_string);
    fclose(inputfile);
    pushButton1->setEnabled(true);
    return;
  }

/************************* read logs **********************************************/

  if(edfplus)
  {
    strncpy(logfilepath, path, MAX_PATH_LENGTH);
    remove_extension_from_filename(logfilepath);
    strcat(logfilepath, ".LOG");
    logfile = fopeno(logfilepath, "rb");
    if(logfile==NULL)
    {
      remove_extension_from_filename(logfilepath);
      strcat(logfilepath, ".log");
      logfile = fopeno(logfilepath, "rb");
      if(logfile==NULL)
      {
        snprintf(txt_string, 2048, "Can not open file %s for reading,\n"
                            "if there is no .log file you can try to create an EDF file instead of EDF+.\n",
                            logfilepath);
        textEdit1->append(QString::fromLocal8Bit(txt_string));
        fclose(inputfile);
        pushButton1->setEnabled(true);
        return;
      }
    }

    rewind(logfile);
    if(fread(scratchpad, 16, 1, logfile)!=1)
    {
      textEdit1->append("error reading .log file.\n");
      fclose(logfile);
      fclose(inputfile);
      pushButton1->setEnabled(true);
      return;
    }
    scratchpad[16] = 0;
    if(check_device(scratchpad))
    {
      snprintf(txt_string, 2048, "error, .log file has unknown signature: \"%s\"\n", scratchpad);
      textEdit1->append(QString::fromLocal8Bit(txt_string));
      fclose(logfile);
      fclose(inputfile);
      pushButton1->setEnabled(true);
      return;
    }

    fseeko(logfile, 0x0091LL, SEEK_SET);
    n_logblocks = fgetc(logfile);
    log_buf = (char *)calloc(1, n_logblocks * 11521);
    if(log_buf==NULL)
    {
      textEdit1->append("malloc error\n");
      fclose(logfile);
      fclose(inputfile);
      pushButton1->setEnabled(true);
      return;
    }
    sublog_buf = (char *)calloc(1, n_logblocks * 11521);
    if(sublog_buf==NULL)
    {
      textEdit1->append("malloc error\n");
      fclose(logfile);
      fclose(inputfile);
      free(log_buf);
      pushButton1->setEnabled(true);
      return;
    }

    read_subevents = 1;

    total_logs = 0;

    for(i=0; i<n_logblocks; i++)
    {
      fseeko(logfile, (long long)(0x0092 + (i * 20)), SEEK_SET);
      if(fread((char *)(&logblock_address), 4, 1, logfile)!=1)
      {
        textEdit1->append("error reading .log file.\n");
        fclose(inputfile);
        fclose(logfile);
        free(log_buf);
        free(sublog_buf);
        pushButton1->setEnabled(true);
        return;
      }
      fseeko(logfile, (long long)(logblock_address + 0x0012), SEEK_SET);
      n_logs = fgetc(logfile);
      fseeko(logfile, (long long)(logblock_address + 0x0014), SEEK_SET);
      if(fread(log_buf + (total_logs * 45), n_logs * 45, 1, logfile)!=1)
      {
        textEdit1->append("error reading .log file.\n");
        fclose(inputfile);
        fclose(logfile);
        free(log_buf);
        free(sublog_buf);
        pushButton1->setEnabled(true);
        return;
      }

      if(read_subevents)
      {
        if(fseeko(logfile, 0x0092LL + ((i + 22) * 20) , SEEK_SET))
        {
          read_subevents = 0;
        }
        else
        {
          if(fread((char *)(&logblock_address), 4, 1, logfile)!=1)
          {
            read_subevents = 0;
          }
          else
          {
            if(fseeko(logfile, logblock_address + 0x0012LL, SEEK_SET))
            {
              read_subevents = 0;
            }
            else
            {
              n_sublogs = fgetc(logfile);
              if(n_sublogs != n_logs)
              {
                read_subevents = 0;
              }
              else
              {
                if(fseeko(logfile, logblock_address + 0x0014LL, SEEK_SET))
                {
                  read_subevents = 0;
                }
                else
                {
                  if(fread(sublog_buf + (total_logs * 45), n_sublogs * 45, 1, logfile)!=1)
                  {
                    read_subevents = 0;
                  }
                }
              }
            }
          }
        }
      }

      total_logs += n_logs;
    }

    for(i=0; i<total_logs; i++)
    {
      for(j=0; j<20; j++)
      {
        if(((unsigned char *)log_buf)[(i * 45) + j]<32)  log_buf[(i * 45) + j] = ' ';
      }

      latin1_to_utf8(log_buf + (i * 45), 20);

      if(read_subevents)
      {
        strncpy(log_buf + (i * 45) + 26, sublog_buf + (i * 45) + 24, 6);
      }
    }

/************************* check pntfile **********************************************/

    strncpy(pntfilepath, path, MAX_PATH_LENGTH);
    remove_extension_from_filename(logfilepath);
    strcat(logfilepath, ".PNT");
    pntfile = fopeno(pntfilepath, "rb");
    if(pntfile==NULL)
    {
      remove_extension_from_filename(logfilepath);
      strcat(logfilepath, ".pnt");
      pntfile = fopeno(pntfilepath, "rb");
      if(pntfile==NULL)
      {
        snprintf(txt_string, 2048, "Can not open file %s for reading,\n"
                            "if there is no .pnt file you can try to create an EDF file instead of EDF+.\n",
                            pntfilepath);
        textEdit1->append(QString::fromLocal8Bit(txt_string));
        fclose(logfile);
        fclose(inputfile);
        free(log_buf);
        free(sublog_buf);
        pushButton1->setEnabled(true);
        return;
      }
    }

    rewind(pntfile);
    if(fread(scratchpad, 16, 1, pntfile)!=1)
    {
      textEdit1->append("error reading .pnt file.\n");
      fclose(pntfile);
      fclose(logfile);
      fclose(inputfile);
      free(log_buf);
      free(sublog_buf);
      pushButton1->setEnabled(true);
      return;
    }
    scratchpad[16] = 0;
    if(check_device(scratchpad))
    {
      snprintf(txt_string, 2048, "error, .pnt file has unknown signature: \"%s\"\n", scratchpad);
      textEdit1->append(QString::fromLocal8Bit(txt_string));
      fclose(pntfile);
      fclose(logfile);
      fclose(inputfile);
      free(log_buf);
      free(sublog_buf);
      pushButton1->setEnabled(true);
      return;
    }
  }

/***************** initialize labels **************************************/

  for(i=0; i<256; i++)
  {
    strcpy(labels[i], "-               ");
  }

  strcpy(labels[0],   "EEG FP1         ");
  strcpy(labels[1],   "EEG FP2         ");
  strcpy(labels[2],   "EEG F3          ");
  strcpy(labels[3],   "EEG F4          ");
  strcpy(labels[4],   "EEG C3          ");
  strcpy(labels[5],   "EEG C4          ");
  strcpy(labels[6],   "EEG P3          ");
  strcpy(labels[7],   "EEG P4          ");
  strcpy(labels[8],   "EEG O1          ");
  strcpy(labels[9],   "EEG O2          ");
  strcpy(labels[10],  "EEG F7          ");
  strcpy(labels[11],  "EEG F8          ");
  strcpy(labels[12],  "EEG T3          ");
  strcpy(labels[13],  "EEG T4          ");
  strcpy(labels[14],  "EEG T5          ");
  strcpy(labels[15],  "EEG T6          ");
  strcpy(labels[16],  "EEG FZ          ");
  strcpy(labels[17],  "EEG CZ          ");
  strcpy(labels[18],  "EEG PZ          ");
  strcpy(labels[19],  "EEG E           ");
  strcpy(labels[20],  "EEG PG1         ");
  strcpy(labels[21],  "EEG PG2         ");
  strcpy(labels[22],  "EEG A1          ");
  strcpy(labels[23],  "EEG A2          ");
  strcpy(labels[24],  "EEG T1          ");
  strcpy(labels[25],  "EEG T2          ");
  for(i=26; i<35; i++)
  {
    sprintf(labels[i], "EEG X%i          ", i - 25);
  }
  strcpy(labels[35],  "EEG X10         ");
  strcpy(labels[36],  "EEG X11         ");
  for(i=42; i<74; i++)
  {
    sprintf(labels[i], "DC%02i            ", i - 41);
  }
  strcpy(labels[74],  "EEG BN1         ");
  strcpy(labels[75],  "EEG BN2         ");
  strcpy(labels[76],  "EEG Mark1       ");
  strcpy(labels[77],  "EEG Mark2       ");
  strcpy(labels[100], "EEG X12/BP1     ");
  strcpy(labels[101], "EEG X13/BP2     ");
  strcpy(labels[102], "EEG X14/BP3     ");
  strcpy(labels[103], "EEG X15/BP4     ");
  for(i=104; i<188; i++)
  {
    sprintf(labels[i], "EEG X%i         ", i - 88);
  }
  for(i=188; i<254; i++)
  {
    sprintf(labels[i], "EEG X%i        ", i - 88);
  }
  strcpy(labels[255], "Z               ");

  if(read_21e_file(path))
  {
    textEdit1->append("Can not open *.21e file, converter will use default electrode names.");
  }

/***************** start conversion **************************************/

  total_blocks = 0;

  fseeko(inputfile, 0x0091LL, SEEK_SET);
  ctl_block_cnt = fgetc(inputfile);
  if(ctl_block_cnt==EOF)
  {
    textEdit1->append("error reading inputfile.\n");
    pushButton1->setEnabled(true);
    fclose(inputfile);
    if(edfplus)
    {
      fclose(logfile);
      free(log_buf);
      free(sublog_buf);
      fclose(pntfile);
    }
    return;
  }

  for(i=0; i<ctl_block_cnt; i++)
  {
    fseeko(inputfile, (long long)(0x0092 + (i * 20)), SEEK_SET);
    if(fread((char *)(&ctlblock_address), 4, 1, inputfile)!=1)
    {
      textEdit1->append("error reading inputfile.\n");
      pushButton1->setEnabled(true);
      fclose(inputfile);
      if(edfplus)
      {
        fclose(logfile);
        free(log_buf);
        free(sublog_buf);
        fclose(pntfile);
      }
      return;
    }
    fseeko(inputfile, (long long)(ctlblock_address + 17), SEEK_SET);
    datablock_cnt = fgetc(inputfile);
    if(datablock_cnt==EOF)
    {
      textEdit1->append("error reading inputfile.\n");
      pushButton1->setEnabled(true);
      fclose(inputfile);
      if(edfplus)
      {
        fclose(logfile);
        free(log_buf);
        free(sublog_buf);
        fclose(pntfile);
      }
      return;
    }

    for(j=0; j<datablock_cnt; j++)
    {
      fseeko(inputfile, (long long)(ctlblock_address + (j * 20) + 18), SEEK_SET);
      if(fread((char *)(&wfmblock_address), 4, 1, inputfile)!=1)
      {
        textEdit1->append("error reading inputfile.\n");
        pushButton1->setEnabled(true);
        fclose(inputfile);
        if(edfplus)
        {
          fclose(logfile);
          free(log_buf);
          free(sublog_buf);
          fclose(pntfile);
        }
        return;
      }

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

      strcpy(outputpath, path);
      if(edfplus)  sprintf(outputpath + strlen(path) - 4, "_%u-%u+.edf", i + 1, j + 1);
      else  sprintf(outputpath + strlen(path) - 4, "_%u-%u.edf", i + 1, j + 1);

      outputfile = fopeno(outputpath, "wb");
      if(outputfile==NULL)
      {
        snprintf(txt_string, 2048, "can not open file %s for writing.\n", outputpath);
        textEdit1->append(QString::fromLocal8Bit(txt_string));
        pushButton1->setEnabled(true);
        fclose(inputfile);
        if(edfplus)
        {
          fclose(logfile);
          free(log_buf);
          free(sublog_buf);
          fclose(pntfile);
        }
        return;
      }

      textEdit1->append("Converting a waveform datablock...");

      for(k=0; k<10; k++)  qApp->processEvents();

      error = convert_nk2edf(inputfile, outputfile, pntfile, wfmblock_address, edfplus, total_logs, log_buf, read_subevents);
      if(error==0)
      {
        snprintf(txt_string, 2048, "to %s", outputpath);
        textEdit1->append(txt_string);
      }
      if(error==1)  textEdit1->append("malloc error.\n");
      if(error==2)  textEdit1->append("read error during conversion.\n");
      if(error==3)  textEdit1->append("write error during conversion.\n");
      if(error==4)  textEdit1->append("format error.\n");

      if(fclose(outputfile))
      {
        textEdit1->append("error closing outputfile.\n");
        pushButton1->setEnabled(true);
        fclose(inputfile);
        if(edfplus)
        {
          fclose(logfile);
          fclose(pntfile);
          free(log_buf);
          free(sublog_buf);
        }
        return;
      }

      if(error)
      {
        if(edfplus)
        {
          fclose(logfile);
          fclose(pntfile);
          free(log_buf);
          free(sublog_buf);
        }
        pushButton1->setEnabled(true);
        return;
      }

      total_blocks++;

      /**************************************************************/
    }
  }

  if(fclose(inputfile))  textEdit1->append("error closing inputfile.\n");
  if(edfplus)
  {
    if(fclose(logfile))  textEdit1->append("error closing .log file.\n");
    if(fclose(pntfile))  textEdit1->append("error closing .pnt file.\n");
    free(log_buf);
    free(sublog_buf);
  }

  if(edfplus)  snprintf(txt_string, 2048, "Converted %u waveformblock(s) successfully to EDF+.\n", total_blocks);
  else  snprintf(txt_string, 2048, "Converted %u waveformblock(s) successfully to EDF.\n", total_blocks);
  textEdit1->append(txt_string);

  pushButton1->setEnabled(true);
}
Exemplo n.º 10
0
/* Make a best effort to convert a X.509 name to a UTF-8 encoded
 * string and return it.  If we can't properly convert just do a
 * fuzzy conversion so we have something to display. */
static const char *
x509name_to_utf8_string(const x509_name *name, apr_pool_t *result_pool)
{
  const svn_string_t *src_string;
  const svn_string_t *utf8_string;
  svn_error_t *err;

  src_string = svn_string_ncreate((const char *)name->val.p,
                                  name->val.len,
                                  result_pool);
  switch (name->val.tag)
    {
    case ASN1_UTF8_STRING:
      if (svn_utf__is_valid(src_string->data, src_string->len))
        return nul_escape(src_string, result_pool);
      else
        /* not a valid UTF-8 string, who knows what it is,
         * so run it through the fuzzy_escape code.  */
        return fuzzy_escape(src_string, result_pool);
      break;

      /* Both BMP and UNIVERSAL should always be in Big Endian (aka
       * network byte order).  But rumor has it that there are certs
       * out there with other endianess and even Byte Order Marks.
       * If we actually run into these, we might need to do something
       * about it. */

    case ASN1_BMP_STRING:
      if (0 != src_string->len % sizeof(apr_uint16_t))
          return fuzzy_escape(src_string, result_pool);
      err = svn_utf__utf16_to_utf8(&utf8_string,
                                   (const void*)(src_string->data),
                                   src_string->len / sizeof(apr_uint16_t),
                                   TRUE, result_pool, result_pool);
      break;

    case ASN1_UNIVERSAL_STRING:
      if (0 != src_string->len % sizeof(apr_int32_t))
          return fuzzy_escape(src_string, result_pool);
      err = svn_utf__utf32_to_utf8(&utf8_string,
                                   (const void*)(src_string->data),
                                   src_string->len / sizeof(apr_int32_t),
                                   TRUE, result_pool, result_pool);
      break;

      /* Despite what all the IETF, ISO, ITU bits say everything out
       * on the Internet that I can find treats this as ISO-8859-1.
       * Even the name is misleading, it's not actually T.61.  All the
       * gory details can be found in the Character Sets section of:
       * https://www.cs.auckland.ac.nz/~pgut001/pubs/x509guide.txt
       */
    case ASN1_T61_STRING:
      err = latin1_to_utf8(&utf8_string, src_string, result_pool);
      break;

      /* This leaves two types out there in the wild.  PrintableString,
       * which is just a subset of ASCII and IA5 which is ASCII (though
       * 0x24 '$' and 0x23 '#' may be defined with differnet symbols
       * depending on the location, in practice it seems everyone just
       * treats it as ASCII).  Since these are just ASCII run through
       * the fuzzy_escape code to deal with anything that isn't actually
       * ASCII.  There shouldn't be any other types here but if we find
       * a cert with some other encoding, the best we can do is the
       * fuzzy_escape().  Note: Technically IA5 isn't valid in this
       * context, however in the real world it may pop up. */
    default:
      return fuzzy_escape(src_string, result_pool);
    }

  if (err)
    {
      svn_error_clear(err);
      return fuzzy_escape(src_string, result_pool);
    }

  return nul_escape(utf8_string, result_pool);
}
Exemplo n.º 11
0
void
meta_prop_get_values (MetaDisplay   *display,
                      Window         xwindow,
                      MetaPropValue *values,
                      int            n_values)
{
  int i;
  AgGetPropertyTask **tasks;

  meta_verbose ("Requesting %d properties of 0x%lx at once\n",
                n_values, xwindow);
  
  if (n_values == 0)
    return;
  
  tasks = g_new0 (AgGetPropertyTask*, n_values);

  /* Start up tasks. The "values" array can have values
   * with atom == None, which means to ignore that element.
   */
  i = 0;
  while (i < n_values)
    {
      if (values[i].required_type == None)
        {
          switch (values[i].type)
            {
            case META_PROP_VALUE_INVALID:
              /* This means we don't really want a value, e.g. got
               * property notify on an atom we don't care about.
               */
              if (values[i].atom != None)
                meta_bug ("META_PROP_VALUE_INVALID requested in %s\n", G_STRFUNC);
              break;
            case META_PROP_VALUE_UTF8_LIST:
            case META_PROP_VALUE_UTF8:
              values[i].required_type = display->atom_UTF8_STRING;
              break;
            case META_PROP_VALUE_STRING:
            case META_PROP_VALUE_STRING_AS_UTF8:
              values[i].required_type = XA_STRING;
              break;
            case META_PROP_VALUE_MOTIF_HINTS:
              values[i].required_type = AnyPropertyType;
              break;
            case META_PROP_VALUE_CARDINAL_LIST:
            case META_PROP_VALUE_CARDINAL:
              values[i].required_type = XA_CARDINAL;
              break;
            case META_PROP_VALUE_WINDOW:
              values[i].required_type = XA_WINDOW;
              break;
            case META_PROP_VALUE_ATOM_LIST:
              values[i].required_type = XA_ATOM;
              break;
            case META_PROP_VALUE_TEXT_PROPERTY:
              values[i].required_type = AnyPropertyType;
              break;
            case META_PROP_VALUE_WM_HINTS:
              values[i].required_type = XA_WM_HINTS;
              break;
            case META_PROP_VALUE_CLASS_HINT:
              values[i].required_type = XA_STRING;
              break;
            case META_PROP_VALUE_SIZE_HINTS:
              values[i].required_type = XA_WM_SIZE_HINTS;
              break;
            case META_PROP_VALUE_SYNC_COUNTER:
	      values[i].required_type = XA_CARDINAL;
              break;
            }
        }

      if (values[i].atom != None)
        tasks[i] = get_task (display, xwindow,
                             values[i].atom, values[i].required_type);
      
      ++i;
    }  
  
  /* Get replies for all our tasks */
  meta_topic (META_DEBUG_SYNC, "Syncing to get %d GetProperty replies in %s\n",
              n_values, G_STRFUNC);
  XSync (display->xdisplay, False);
  
  /* Collect results, should arrive in order requested */
  i = 0;
  while (i < n_values)
    {
      AgGetPropertyTask *task;
      GetPropertyResults results;
      
      if (tasks[i] == NULL)
        {
          /* Probably values[i].type was None, or ag_task_create()
           * returned NULL.
           */
          values[i].type = META_PROP_VALUE_INVALID;
          goto next;
        }
      
      task = ag_get_next_completed_task (display->xdisplay);
      g_assert (task != NULL);
      g_assert (ag_task_have_reply (task));

      results.display = display;
      results.xwindow = xwindow;
      results.xatom = values[i].atom;
      results.prop = NULL;
      results.n_items = 0;
      results.type = None;
      results.bytes_after = 0;
      results.format = 0;
      
      if (ag_task_get_reply_and_free (task,
                                      &results.type, &results.format,
                                      &results.n_items,
                                      &results.bytes_after,
                                      &results.prop) != Success ||
          results.type == None)
        {
          values[i].type = META_PROP_VALUE_INVALID;
          if (results.prop)
            {
              XFree (results.prop);
              results.prop = NULL;
            }
          goto next;
        }

      switch (values[i].type)
        {
        case META_PROP_VALUE_INVALID:
          g_assert_not_reached ();
          break;
        case META_PROP_VALUE_UTF8_LIST:
          if (!utf8_list_from_results (&results,
                                       &values[i].v.string_list.strings,
                                       &values[i].v.string_list.n_strings))
            values[i].type = META_PROP_VALUE_INVALID;
          break;
        case META_PROP_VALUE_UTF8:
          if (!utf8_string_from_results (&results,
                                         &values[i].v.str))
            values[i].type = META_PROP_VALUE_INVALID;
          break;
        case META_PROP_VALUE_STRING:
          if (!latin1_string_from_results (&results,
                                           &values[i].v.str))
            values[i].type = META_PROP_VALUE_INVALID;
          break;
        case META_PROP_VALUE_STRING_AS_UTF8:
          if (!latin1_string_from_results (&results,
                                           &values[i].v.str))
            values[i].type = META_PROP_VALUE_INVALID;
          else
            {
              char *new_str;
              char *xmalloc_new_str;

              new_str = latin1_to_utf8 (values[i].v.str);
              xmalloc_new_str = ag_Xmalloc (strlen (new_str) + 1);
              if (xmalloc_new_str != NULL)
                {
                  strcpy (xmalloc_new_str, new_str);
                  meta_XFree (values[i].v.str);
                  values[i].v.str = xmalloc_new_str;
                }

              g_free (new_str);
            }
          break;
        case META_PROP_VALUE_MOTIF_HINTS:
          if (!motif_hints_from_results (&results,
                                         &values[i].v.motif_hints))
            values[i].type = META_PROP_VALUE_INVALID;
          break;
        case META_PROP_VALUE_CARDINAL_LIST:
          if (!cardinal_list_from_results (&results,
                                           &values[i].v.cardinal_list.cardinals,
                                           &values[i].v.cardinal_list.n_cardinals))
            values[i].type = META_PROP_VALUE_INVALID;
          break;
        case META_PROP_VALUE_CARDINAL:
          if (!cardinal_with_atom_type_from_results (&results,
                                                     values[i].required_type,
                                                     &values[i].v.cardinal))
            values[i].type = META_PROP_VALUE_INVALID;
          break;
        case META_PROP_VALUE_WINDOW:
          if (!window_from_results (&results,
                                    &values[i].v.xwindow))
            values[i].type = META_PROP_VALUE_INVALID;
          break;
        case META_PROP_VALUE_ATOM_LIST:
          if (!atom_list_from_results (&results,
                                       &values[i].v.atom_list.atoms,
                                       &values[i].v.atom_list.n_atoms))
            values[i].type = META_PROP_VALUE_INVALID;
          break;
        case META_PROP_VALUE_TEXT_PROPERTY:
          if (!text_property_from_results (&results, &values[i].v.str))
            values[i].type = META_PROP_VALUE_INVALID;
          break;
        case META_PROP_VALUE_WM_HINTS:
          if (!wm_hints_from_results (&results, &values[i].v.wm_hints))
            values[i].type = META_PROP_VALUE_INVALID;
          break;
        case META_PROP_VALUE_CLASS_HINT:
          if (!class_hint_from_results (&results, &values[i].v.class_hint))
            values[i].type = META_PROP_VALUE_INVALID;
          break;
        case META_PROP_VALUE_SIZE_HINTS:
          if (!size_hints_from_results (&results,
                                        &values[i].v.size_hints.hints,
                                        &values[i].v.size_hints.flags))
            values[i].type = META_PROP_VALUE_INVALID;
          break;
        case META_PROP_VALUE_SYNC_COUNTER:
#ifdef HAVE_XSYNC
          if (!counter_from_results (&results,
                                     &values[i].v.xcounter))
            values[i].type = META_PROP_VALUE_INVALID;
#else
          values[i].type = META_PROP_VALUE_INVALID;
          if (results.prop)
            {
              XFree (results.prop);
              results.prop = NULL;
            }
#endif
          break;
        }

    next:
      ++i;
    }

  g_free (tasks);
}
Exemplo n.º 12
0
int ei_encode_atom_len_as(char *buf, int *index, const char *p, int len,
			  erlang_char_encoding from_enc,
			  erlang_char_encoding to_enc)
{
  char *s = buf + *index;
  char *s0 = s;
  int offs;

  if (len >= MAXATOMLEN && (from_enc & (ERLANG_LATIN1|ERLANG_ASCII))) {
      return -1;
  }

  switch(to_enc) {
  case ERLANG_LATIN1:
      if (buf) {
	  put8(s,ERL_ATOM_EXT);
	  switch (from_enc) {
	  case ERLANG_UTF8:
	      len = utf8_to_latin1(s+2, p, len, MAXATOMLEN-1, NULL);
	      if (len < 0) return -1;
	      break;
	  case ERLANG_ASCII:
	      if (verify_ascii_atom(p, len) < 0) return -1;
	      memcpy(s+2, p, len);
	      break;
	  case ERLANG_LATIN1:
	      memcpy(s+2, p, len);
	      break;
	  default:
	      return -1;
	  }
	  put16be(s,len);
      }
      else {
	  s += 3;
	  if (from_enc == ERLANG_UTF8) {
	      len = utf8_to_latin1(NULL, p, len, MAXATOMLEN-1, NULL);
	      if (len < 0) return -1;
	  } else if (from_enc == ERLANG_ASCII)
	    if (verify_ascii_atom(p, len) < 0) return -1;
      }
      break;
      
  case ERLANG_UTF8:
      offs =  1 + 1;
      switch (from_enc) {
      case ERLANG_LATIN1:
	  if (len >= 256/2) offs++;
	  len = latin1_to_utf8((buf ? s+offs : NULL), p, len, MAXATOMLEN_UTF8-1, NULL);
	  break;
      case ERLANG_ASCII:
	  if (verify_ascii_atom(p, len) < 0) return -1;
	  if (buf) memcpy(s+offs,p,len);
	  break;
      case ERLANG_UTF8:
	  if (len >= 256) offs++;
	  if (verify_utf8_atom(p, len) < 0) return -1;
	  if (buf) memcpy(s+offs,p,len);
	  break;
      default:
	  return -1;
      }
      if (buf) {
	  if (offs == 2) {
	      put8(s, ERL_SMALL_ATOM_UTF8_EXT);
	      put8(s, len);
	  }
	  else {
	      put8(s, ERL_ATOM_UTF8_EXT);
	      put16be(s, len);
	  }
      }
      else s+= offs;
      break;

  default:
      return -1;
  }
  s += len;

  *index += s-s0; 

  return 0; 
}