Quantcast
Channel: WE MOVED to github.com/microsoft/cpprestsdk. This site is not monitored!
Viewing all 4845 articles
Browse latest View live

Updated Release: C++ Rest SDK 2.5.0

$
0
0
Android
  • Fixed issue in CMakeLists.txt where parenthesis were incorrectly used instead of brackets.
  • Fixed issue in CMakeLists.txt where pplxlinux.cpp source file was missing.
  • Added Android TestRunner packing androidproj to build.

Windows
  • Fixed several code analysis warnings.
  • Updating NuGet package for missing OpenSSL license, also patched 2.4.0's NuGet package.
  • Fixed not working on XP issue because of crypto API. #331, #334
  • Fixed several functions missing an explicit calling convention. This caused problems if you changed the calling convention from the cdecl.
  • Added support for Windows on Devices/Galileo. #217
  • Added option to force using PPLX on Windows Threadpool instead of PPL on the Concurrency Runtime. Library can be rebuilt using CPPREST_FORCE_PPLX macro.

OSX
  • Merged a pull request to work around a FindOpenSSL.cmake issue, enabling it to find Homebrew's copy.

Websockets (non-WinRT)
  • Fixed a race condition during websocket client destructor which would sometimes result in an AV/Segfault.
  • Added proxy support for Websocket++ based implementation.

http_client
  • Make std::function parameter to http_client::add_handler passed by const reference.

Miscellaneous
  • Merged pull request adding http_constants.dat to be installed with 'make install'.

Tests
  • Fixed race conditions in close_callback_client_from_server
  • Added proper synchronization to test_websocket_server (preventing some race conditions). #305

Commented Unassigned: exception in cpprest120d_2_2!web::hex_char_digit_to_decimal_char+395 [335]

$
0
0
I get the following exception if trying to pass invalid characters as arguments. E.g.:

http://localhost:9576/lucyhttptest?{ .





With exception:
STACK_TEXT:
KERNELBASE!RaiseException+0x68
MSVCR120D!_CxxThrowException+0x116 [f:\dd\vctools\crt\crtw32\eh\throw.cpp @ 154]
cpprest120d_2_2!web::hex_char_digit_to_decimal_char+0x395
cpprest120d_2_2!std::_Debug_pointer<<lambda_ba2697e9ad314c5f3f6c2bafb10744d5> >+0x1f
cpprest120d_2_2!Concurrency::task<web::http::http_request>::_CreateImpl+0x175
cpprest120d_2_2!std::_Func_impl<std::_Callable_obj<<lambda_4b963204d53058a2001fbec56ddaeade>,0>,std::allocator<std::_Func_class<void,unsigned long,unsigned long> >,void,unsigned long,unsigned long>::_Move+0xbd
cpprest120d_2_2!std::_Hash<std::_Umap_traits<web::http::experimental::listener::details::http_listener_impl * __ptr64,std::unique_ptr<web::http::experimental::details::http_windows_server::listener_registration,std::default_delete<web::http::experimental::details::http_windows_server::listener_registration> >,std::_Uhash_compare<web::http::experimental::listener::details::http_listener_impl * __ptr64,std::hash<web::http::experimental::listener::details::http_listener_impl * __ptr64>,std::equal_to<web::http::experimental::listener::details::http_listener_impl * __ptr64> >,std::allocator<std::pair<web::http::experimental::listener::details::http_listener_impl * __ptr64 const,std::unique_ptr<web::http::experimental::details::http_windows_server::listener_registration,std::default_delete<web::http::experimental::details::http_windows_server::listener_registration> > > >,0> >::erase+0x327
cpprest120d_2_2!std::copy<std::_Vector_iterator<std::_Vector_val<std::_Simple_types<unsigned char> > >,stdext::checked_array_iterator<unsigned char * __ptr64> >+0x12a
cpprest120d_2_2!std::_Func_class<void,void * __ptr64>::_Do_alloc<std::_Func_impl<std::_Callable_obj<<lambda_383e03dea2dee782e69b3b00ae082657>,0>,std::allocator<std::_Func_class<void,void * __ptr64> >,void,void * __ptr64>,<lambda_383e03dea2dee782e69b3b00ae082657>,std::allocator<std::_Func_class<void,void * __ptr64> > >+0x39
cpprest120d_2_2!std::_Ptr_base<web::http::oauth1::details::oauth1_handler>::_Decref+0x21
KERNEL32!BasepTpIoCallback+0x49
ntdll!TppIopExecuteCallback+0x175
ntdll!TppWorkerThread+0x818
KERNEL32!BaseThreadInitThunk+0xd
ntdll!RtlUserThreadStart+0x1d


