cookie_interface.c
Download cookie_interface.c raw
/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) 1998 - 2017, Daniel Stenberg<EMAIL_ADDRESS>et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * ***************************************************************************/ /* <DESC> * Import and export cookies with COOKIELIST. * </DESC> */ #include <stdio.h> #include <string.h> #include <stdlib.h> #include <errno.h> #include <time.h> #include <curl/curl.h> static void print_cookies(CURL *curl) { CURLcode res; struct curl_slist *cookies; struct curl_slist *nc; int i; printf("Cookies, curl knows:\n"); res = curl_easy_getinfo(curl, CURLINFO_COOKIELIST, &cookies); if(res != CURLE_OK) { fprintf(stderr, "Curl curl_easy_getinfo failed: %s\n", curl_easy_strerror(res)); exit(1); } nc = cookies; i = 1; while(nc) { printf("[%d]: %s\n", i, nc->data); nc = nc->next; i++; } if(i == 1) { printf("(none)\n"); } curl_slist_free_all(cookies); } int main(void) { CURL *curl; CURLcode res; curl_global_init(CURL_GLOBAL_ALL); curl = curl_easy_init(); if(curl) { char nline[256]; curl_easy_setopt(curl, CURLOPT_URL, "http://www.example.com/"); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); curl_easy_setopt(curl, CURLOPT_COOKIEFILE, ""); /* start cookie engine */ res = curl_easy_perform(curl); if(res != CURLE_OK) { fprintf(stderr, "Curl perform failed: %s\n", curl_easy_strerror(res)); return 1; } print_cookies(curl); printf("Erasing curl's knowledge of cookies!\n"); curl_easy_setopt(curl, CURLOPT_COOKIELIST, "ALL"); print_cookies(curl); printf("-----------------------------------------------\n" "Setting a cookie \"PREF\" via cookie interface:\n"); #ifdef WIN32 #define snprintf _snprintf #endif /* Netscape format cookie */ snprintf(nline, sizeof(nline), "%s\t%s\t%s\t%s\t%lu\t%s\t%s", ".example.com", "TRUE", "/", "FALSE", (unsigned long)time(NULL) + 31337UL, "PREF", "hello example, i like you very much!"); res = curl_easy_setopt(curl, CURLOPT_COOKIELIST, nline); if(res != CURLE_OK) { fprintf(stderr, "Curl curl_easy_setopt failed: %s\n", curl_easy_strerror(res)); return 1; } /* HTTP-header style cookie. If you use the Set-Cookie format and don't specify a domain then the cookie is sent for any domain and will not be modified, likely not what you intended. Starting in 7.43.0 any-domain cookies will not be exported either. For more information refer to the CURLOPT_COOKIELIST documentation. */ snprintf(nline, sizeof(nline), "Set-Cookie: OLD_PREF=3d141414bf4209321; " "expires=Sun, 17-Jan-2038 19:14:07 GMT; path=/; domain=.example.com"); res = curl_easy_setopt(curl, CURLOPT_COOKIELIST, nline); if(res != CURLE_OK) { fprintf(stderr, "Curl curl_easy_setopt failed: %s\n", curl_easy_strerror(res)); return 1; } print_cookies(curl); res = curl_easy_perform(curl); if(res != CURLE_OK) { fprintf(stderr, "Curl perform failed: %s\n", curl_easy_strerror(res)); return 1; } curl_easy_cleanup(curl); } else { fprintf(stderr, "Curl init failed!\n"); return 1; } curl_global_cleanup(); return 0; }


Element one
Element two
Element three
Element four
Element five
Element six
Element seven
Element eight


