Example #1
0
static int us1060_start_server (char *cert, char *key, int no_http_auth, int enable_pop, int enable_srp)
{
    int rv;

    if (enable_srp) {
	rv = st_start_srp(US1060_SERVER_PORT, 
			  cert, key,
			  "US1060 test realm",
			  US1060_CACERTS,
			  US1060_TRUST_CERTS,
	                  "CA/estExampleCA.cnf",
		          enable_pop,
		          US1060_VFILE);
    } else {
	rv = st_start(US1060_SERVER_PORT, 
		      cert, key,
		      "US1060 test realm",
		      US1060_CACERTS,
		      US1060_TRUST_CERTS,
	              "CA/estExampleCA.cnf",
		      0,
		      enable_pop,
		      0);
    }

    if (no_http_auth) {
        st_disable_http_auth();
    }

    return rv;
}
Example #2
0
static void ParseNotes(StringX &sxNotes,
                       std::vector<StringX> &vsxnotes_lines)
{
  if (!sxNotes.empty()) {
    // Use \n and \r to tokenise this line
    StringX::size_type st_start(0), st_end(0);
    const StringX sxdelim = _T("\r\n");
    StringX sxline;
    StringX::size_type st_index;
    while (st_end != StringX::npos) {
      st_end = sxNotes.find(sxdelim, st_start);
      sxline = (sxNotes.substr(st_start, 
                   (st_end == StringX::npos) ? StringX::npos : st_end - st_start));
      st_index = 0;
      // Remove all tabs - \t
      for (;;) {
        st_index = sxline.find(_T("\\t"), st_index);
        if (st_index == StringX::npos)
          break;
        sxline.replace(st_index, 2, _T(""));
        st_index += 1;
      }
      vsxnotes_lines.push_back(sxline);
      st_start = ((st_end > (StringX::npos - sxdelim.size()))
                          ? StringX::npos : st_end + sxdelim.size());
    }
  }
}
Example #3
0
/*
 * Start the appropriate flavor of st_server
 * based what character is specified
 * B - Basic auth
 * D - Digest auth
 * C - CRL checking
 * N = No auth
 */