FOLLOWUP_IP:
cpprest120d_2_2!web::hex_char_digit_to_decimal_char+395
00007ff9`53c55985 90 nop

I can repro it with the simplest setup:

// This policy fixes the issue
concurrency::CurrentScheduler::Create(Concurrency::SchedulerPolicy(1, 2, Concurrency::MinConcurrency));

std::wstring url = prot + L"://" + host + L":" + port + L"/lucyhttptest";
std::wcout << "url: " << url << std::endl;

http_listener listener(url);
listener.support(methods::GET, handle_get);

try
{

std::wcout << L"Launching" << std::endl;

listener
.open()
.then([&listener](){std::wcout << L"Start to listen"<<std::endl ; })
.wait();


std::wcout << L"press enter to exit" << std::endl;
std::string line;
std::getline(std::cin, line);

listener.close().wait();

}
catch (exception const & e)
{
wcout << e.what() << endl;
return 1;
}

return 0;

can attach VS2013 project if needed for repro.

Comments: Hi Ruslan, All you should need to do is wrap the URI construction in a try catch if you want to handle this specific error. Or in this case around the http_listener constructor since you are passing a string which in turn calls the URI constructor. Steve

New Post: Creating a static library for Casablanca C++ rest SDK 2.3

$
0
0
Are you linking the C++ REST SDK against your other C++ application? Try adding the NuGet package to that application as well.

Updated Release: C++ Rest SDK 2.5.0

$
0
0
Android
  • Fixed issue in CMakeLists.txt where parenthesis were incorrectly used instead of brackets.
  • Fixed issue in CMakeLists.txt where pplxlinux.cpp source file was missing.
  • Added Android TestRunner packing androidproj to build.

Windows
  • Fixed several code analysis warnings.
  • Updating NuGet package for missing OpenSSL license, also patched 2.4.0's NuGet package.
  • Fixed not working on XP issue because of crypto API. #331, #334
  • Fixed several functions missing an explicit calling convention. This caused problems if you changed the calling convention from the cdecl.
  • Added support for Windows on Devices/Galileo. #217
  • Added option to force using PPLX on Windows Threadpool instead of PPL on the Concurrency Runtime. Library can be rebuilt using CPPREST_FORCE_PPLX macro.

OSX
  • Merged a pull request to work around a FindOpenSSL.cmake issue, enabling it to find Homebrew's copy.

Websockets (non-WinRT)
  • Fixed a race condition during websocket client destructor which would sometimes result in an AV/Segfault.
  • Added proxy support for Websocket++ based implementation.

http_client
  • Make std::function parameter to http_client::add_handler passed by const reference.
  • Fixed invalid check in WinHTTP based implementation causing autologon security level to be high if credentials are not provided.

Miscellaneous
  • Merged pull request adding http_constants.dat to be installed with 'make install'.

Tests
  • Fixed race conditions in close_callback_client_from_server
  • Added proper synchronization to test_websocket_server (preventing some race conditions). #305

New Post: Converting strings to string_t

$
0
0
I'm kind of dense when it comes to documentation. I've tried the below approaches:

builder.append_query(U("s"), localseed.to_string_t());

and

wstring qs = utility::to_string_t(localseed);
builder.append_query(U("s"), localseed);

and

builder.append_query(U("s"), utility::to_string_t(localseed));

I get either cast errors or error C2039: 'to_string_t' : is not a member of 'utility'

I didn't see to_string_t used in any of the samples, so I'm unsure of exactly how to invoke it.

New Post: Converting strings to string_t

$
0
0
Durrrr. I need to not look at code when I'm so tired. Typos abound. Fixed it!

Thanks for the help, Steve!

New Post: localhost does not work but 127.0.0.1 does

$
0
0
Hi,

I am trying to combine C++ REST with registering the URL in my application. I think I am tantalisingly close but cannot get to grips with HttpSetServiceConfiguration and its associated code.

I have based my code on this for the time being: https://github.com/JamesDunne/cpphttp/blob/master/cpphttp/cpphttp.cpp

The error I am getting is that HttpSetServiceConfiguration is returning an invalid parameter error. Can anyone tell me why this might be?

Is this the right way to register a url? I am confused about the code required to register a url in an application, and that to reserve a url during installation.
int _tmain(void)
{
    
    utility::string_t port = U("27016");

    utility::string_t address = U("http://localhost:");
    address.append(port);
    
    //***************************************
    // Attempting to register a url
        //***************************************

    std::wstring url_str = L"http://localhost:27016/";


    HTTPAPI_VERSION apiVersion = HTTPAPI_VERSION_2;
    auto result = HttpInitialize(apiVersion, HTTP_INITIALIZE_SERVER, 0);
    if (NO_ERROR != result) return 0;

    std::cout << "HTTP initialized." << std::endl;

    HANDLE reqQueue = 0;
    result = HttpCreateRequestQueue(apiVersion, NULL, NULL, 0, &reqQueue);
    if (NO_ERROR != result)
    {
        cleanup1();
    }
    std::cout << "HTTP request queue created." << std::endl; 
    

    HTTP_SERVER_SESSION_ID serverSessionId = 0;
    result = HttpCreateServerSession(apiVersion, &serverSessionId, 0);
    if (NO_ERROR != result)
    {
        cleanup2(reqQueue);
        cleanup1();
        return 0;
    }
    std::cout << "HTTP server session created." << std::endl; 
    
    HTTP_URL_GROUP_ID urlGroupId = 0;
    result = HttpCreateUrlGroup(serverSessionId, &urlGroupId, 0);
    if (NO_ERROR != result)
    {
        cleanup3(serverSessionId);
        cleanup2(reqQueue);
        cleanup1();
        return 0; 
    }
    std::cout << "Url group created." << std::endl; 
    
    
    result = HttpAddUrlToUrlGroup(urlGroupId, url_str, NULL, 0);
    if (NO_ERROR != result) 
    {
        cleanup4(urlGroupId);
        cleanup3(serverSessionId);
        cleanup2(reqQueue);
        cleanup1();
        return 0;
    }
    std::cout << "Url added to group." << std::endl; 

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

    
    HTTP_SERVICE_CONFIG_IP_LISTEN_PARAM ip_listen_param;
    ip_listen_param.pAddress = (PSOCKADDR)&url_str;
    ip_listen_param.AddrLength = sizeof(url_str);
    result = HttpSetServiceConfiguration(reqQueue, HttpServiceConfigIPListenList, &ip_listen_param, sizeof(HTTP_SERVICE_CONFIG_IP_LISTEN_PARAM), NULL);
    if (NO_ERROR != result)
    {
        switch (result)
        {
            case (ERROR_ALREADY_EXISTS) :
                std::cout << "ERROR_ALREADY_EXISTS" << std::endl;
            break;

            case (ERROR_INSUFFICIENT_BUFFER) :
                std::cout << "ERROR_INSUFFICIENT_BUFFER" << std::endl;
            break;

            case (ERROR_INVALID_HANDLE) :
                std::cout << "ERROR_INVALID_HANDLE" << std::endl;
            break;
            
            case (ERROR_INVALID_PARAMETER) :
                std::cout << "ERROR_INVALID_PARAMETER" << std::endl;
            break;

            case (ERROR_NO_SUCH_LOGON_SESSION) :
                std::cout << "ERROR_NO_SUCH_LOGON_SESSION" << std::endl;
            break;
            
            default:
                std::cout << "Other Error" << std::endl;
            break;

        }
        
        
        std::string line;
        std::getline(std::cin, line);
        
        return 0;
    }

        //********************************
        //carry on with casablanca code
       //********************************

       on_initialize(address);
    
    std::string line;
    std::getline(std::cin, line);

    on_shutdown();
    
    return 0;   

New Post: Creating a static library for Casablanca C++ rest SDK 2.3

$
0
0
I understand that adding NuGet package to the application will help my cause but I cannot expect every C++ application to install C++ rest SDK through NuGet package.Is there any alternative way to link ?also how to find out which lib(installed from Nuget package) is my C++ application using? and thanks roschuma for you replies.I really appreciate it.

New Post: localhost does not work but 127.0.0.1 does

$
0
0
Hi andy5739,

I'm not sure if this is your problem but quickly looking at the code I don't think you are initializing the HTTP_SERVICE_CONFIG_IP_LISTEN_PARAM correctly. You are trying to cast a pointer to a std::wstring to a PSOCKADDR and then calling sizeof on the std::string, I don't think either of these are correct. Take a look here for the documentation on PSOCKADDR.

Also since your question here is about HttpSetServiceConfiguration, which isn't part of the C++ REST SDK, I recommend you ask on the Windows forum.

Steve

New Post: localhost does not work but 127.0.0.1 does

$
0
0
Hi andy5739,

I'm not sure if this is your problem but quickly looking at the code I don't think you are initializing the HTTP_SERVICE_CONFIG_IP_LISTEN_PARAM correctly. You are trying to cast a pointer to a std::wstring to a PSOCKADDR and then calling sizeof on the std::string, I don't think either of these are correct. Take a look here for the documentation on PSOCKADDR.

Also since your question here is about HttpSetServiceConfiguration, which isn't part of the C++ REST SDK, I recommend you ask on the Windows forum.

Steve

New Post: Creating a static library for Casablanca C++ rest SDK 2.3

$
0
0
Ok, so I think I'm not understanding what your use case is here.
  • If you're making a library, (such as a DLL or a static lib), other programs which use your library will need to install the C++ REST SDK NuGet package to use your library. They will need to also follow the guidance below for applications.
  • If you're making an application, then you don't need to worry about other C++ applications. You just make sure to copy the cpprest120_2_4.dll file along with your ConsoleApplication1.exe and everything will work fine.
Basically, yes, you can expect every C++ application which wants to use your library to install C++ REST SDK through the NuGet package. You can link your users to our installation instructions page for further guidance on how to do that.

roschuma

New Post: Creating a static library for Casablanca C++ rest SDK 2.3

$
0
0
Ok I also installed C++ rest SDK to my application through NuGet package to use my library(A static library which is built using C++ rest SDK).But still getting those four linker errors.

I have just referenced my newly created lib file and the header file in my new C++ application. Am I missing anything more?

New Post: Problem with Casablanca SDK

$
0
0
I have developed a VC++ listener application using Casablanca SDK. This is the source code.
int _tmain(int argc, _TCHAR* argv[])
{
    __uri_builder uri(L"http://localhost:2001/");__
    http_listener listener(uri.to_uri());
    std::cout << "Welcome to Casablanca" << std::endl;

    CheckOSVersion();

    listener.support(methods::GET, [](http_request req)
    {
        HKEY hKey;
        LONG lRes = RegOpenKeyExW(HKEY_CURRENT_USER, L"SOFTWARE\\Casablanca", 0, KEY_READ, &hKey);

        bool bExistsAndSuccess (lRes == ERROR_SUCCESS);
        bool bDoesNotExistsSpecifically (lRes == ERROR_FILE_NOT_FOUND);

        std::wstring strValueOfBinDir;
        GetStringRegKey(hKey, L"Encryption", strValueOfBinDir, L"1");

        GIDSdkWriteXML();

        http_response response (status_codes::OK);

        response.headers().add(U("Access-Control-Allow-Origin"), U("*"));
        response.set_body(strValueOfBinDir, U("text/html"));

        req.set_request_uri(L"requestpath");
        req.reply(response);
    });

    listener.support(methods::PUT,[](http_request req)
    {
        std::cout << "Serving PUT" << std::endl;
        req.reply(status_codes::OK, U("<html><body><h1>It works!</h1>(Casablanca, that is a POST Request.)</body></html>"), 
            U("text/html"));
    });

    listener.support(methods::POST,[](http_request req)
    {
        std::cout << "Serving POST" << std::endl;
        req.extract_string(true).then([req](utility::string_t body)
        {
            std::wcout << body << std::endl;
            //req.reply(status_codes::OK, U("<html><body>Received.</body></html>"), U("text/html"));
        });
    }); 

    listener.open().wait();
    fgetc(stdin);
    listener.close().wait();
}
Everything is working fine. But when I change this line
__uri_builder uri(L"http://localhost:2001/");__
Where I replace the localhost with the IP Address, so that the server can be externally accessed. it crashes. Can someone tell me the solution to this?

New Post: Problem with Casablanca SDK

$
0
0
I have developed a VC++ listener application using Casablanca SDK. This is the source code.
int _tmain(int argc, _TCHAR* argv[])
{
    __uri_builder uri(L"http://localhost:2001/");__
    http_listener listener(uri.to_uri());
    std::cout << "Welcome to Casablanca" << std::endl;

    CheckOSVersion();

    listener.support(methods::GET, [](http_request req)
    {
        HKEY hKey;
        LONG lRes = RegOpenKeyExW(HKEY_CURRENT_USER, L"SOFTWARE\\Casablanca", 0, KEY_READ, &hKey);

        bool bExistsAndSuccess (lRes == ERROR_SUCCESS);
        bool bDoesNotExistsSpecifically (lRes == ERROR_FILE_NOT_FOUND);

        std::wstring strValueOfBinDir;
        GetStringRegKey(hKey, L"Encryption", strValueOfBinDir, L"1");

        GIDSdkWriteXML();

        http_response response (status_codes::OK);

        response.headers().add(U("Access-Control-Allow-Origin"), U("*"));
        response.set_body(strValueOfBinDir, U("text/html"));

        req.set_request_uri(L"requestpath");
        req.reply(response);
    });

    listener.support(methods::PUT,[](http_request req)
    {
        std::cout << "Serving PUT" << std::endl;
        req.reply(status_codes::OK, U("<html><body><h1>It works!</h1>(Casablanca, that is a POST Request.)</body></html>"), 
            U("text/html"));
    });

    listener.support(methods::POST,[](http_request req)
    {
        std::cout << "Serving POST" << std::endl;
        req.extract_string(true).then([req](utility::string_t body)
        {
            std::wcout << body << std::endl;
            //req.reply(status_codes::OK, U("<html><body>Received.</body></html>"), U("text/html"));
        });
    }); 

    listener.open().wait();
    fgetc(stdin);
    listener.close().wait();
}
Everything is working fine. But when I change this line
__uri_builder uri(L"http://localhost:2001/");__
Where I replace the localhost with the IP Address, so that the server can be externally accessed. it crashes. Can someone tell me the solution to this?

New Post: Problem with Casablanca SDK

$
0
0
I have developed a VC++ listener application using Casablanca SDK. This is the source code.
int _tmain(int argc, _TCHAR* argv[])
{
    __uri_builder uri(L"http://localhost:2001/");__
    http_listener listener(uri.to_uri());
    std::cout << "Welcome to Casablanca" << std::endl;

    CheckOSVersion();

    listener.support(methods::GET, [](http_request req)
    {
        HKEY hKey;
        LONG lRes = RegOpenKeyExW(HKEY_CURRENT_USER, L"SOFTWARE\\Casablanca", 0, KEY_READ, &hKey);

        bool bExistsAndSuccess (lRes == ERROR_SUCCESS);
        bool bDoesNotExistsSpecifically (lRes == ERROR_FILE_NOT_FOUND);

        std::wstring strValueOfBinDir;
        GetStringRegKey(hKey, L"Encryption", strValueOfBinDir, L"1");

        GIDSdkWriteXML();

        http_response response (status_codes::OK);

        response.headers().add(U("Access-Control-Allow-Origin"), U("*"));
        response.set_body(strValueOfBinDir, U("text/html"));

        req.set_request_uri(L"requestpath");
        req.reply(response);
    });

    listener.support(methods::PUT,[](http_request req)
    {
        std::cout << "Serving PUT" << std::endl;
        req.reply(status_codes::OK, U("<html><body><h1>It works!</h1>(Casablanca, that is a POST Request.)</body></html>"), 
            U("text/html"));
    });

    listener.support(methods::POST,[](http_request req)
    {
        std::cout << "Serving POST" << std::endl;
        req.extract_string(true).then([req](utility::string_t body)
        {
            std::wcout << body << std::endl;
            //req.reply(status_codes::OK, U("<html><body>Received.</body></html>"), U("text/html"));
        });
    }); 

    listener.open().wait();
    fgetc(stdin);
    listener.close().wait();
}
Everything is working fine. But when I change this line
__uri_builder uri(L"http://localhost:2001/");__
Where I replace the localhost with the IP Address, so that the server can be externally accessed. it crashes. Can someone tell me the solution to this?

New Post: Converting strings to string_t

$
0
0
Steve it would be really really really nice to use utf8 for all platforms. it is a bit of a mess to ensure convert everything that goes in and out of the sdk to utf-16 on windows.
http://utf8everywhere.org/ have some very good arguments...

eske

New Post: Problem with Casablanca SDK

$
0
0
Hi maverick786us,

What do you mean by crashes, is an exception throw? If so what is the message of the exception? Can you share the exact string you are using to construct the uri_builder?

Here is a similar discussion about using localhost vs. '*' on Windows.

Thanks,
Steve

Commented Feature: Windows - support for utf-8, single byte strings [239]

$
0
0
On Windows string_t is a 2 byte character, assumed UTF-16 string in the C++ Rest SDK. For some data critical areas we could make API overloads that work with std::string or return std::string.

This has come up numerous times from customers, internal and external.

Steve
Comments: In the development branch I added extract_utf8string and extract_utf16string overloads to http_request and http_response. It is now possible to deal with request/response bodies in UTF-8 and UTF-16 regardless of the platform. This covers all locations of unbounded user data in the HTTP portions of the library. Other areas would probably benefit from UTF-8 overloads on Windows.

Updated Release: C++ Rest SDK 2.5.0

$
0
0
Android
  • Fixed issue in CMakeLists.txt where parenthesis were incorrectly used instead of brackets.
  • Fixed issue in CMakeLists.txt where pplxlinux.cpp source file was missing.
  • Added Android TestRunner packing androidproj to build.

Windows
  • Fixed several code analysis warnings.
  • Updating NuGet package for missing OpenSSL license, also patched 2.4.0's NuGet package.
  • Fixed not working on XP issue because of crypto API. #331, #334
  • Fixed several functions missing an explicit calling convention. This caused problems if you changed the calling convention from the cdecl.
  • Added support for Windows on Devices/Galileo. #217
  • Added option to force using PPLX on Windows Threadpool instead of PPL on the Concurrency Runtime. Library can be rebuilt using CPPREST_FORCE_PPLX macro.

OSX
  • Merged a pull request to work around a FindOpenSSL.cmake issue, enabling it to find Homebrew's copy.

Websockets (non-WinRT)
  • Fixed a race condition during websocket client destructor which would sometimes result in an AV/Segfault.
  • Added proxy support for Websocket++ based implementation.

http_client
  • Make std::function parameter to http_client::add_handler passed by const reference.
  • Fixed invalid check in WinHTTP based implementation causing autologon security level to be high if credentials are not provided.
  • Added extract_utf8string and extract_utf16string to http_request and http_response classes. This allows uses either UTF-8 or UTF-16, instead of utility::string_t, more efficiently regardless of the platform.

Miscellaneous
  • Merged pull request adding http_constants.dat to be installed with 'make install'.

Tests
  • Fixed race conditions in close_callback_client_from_server
  • Added proper synchronization to test_websocket_server (preventing some race conditions). #305

New Post: Converting strings to string_t

$
0
0
Hi eske,

We felt it was important to have UTF-16 available as an easy option on Windows, however I do see the merits in having UTF-8 working regardless of the platform. This is tracked in the following issue.

We can't break all existing programs and realistically we won't be going and adding overloads supporting both UTF-8 and UTF-16 for each API in the library. However for some areas of the library this would be possible. Particularly APIs that deal with unbounded user data are good candidates, to avoid additional conversions/copies. A little bit of progress has been made in this area. In the 2.3.0 release we added http_client::request overloads to work with UTF-8 on Windows. In the development branch I've added http_response::extract_utf8string and http_response::extract_utf16string for handling response bodies, this will be in release 2.5.0.

If you have made changes to improve any of the APIs for UTF-8 on Windows let me know, it would be good to have them contributed back into the library.

Thanks,
Steve
Viewing all 4845 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>