Introduction
The WNS Recipe provides a simple managed API for authenticating against WNS, constructing payloads and posting notifications to Windows Push Notification Services (WNS).
Using the WNS Recipe
After installing this NuGet, you will have a WnsRecipe assembly added to your project references.
To send notifications using WNS, you must first register your application at the Windows Push Notifications & Live Connect portal to obtain Package Security Identifier (SID) and a secret key that your cloud service uses to authenticate with WNS.
An application receives push notifications by requesting a notification channel from WNS, which returns a channel URI that the application then registers with your cloud service.
In your cloud service, the WnsAccessTokenProvider authenticates with WNS by providing its credentials, the package SID and secret key, and receives in return an access token that the provider caches and can reuse for multiple notification requests.
The cloud service constructs a notification request by filling out a template class that contains the information that will be sent with the notification, including text and image references.
Using the channel URI of a registered client, the cloud service can then send a notification whenever it has an update for the user.
Note that to have the Send method available, you need to add a reference to the NotificationsExtensions namespace.
Diagnostics
To ease troubleshooting, the WNS Recipe has been instrumented to write trace information by taking advantage of the diagnostics support provided by the .NET Framework.
By default, tracing is disabled. To enable it, you first need to configure the trace source used by the recipe by enabling one or more trace listeners and then set the level of information included in the trace by choosing from the levels: error, warning, information, or verbose.
For example, at the error level, the component logs any failures in sending notifications, including status information, request and response sent to WNS, as well as any HTTP headers. Increasing the level to Information also records any notifications that are sent successfully.
Your choice of listener will vary based on the environment where the application runs. For example, not all listeners can be used in the Windows Azure environment or some require special considerations.
You can configure the trace source programmatically, by initializing the TraceSource property of the WnsDiagnostics class.
Otherwise, the trace source can be configured using the application configuration file. The WNS Recipe NuGet adds a new WNSRecipe source in the system.diagnostics section of the configuration file of your project. To complete the configuration, set the switchValue to choose the trace level and add one or more trace listeners, for example, by uncommenting one of the entries that have already been provided.
Note that some trace listeners in this section may require additional configuration steps such as configuring output file location, setting file permissions, creating event sources, etc. For additional information on trace listener configuration, please refer to Configuring Trace Listeners and Trace Listeners.
To complete the configuration steps, you must enable tracing by calling the Enable method of the WnsDiagnostics class.
By default, the Enable method sets up a default trace source named WNSRecipe. When the component is executed in the Windows Azure environment, it will also configure itself to monitor a service configuration setting that controls the level of tracing and is named by default WnsRecipeDiagnosticsTraceLevel. This feature allows you to simply upload a new ServiceConfiguration.cscfg file to your Windows Azure service to change the level of information included in the trace logs without redeploying or stopping the service.
Optionally, the Enable method allows you to choose a different name for the trace source used by the WNS Recipe, for example, to share the same trace source used by other components in your application, as well as changing the name of the service configuration setting that controls the trace level. For example, the following code enables the WNS Recipe to use the WNSDiagnostics trace source and sets WnsTraceLevel as the name of the setting in the ServiceConfiguration.cscfg file that controls the trace level.


Toggle navigation
Log Out
Postcard
| Lorem Ipsum
STEPS:
1. Front
2. Back
3. Proof
4. Export PRESS PDF
Next


Methods
(inner) handleInspireCreate(request, response, next) → {Promise}
This route handler takes the Slack User ID and command text from the request
and creates a new inspiration in the user's library, saving it to the database.
Parameters:
| Name | Type | Description |
|---|---|---|
request |
object | |
response |
object | |
next |
function |
- Source:
Returns:
- Type
- Promise
(inner) handleInspireDelete(request, response, next) → {Promise}
This route handler takes the Slack User ID and command text from the request
and deletes the inspiration with the matching ID in the user's library from
the database.
Parameters:
| Name | Type | Description |
|---|---|---|
request |
object | |
response |
object | |
next |
function |
- Source:
Returns:
- Type
- Promise
(inner) handleInspireHelp(request, response)
This route handler simply sends usage instructions back to the Slack user
via the response.
Parameters:
| Name | Type | Description |
|---|---|---|
request |
object | |
response |
object |
- Source:
(inner) handleInspireMe(request, response, next) → {Promise}
This route handler takes the Slack User ID from the request and sends
a random inspiration object from that user's library to the "inspirations"
channel in the bot's Slack workspace.
Parameters:
| Name | Type | Description |
|---|---|---|
request |
object | |
response |
object | |
next |
function |
- Source:
Returns:
- Type
- Promise
(inner) handleInspireScheduled(request, response, next) → {Promise}
This route handler grabs a random inspiration from the database and sends
it to the "inspirations" channel in the bot's Slack workspace.
Parameters:
| Name | Type | Description |
|---|---|---|
request |
object | |
response |
object | |
next |
function |
- Source:
Returns:
- Type
- Promise
(inner) handleInspireUpdate(request, response, next) → {Promise}
This route handler takes the Slack User ID and command text from the request
and updates the inspiration with the matching ID in the user's library,
saving the updated object to the database.
Parameters:
| Name | Type | Description |
|---|---|---|
request |
object | |
response |
object | |
next |
function |
- Source:
Returns:
- Type
- Promise