static int us901_start_server(char server_type) {
    int rv;

    switch (server_type) {
    case 'B':
        rv = st_start(US901_SERVER_PORT,
        US901_SERVER_CERTKEY,
        US901_SERVER_CERTKEY, "estrealm", "CA/estCA/cacert.crt",
                "CA/trustedcerts.crt", "CA/estExampleCA.cnf", 0, 0, 0);
        st_enable_http_basic_auth();
        break;
    case 'D':
        rv = st_start(US901_SERVER_PORT,
        US901_SERVER_CERTKEY,
        US901_SERVER_CERTKEY, "estrealm", "CA/estCA/cacert.crt",
                "CA/trustedcerts.crt", "CA/estExampleCA.cnf", 0, 0, 0);
        st_enable_http_digest_auth();
        break;
    case 'C':
        system(
                "openssl ca -config CA/estExampleCA.cnf -gencrl -out CA/estCA/crl.pem");
        SLEEP(1);
        system(
                "cat CA/trustedcerts.crt CA/estCA/crl.pem > US901/trustedcertsandcrl.crt");
        SLEEP(1);
        rv = st_start(US901_SERVER_PORT,
        US901_SERVER_CERTKEY,
        US901_SERVER_CERTKEY, "estrealm", "CA/estCA/cacert.crt",
                "US901/trustedcertsandcrl.crt", "CA/estExampleCA.cnf", 0, 0, 0);
        st_enable_crl();
        st_disable_http_auth();
        break;
    case 'N':
        rv = st_start(US901_SERVER_PORT,
        US901_SERVER_CERTKEY,
        US901_SERVER_CERTKEY, "estrealm", "CA/estCA/cacert.crt",
                "CA/trustedcerts.crt", "CA/estExampleCA.cnf", 0, 0, 0);
        st_disable_http_auth();
        break;
    default:
        rv = -1;
        break;
    }

    return rv;
}
Example #4
0
lexeme *get_lex(lexer_info *linfo)
{
    lexeme *lex = NULL;
    buffer buf;

    new_buffer(&buf);

    do {
        if (linfo->get_next_char) {
            linfo->get_next_char = 0;
            get_char(linfo);
        }

        switch (linfo->state) {
        case ST_START:
            lex = st_start(linfo, &buf);
            break;

        case ST_ONE_SYM_LEX:
            lex = st_one_sym_lex(linfo, &buf);
            break;

        case ST_ONE_TWO_SYM_LEX:
            lex = st_one_two_sym_lex(linfo, &buf);
            break;

        case ST_BACKSLASH:
            lex = st_backslash(linfo, &buf);
            break;

        case ST_BACKSLASH_IN_QUOTES:
            lex = st_backslash_in_quotes(linfo, &buf);
            break;

        case ST_IN_QUOTES:
            lex = st_in_quotes(linfo, &buf);
            break;

        case ST_WORD:
            lex = st_word(linfo, &buf);
            break;

        case ST_ERROR:
            lex = st_error(linfo, &buf);
            break;

        case ST_EOLN_EOF:
            lex = st_eoln_eof(linfo, &buf);
            break;
        } /* switch */
    } while (lex == NULL);

    return lex;
}
Example #5
0
static int us896_start_server(int manual_enroll, int nid) {
    int rv;

    rv = st_start(US896_SERVER_PORT,
    US896_SERVER_CERTKEY,
    US896_SERVER_CERTKEY, "US896 test realm",
    US896_CACERTS,
    US896_TRUST_CERTS, "CA/estExampleCA.cnf", manual_enroll, 0, nid);

    SLEEP(1);
    return rv;
}
Example #6
0
void stt_test_2(void)
{
    st_start();
    
    UART_1_PutString(_state_none_event_none);
    
    for (;;)
    {
        if (st_is_valid_input() == ST_SUCCESS)
        {
            st_transition();
        }
    }
}
Example #7
0
File: us1864.c Project: DDvO/libest
static int us1864_start_server (int manual_enroll, int nid)
{
    int rv;

    rv = st_start(US1864_TCP_PORT, 
	          "CA/estCA/private/estservercertandkey.pem",
	          "CA/estCA/private/estservercertandkey.pem",
	          "US1864 test realm",
	          "CA/estCA/cacert.crt",
	          "CA/trustedcerts.crt",
	          "CA/estExampleCA.cnf",
		  manual_enroll,
		  0,
		  nid);
    return rv;
}
Example #8
0
static int us1864_start_server (int manual_enroll, int nid)
{
    int rv;

    rv = st_start(US1864_TCP_PORT,
                  US1864_SERVER_CERT,
                  US1864_SERVER_KEY,
                  "US1864 test realm",
                  US1864_CACERTS,
                  US1864_TRUSTED_CERT,
                  "CA/estExampleCA.cnf",
                  manual_enroll,
                  0,
                  nid);
    return rv;
}
Example #9
0
File: us900.c Project: DDvO/libest
static int us900_start_server (int manual_enroll, int nid)
{
    int rv;

    rv = st_start(US900_SERVER_PORT, 
	          US900_SERVER_CERTKEY,
	          US900_SERVER_CERTKEY,
	          "US900 test realm",
	          US900_CACERTS,
	          US900_TRUST_CERTS,
	          "CA/estExampleCA.cnf",
		  manual_enroll,
		  0,
		  nid);


    sleep(1);
    return rv;
}
Example #10
0
static int us748_start_server (int manual_enroll, int nid)
{
    int rv = 0;

    /*
     * First we start an EST server acting as the CA
     */
    rv = st_start(US748_TCP_SERVER_PORT, 
	          US748_SERVER_CERT,
	          US748_SERVER_KEY,
	          "estrealm",
	          US748_CACERT,
	          "CA/trustedcerts.crt",
	          "US748/estExampleCA.cnf",
		  manual_enroll,  // manual enroll
		  0,  // disable PoP
		  nid); // ecdhe nid info
    sleep(1);
    if (rv != EST_ERR_NONE) return rv;

    /*
     * Next we start an EST proxy acting as an RA.
     */
    rv = st_proxy_start(US748_TCP_PROXY_PORT, 
                        US748_PROXY_CERT,
                        US748_PROXY_KEY,
                        "estrealm",
                        US748_CACERT,
                        "CA/trustedcerts.crt",
                        "estuser",
                        "estpwd",
                        "127.0.0.1",
                        US748_TCP_SERVER_PORT,
                        0,  // disable PoP
                        nid);  // ecdhe nid info
    sleep(1);

    return rv;
}
Example #11
0
File: us895.c Project: DDvO/libest
static int us895_start_server (int manual_enroll, int nid)
{
    int rv;

    rv = st_start(US895_SERVER_PORT, 
	          US895_SERVER_CERTKEY,
	          US895_SERVER_CERTKEY,
	          "US895 test realm",
	          "CA/estCA/cacert.crt",
	          "CA/trustedcerts.crt",
	          "CA/estExampleCA.cnf",
		  manual_enroll,
		  0,
		  nid);

    if (rv) {
        return (rv);
    }
    
    /*
     * Next we start an EST proxy acting as an RA
     */
    rv = st_proxy_start(US895_PROXY_PORT, 
	          US895_SERVER_CERTKEY,
	          US895_SERVER_CERTKEY,
	          "US895 test realm",
	          "CA/estCA/cacert.crt",
	          "CA/trustedcerts.crt",
		  "estuser",
		  "estpwd",
		  "127.0.0.1",
		  US895_SERVER_PORT,
		  0,
		  nid);


    sleep(1);
    return rv;
}
Example #12
0
int us1190_start_server ()
{
    int rv = 0;

    /*
     * Start an EST server acting as the CA
     * this server does not support TLS 1.0
     */
    rv = st_start(atoi(US1190_TCP_SERVER_PORT),
                  US1190_SERVER_CERT,
                  US1190_SERVER_KEY,
                  "estrealm",
                  US1190_CACERT,
                  US1190_TRUSTED_CERT,
                  "US1190/estExampleCA.cnf",
                  0,  // manual enroll
                  0,  // disable PoP
                  0); // ecdhe nid info
    SLEEP(1);
    if (rv != EST_ERR_NONE)
        return rv;

    return rv;
}
Example #13
0
File: us893.c Project: DDvO/libest
static int us893_start_server (int manual_enroll, int nid)
{
    int rv;

    /*
     * First we start an EST server acting as the CA
     */
    rv = st_start(US893_TCP_SERVER_PORT, 
	          US893_SERVER_CERTKEY,
	          US893_SERVER_CERTKEY,
	          "US893 test realm",
	          "CA/estCA/cacert.crt",
	          "CA/trustedcerts.crt",
	          "US893/estExampleCA.cnf",
		  manual_enroll,
		  0,
		  nid);
    if (rv != EST_ERR_NONE) return rv;

    /*
     * Next we start an EST proxy actging as an RA
     */
    rv = st_proxy_start(US893_TCP_PROXY_PORT, 
	          US893_PROXY_CERT,
	          US893_PROXY_KEY,
	          "US893 test realm",
	          "CA/estCA/cacert.crt",
	          "CA/trustedcerts.crt",
		  "estuser",
		  "estpwd",
		  "127.0.0.1",
		  US893_TCP_SERVER_PORT,
		  0,
		  nid);
    return rv;
}
Example #14
0
/****************************************************************************
 *  Exported Functions
 ****************************************************************************/
