20 int prowl_push_msg(
char* api_key,
int priority,
char* application_name,
char* event_name,
char* description)
24 char* response = NULL;
26 static int wsa_init = 0;
38 if (WSAStartup(MAKEWORD(2, 2), &wsad) != 0)
40 fprintf(stderr,
"Failed to initialize winsock (%d)\n", GetLastError());
45 printf(
"Prowl [debug]: Initialized Winsock\n");
56 printf(
"Prowl [debug]: Connected\n");
59 sprintf(buffer,
"GET /publicapi/add?apikey=%s&priority=%d&application=%s&event=%s&description=%s\r\nHost: %s\r\n\r\n",
60 api_key, priority, application_name, event_name, description,
HOSTNAME);
61 if (SSL_write(c->
ssl_handle, buffer, strlen(buffer)) <= 0)
63 fprintf(stderr,
"Failed to write buffer to SSL connection\n");
64 ERR_print_errors_fp(stderr);
69 printf(
"Prowl [debug]: Written buffer: %s\n", buffer);
75 OutputDebugString(
"Prowl [debug]: server response:");
76 if (response != NULL) printf(
"%s\n", response);
82 free(application_name);
92 char* start = strstr(response,
"<prowl>");
95 if (start == NULL)
return -1;
97 start = strstr(start,
"code");
100 if (start == NULL)
return -1;
103 if (sscanf(start,
"code=\"%d\"", &code) != 1)
return -1;
118 SSL_load_error_strings();
120 c->
ssl_context = SSL_CTX_new(SSLv23_client_method());
121 if (c->
ssl_context == NULL) ERR_print_errors_fp(stderr);
124 if (c->
ssl_handle == NULL) ERR_print_errors_fp(stderr);
126 SSL_CTX_set_verify(c->
ssl_context, SSL_VERIFY_PEER, SSL_VERIFY_NONE);
130 if (SSL_connect(c->
ssl_handle) != 1) ERR_print_errors_fp(stderr);
133 printf(
"Prowl [debug]: SSL Handshake successful\n");
139 fprintf(stderr,
"Failed to retrieve a valid connected socket\n");
142 perror(
"Prowl: Failed to retrieve connected socket");
151 SOCKET s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
152 struct sockaddr_in server;
153 struct hostent* host = gethostbyname(
HOSTNAME);
158 fprintf(stderr,
"Could not create socket (%d)\n", WSAGetLastError());
161 perror(
"Prowl: Could not create socket");
168 fprintf(stderr,
"Could not retrieve host by name (%d)\n", WSAGetLastError());
171 perror(
"Prowl: Could not retrieve host by name");
175 memset(&server, 0,
sizeof(
struct sockaddr_in));
176 server.sin_family = AF_INET;
178 server.sin_addr = *(
struct in_addr*)host->h_addr_list[0];
180 if (connect(s, (
struct sockaddr*)&server,
sizeof(server)) ==
SOCKET_ERROR)
183 fprintf(stderr,
"Prowl connect error (%d)\n", WSAGetLastError());
186 perror(
"Prowl: connect error");
198 char* retval = (
char*)malloc(size);
200 memset(retval, 0, size);
209 retval = realloc(retval, size + r);
210 strcat(retval, buffer);
232 static char hex[] =
"0123456789abcdef";
233 return hex[code & 15];
239 char* buf = (
char*)malloc(strlen(str) * 3 + 1);
244 if (isalnum(*pstr) || *pstr ==
'-' || *pstr ==
'_' || *pstr ==
'.' || *pstr ==
'~')
static char * prowl_url_encode(char *str)
static SOCKET prowl_tcp_connect()
static prowl_connection * prowl_ssl_connect()
int prowl_push_msg(char *api_key, int priority, char *application_name, char *event_name, char *description)
static void prowl_ssl_disconnect(prowl_connection *c)
#define closesocket(socket)
static char * prowl_ssl_read(prowl_connection *c)
static int prowl_get_response_code(char *response)
static char prowl_int_to_hex(char code)