uint8 stt_test_1(void)
{
    uint8 result = STT_SUCCESS;
    char string_0[ST_NODE_LIMIT] = {0};
    
    UART_1_Start();
    
    UART_1_PutString("\x1b\x5b\x32\x4a");
    UART_1_PutString("FINITE STATE MACHINE LIBRARY TEST\r\n");
    UART_1_PutString("\r\n");
    UART_1_PutString("Test\tFunction\t\tResult\r\n");
    UART_1_PutString("----\t--------\t\t------\r\n");
    
    /*
     *  Initialise test.
     */
    if (result == STT_SUCCESS)
    {
        st_start();
        
        UART_1_PutString("   -\tInitialise test...\tPASS\r\n");
    }
    
    /*
     *  Test st_add_key().
     */
    if (result == STT_SUCCESS)
    {
        if (st_add_key(NULL) == ST_BAD_ARGUMENT)
        {
            UART_1_PutString("   1\tst_add_key()\t\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   1\tst_add_key()\t\tFAIL\r\n");
            result = STT_FAILURE;
        }
    }
    
    if (result == STT_SUCCESS)
    {
        if (st_add_key("A") == ST_SUCCESS)
        {
            UART_1_PutString("   2\tst_add_key()\t\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   2\tst_add_key()\t\tFAIL\r\n");
            result = STT_FAILURE;
        }
    }
        
    /*
     *  Test st_get_limit().
     */
    if (result == STT_SUCCESS)
    {
        if (st_get_limit() == ST_NODE_LIMIT)
        {
            UART_1_PutString("   3\tst_get_limit()\t\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   3\tst_get_limit()\t\tFAIL\r\n");
            result = STT_FAILURE;
        }
    }
    
    /*
     *  Initialise st_set_limit() test.
     */
    if (result == STT_SUCCESS)
    {
        if (st_add_key("B") == ST_SUCCESS)
        {
            UART_1_PutString("   -\tInitialise test...\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   -\tInitialise test...\tFAIL\r\n");
            result = STT_FAILURE;
        }
    }
    
    if (result == STT_SUCCESS)
    {
        if (st_add_key("C") == ST_SUCCESS)
        {
            UART_1_PutString("   -\tInitialise test...\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   -\tInitialise test...\tFAIL\r\n");
            result = STT_FAILURE;
        }
    }
    
    /*
     *  Test st_set_limit().
     */
    if (result == STT_SUCCESS)
    {
        if (st_set_limit(1) == ST_FAILURE)
        {
            UART_1_PutString("   4\tst_set_limit()\t\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   4\tst_set_limit()\t\tFAIL\r\n");
            result = STT_FAILURE;
        }
    }
    
    if (result == STT_SUCCESS)
    {
        if (st_set_limit(0) == ST_SUCCESS)
        {
            UART_1_PutString("   5\tst_set_limit()\t\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   5\tst_set_limit()\t\tFAIL\r\n");
            result = STT_FAILURE;
        }
    }
    
    /*
     *  Test st_copy_buffer().
     */
    if (result == STT_SUCCESS)
    {
        if (st_copy_buffer(NULL) == ST_BAD_ARGUMENT)
        {
            UART_1_PutString("   6\tst_copy_buffer()\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   6\tst_copy_buffer()\tFAIL\r\n");
            result = STT_FAILURE;
        }
    }
    
    if (result == STT_SUCCESS)
    {
        if (st_copy_buffer(string_0) == ST_SUCCESS)
        {
            UART_1_PutString("   7\tst_copy_buffer()\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   7\tst_copy_buffer()\tFAIL\r\n");
            result = STT_FAILURE;
        }
    }
    
    if (result == STT_SUCCESS)
    {
        if (strcmp(string_0, "ABC") == ST_SUCCESS)
        {
            UART_1_PutString("   8\tst_copy_buffer()\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   8\tst_copy_buffer()\tFAIL\r\n");
            result = STT_FAILURE;
        }
    }
        
    /*
     *  Test st_get_count().
     */
    if (result == STT_SUCCESS)
    {
        if (st_get_count() == 3)
        {
            UART_1_PutString("   9\tst_get_count()\t\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   9\tst_get_count()\t\tFAIL\r\n");
            result = STT_FAILURE;
        }
    }
        
    /*
     *  Test st_empty_buffer().
     */
    if (result == STT_SUCCESS)
    {
        st_empty_buffer();
        
        if (st_get_count() == 0)
        {
            UART_1_PutString("  10\tst_empty_buffer()\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("  10\tst_empty_buffer()\tFAIL\r\n");
            result = STT_FAILURE;
        }
    }
    
    /*
     *  Test st_copy_buffer().
     */
    if (result == STT_SUCCESS)
    {
        if (st_copy_buffer(string_0) == ST_EMPTY)
        {
            UART_1_PutString("  11\tst_copy_buffer()\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("  11\tst_copy_buffer()\tFAIL\r\n");
            result = STT_FAILURE;
        }
    }
    
    /*
     *  Test st_is_valid_input().
     */
    if (result == STT_SUCCESS)
    {
        if (st_is_valid_input() == ST_FAILURE)
        {
            UART_1_PutString("  12\tst_is_valid_input()\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("  12\tst_is_valid_input()\tFAIL\r\n");
            result = STT_FAILURE;
        }
    }
    
    /*
     *  Initialise st_is_valid_input() test.
     */
    if (result == STT_SUCCESS)
    {
        if (st_add_key("C") == ST_SUCCESS)
        {
            UART_1_PutString("   -\tInitialise test...\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   -\tInitialise test...\tFAIL\r\n");
            result = STT_FAILURE;
        }
    }
    
    /*
     *  Test st_is_valid_input().
     */
    if (result == STT_SUCCESS)
    {
        if (st_is_valid_input() == ST_SUCCESS)
        {
            UART_1_PutString("  13\tst_is_valid_input()\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("  13\tst_is_valid_input()\tFAIL\r\n");
            result = STT_FAILURE;
        }
    }
    
    if (result == STT_SUCCESS)
    {   
        if (st_get_count() == 0)
        {
            UART_1_PutString("  14\tst_is_valid_input()\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("  14\tst_is_valid_input()\tFAIL\r\n");
            result = STT_FAILURE;
        }
    }
    
    /*
     *  Test st_set_state().
     */
    if (result == STT_SUCCESS)
    {
        if (st_set_state(ST_STATE_MAXIMUM) == ST_BAD_ARGUMENT)
        {
            UART_1_PutString("  15\tst_set_state()\t\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("  15\tst_set_state()\t\tFAIL\r\n");
            result = STT_FAILURE;
        }
    }
     
    if (result == STT_SUCCESS)
    {
        if (st_set_state(ST_STATE_4) == ST_SUCCESS)
        {
            UART_1_PutString("  16\tst_set_state()\t\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("  16\tst_set_state()\t\tFAIL\r\n");
            result = STT_FAILURE;
        }
    }
    
    /*
     *  Initialise st_is_valid_input() test.
     */
    if (result == STT_SUCCESS)
    {
        if (st_add_key("\r") == ST_SUCCESS)
        {
            UART_1_PutString("   -\tInitialise test...\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   -\tInitialise test...\tFAIL\r\n");
            result = STT_FAILURE;
        }
    }
    
    /*
     *  Test st_is_valid_input().
     */
    if (result == STT_SUCCESS)
    {
        if (st_is_valid_input() == ST_SUCCESS)
        {
            UART_1_PutString("  17\tst_is_valid_input()\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("  17\tst_is_valid_input()\tFAIL\r\n");
            result = STT_FAILURE;
        }
    }
    
    if (result == STT_SUCCESS)
    {   
        if (st_get_count() == 1)
        {
            UART_1_PutString("  18\tst_is_valid_input()\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("  18\tst_is_valid_input()\tFAIL\r\n");
            result = STT_FAILURE;
        }
    }
    
    /*
     *  Initialise st_is_valid_input() test.
     */
    if (result == STT_SUCCESS)
    {
        if (st_set_state(ST_STATE_2) == ST_SUCCESS)
        {
            UART_1_PutString("   -\tInitialise test...\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("   -\tInitialise test...\tFAIL\r\n");
            result = STT_FAILURE;
        }
    }
    
    /*
     *  Test st_is_valid_input().
     */
    if (result == STT_SUCCESS)
    {   
        if (st_is_valid_input() == ST_FAILURE)
        {
            UART_1_PutString("  19\tst_is_valid_input()\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("  19\tst_is_valid_input()\tFAIL\r\n");
            result = STT_FAILURE;
        }
    }
    
    if (result == STT_SUCCESS)
    {
        st_set_bit(ST_HARDWARE_EVENT);
        
        if (st_is_valid_input() == ST_SUCCESS)
        {
            UART_1_PutString("  20\tst_is_valid_input()\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("  20\tst_is_valid_input()\tFAIL\r\n");
            result = STT_FAILURE;
        }
    }
    
    /*
     *  Initialise st_is_valid_input() test.
     */
    if (result == STT_SUCCESS)
    {
        st_clear_bit(ST_CARRIAGE_RETURN);
        
        UART_1_PutString("   -\tInitialise test...\tPASS\r\n");
    }
    
    /*
     *  Test st_is_valid_input().
     */
    if (result == STT_SUCCESS)
    {   
        if (st_is_valid_input() == ST_FAILURE)
        {
            UART_1_PutString("  21\tst_is_valid_input()\tPASS\r\n");
        }
        else
        {
            UART_1_PutString("  21\tst_is_valid_input()\tFAIL\r\n");
            result = STT_FAILURE;
        }
    }
        
    /*
     *  Report test result.
     */
    if (result == STT_SUCCESS)
    {
        UART_1_PutString("\r\n");
        UART_1_PutString("TEST PASSED\r\n");
    }
    else
    {
        UART_1_PutString("\r\n");
        UART_1_PutString("TEST FAILED\r\n");
    }
    
    /*
     *  Clean-up test.
     */
    while (UART_1_ReadTxStatus() != UART_1_TX_STS_FIFO_EMPTY)
    {
        CyDelay(1);
    }
    
    UART_1_Stop();
    
    st_stop();
    
    return result;
}
Example #15
0
StringX PWSAuxParse::GetAutoTypeString(const StringX &sx_in_autotype,
                                       const StringX &sx_group,
                                       const StringX &sx_title,
                                       const StringX &sx_user,
                                       const StringX &sx_pwd,
                                       const StringX &sx_notes,
                                       const StringX &sx_url,
                                       const StringX &sx_email,
                                       std::vector<size_t> &vactionverboffsets)
{
  StringX sxtmp(_T(""));
  StringX sxNotes(sx_notes);
  TCHAR curChar;
  StringX sx_autotype(sx_in_autotype);
  StringX::size_type st_index;
  std::vector<StringX> vsxnotes_lines;

  vactionverboffsets.clear();

  // If empty, try the database default
  if (sx_autotype.empty()) {
    sx_autotype = PWSprefs::GetInstance()->
              GetPref(PWSprefs::DefaultAutotypeString);

    // If still empty, take this default
    if (sx_autotype.empty()) {
      // checking for user and password for default settings
      if (!sx_pwd.empty()){
        if (!sx_user.empty())
          sx_autotype = DEFAULT_AUTOTYPE;
        else
          sx_autotype = _T("\\p\\n");
      }
    }
  }

  // No recursive substitution (e.g. \p or \u), although '\t' will be replaced by a tab
  if (!sx_notes.empty()) {
    // Use \n and \r to tokenise this line
    StringX::size_type st_start(0), st_end(0);
    const StringX sxdelim = _T("\r\n");
    StringX sxline;
    while (st_end != StringX::npos) {
      st_end = sxNotes.find_first_of(sxdelim, st_start);
      sxline = (sxNotes.substr(st_start, (st_end == StringX::npos) ? 
                              StringX::npos : st_end - st_start));
      st_index = 0;
      for (;;) {
        st_index = sxline.find(_T("\\t"), st_index);
        if (st_index == StringX::npos)
          break;
        sxline.replace(st_index, 2, _T("\t"));
        st_index += 1;
      }
      vsxnotes_lines.push_back(sxline);
      // If we just hit a "\r\n", move past it.  Or else, it is a "\r" without
      // a following "\n" or a "\n", so just move past one single char
      if (st_end != StringX::npos) {
        st_start = st_end + (sxNotes.compare(st_end, 2, sxdelim) == 0 ? 2 : 1);
        if (st_start >= sxNotes.length())
          break;
      }
    }
    // Now change '\n' to '\r' in the complete notes field
    st_index = 0;
    for (;;) {
      st_index = sxNotes.find(sxdelim, st_index);
      if (st_index == StringX::npos)
        break;
      sxNotes.replace(st_index, 2, _T("\r"));
      st_index += 1;
    }
    st_index = 0;
    for (;;) {
      st_index = sxNotes.find(_T("\\t"), st_index);
      if (st_index == StringX::npos)
        break;
      sxNotes.replace(st_index, 2, _T("\t"));
      st_index += 1;
    }
  }

  const size_t N = sx_autotype.length();
  const StringX sxZeroes = _T("000");
  int gNumIts;

  for (size_t n = 0; n < N; n++){
    curChar = sx_autotype[n];
    if (curChar == TCHAR('\\')) {
      n++;
      if (n < N)
        curChar = sx_autotype[n];

      switch (curChar){
        case TCHAR('\\'):
          sxtmp += TCHAR('\\');
          break;
        case TCHAR('n'):
        case TCHAR('r'):
          sxtmp += TCHAR('\r');
          break;
        case TCHAR('t'):
          sxtmp += TCHAR('\t');
          break;
        case TCHAR('s'):
          sxtmp += TCHAR('\v');
          break;
        case TCHAR('g'):
          sxtmp += sx_group;
          break;
        case TCHAR('i'):
          sxtmp += sx_title;
          break;
        case TCHAR('u'):
          sxtmp += sx_user;
          break;
        case TCHAR('p'):
          sxtmp += sx_pwd;
          break;
        case TCHAR('l'):
          sxtmp += sx_url;
          break;
        case TCHAR('m'):
          sxtmp += sx_email;
          break;

        case TCHAR('o'):
        {
          if (n == (N - 1)) {
            // This was the last character - send the lot!
            sxtmp += sxNotes;
            break;
          }
          size_t line_number(0);
          gNumIts = 0;
          for (n++; n < N && (gNumIts < 3); ++gNumIts, n++) {
            if (_istdigit(sx_autotype[n])) {
              line_number *= 10;
              line_number += (sx_autotype[n] - TCHAR('0'));
            } else
              break; // for loop
          }
          if (line_number == 0) {
            // Send the lot
            sxtmp += sx_notes;
          } else
          if (line_number <= vsxnotes_lines.size()) {
            // User specifies a too big a line number - ignore the lot
            sxtmp += vsxnotes_lines[line_number - 1];
          }

          // Backup the extra character that delimited the \oNNN string
          n--;
          break; // case 'o'
        }

        // Action Verbs:
        // These are the only ones processed specially by the UI as they involve
        // actions it performs whilst doing the key sending.
        // Copy them to output string unchanged.
        case TCHAR('b'):  // backspace!
        case TCHAR('z'):  // Use older method
          vactionverboffsets.push_back(sxtmp.length());
          sxtmp += _T("\\");
          sxtmp += curChar;
          break; // case 'b' & 'z'

        case TCHAR('d'):  // Delay
        case TCHAR('w'):  // Wait milli-seconds
        case TCHAR('W'):  // Wait seconds
        {
          // Need to ensure that the field length is 3, even if it wasn't
          vactionverboffsets.push_back(sxtmp.length());
          sxtmp += _T("\\");
          sxtmp += curChar;

          gNumIts = 0;
          size_t i = n;
          for (i++; i < N && (gNumIts < 3); ++gNumIts, i++) {
            if (!_istdigit(sx_autotype[i]))
              break;
          }
          // Insert sufficient zeroes to ensure field is 3 characters long
          sxtmp += sxZeroes.substr(0, 3 - gNumIts);
          break; // case 'd', 'w' & 'W'
        }

        // Also copy explicit control characters to output string unchanged.
        case TCHAR('a'): // bell (can't hear it during testing!)
        case TCHAR('v'): // vertical tab
        case TCHAR('f'): // form feed
        case TCHAR('e'): // escape
        case TCHAR('x'): // hex digits (\xNN)
        // and any others we have forgotten!
        // '\cC', '\uXXXX', '\OOO', '\<any other charatcer not recognised above>'
        default:
          sxtmp += L'\\';
          sxtmp += curChar;
          break;
      }
    } else
      sxtmp += curChar;
  }

  vsxnotes_lines.clear();
  return sxtmp;
}