19 char* tmp = (
char*)malloc(len * 2 + 1);
20 memset(tmp, 0, len * 2 + 1);
21 for (l = 0, n = 0; l < len; l++) {
36 if( WSAStartup( MAKEWORD( 2 , 0 ) , &wsaData) != 0 )
61 char* salt = (
char*)malloc(count + 1);
63 for (n = 0; n <
count; n++) salt[n] = (((
int)rand()) % 255) + 1;
73 memset(md5tmp, 0,
sizeof(md5tmp));
92 char* authheader = NULL;
99 authheader = (
char*)malloc(strlen(keyhash) + strlen(salthash) + 7);
100 sprintf(authheader,
" MD5:%s.%s", keyhash, salthash);
109 int growl_tcp_register(
const char *
const server ,
const char *
const appname ,
const char **
const notifications ,
const int notifications_count ,
110 const char *
const password,
const char*
const icon )
119 if (sock == -1)
goto leave;
121 growl_tcp_write(sock,
"GNTP/1.0 REGISTER NONE %s", authheader ? authheader :
"");
127 for(i=0;i<notifications_count;i++)
130 growl_tcp_write(sock,
"Notification-Display-Name: %s", notifications[i]);
137 int len = strlen(line);
139 if (strncmp(line,
"GNTP/1.0 -ERROR", 15) == 0) {
140 fprintf(stderr,
"failed to register notification\n");
151 if (authheader) free(authheader);
153 return (sock == 0) ? 0 : -1;
157 int growl_tcp_notify(
const char *
const server,
const char *
const appname,
const char *
const notify,
const char *
const title,
const char *
const message ,
158 const char *
const password,
const char*
const url,
const char*
const icon)
167 if (sock == -1)
goto leave;
169 growl_tcp_write(sock,
"GNTP/1.0 NOTIFY NONE %s", authheader ? authheader :
"");
175 if (url)
growl_tcp_write(sock,
"Notification-Callback-Target: %s", url );
180 int len = strlen(line);
182 if (strncmp(line,
"GNTP/1.0 -ERROR", 15) == 0) {
183 fprintf(stderr,
"failed to post notification\n");
194 if (authheader) free(authheader);
196 return (sock == 0) ? 0 : -1;
201 int growl(
const char *
const server,
const char *
const appname,
const char *
const notify,
const char *
const title,
const char *
const message ,
202 const char *
const icon ,
const char *
const password ,
const char *url )
204 int rc =
growl_tcp_register( server , appname , (
const char **
const)¬ify , 1 , password, icon );
207 rc =
growl_tcp_notify( server, appname, notify, title, message , password, url, icon );
213 void growl_append_md5(
unsigned char *
const data ,
const int data_length ,
const char *
const password )
218 memset(md5tmp, 0,
sizeof(md5tmp));
227 memcpy( data + data_length , md5tmp , 16 );
231 int growl_udp_register(
const char *
const server ,
const char *
const appname ,
const char **
const notifications ,
const int notifications_count ,
const char *
const password )
233 int register_header_length = 22+strlen(appname);
239 uint8_t GROWL_PROTOCOL_VERSION = 1;
240 uint8_t GROWL_TYPE_REGISTRATION = 0;
242 uint16_t appname_length = ntohs(strlen(appname));
243 uint8_t _notifications_count = notifications_count;
244 uint8_t default_notifications_count = notifications_count;
249 for(i=0;i<notifications_count;i++)
251 register_header_length += 3 + strlen(notifications[i]);
253 data = (
unsigned char*)malloc(register_header_length);
254 memset( data , 0 , register_header_length );
258 memcpy( data + pointer , &GROWL_PROTOCOL_VERSION , 1 );
260 memcpy( data + pointer , &GROWL_TYPE_REGISTRATION , 1 );
262 memcpy( data + pointer , &appname_length , 2 );
264 memcpy( data + pointer , &_notifications_count , 1 );
266 memcpy( data + pointer, &default_notifications_count , 1 );
268 sprintf( (
char*)data + pointer ,
"%s" , appname );
269 pointer += strlen(appname);
271 for(i=0;i<notifications_count;i++)
273 uint16_t notify_length = ntohs(strlen(notifications[i]));
274 memcpy( data + pointer, ¬ify_length , 2 );
276 sprintf( (
char*)data + pointer ,
"%s" , notifications[i] );
277 pointer += strlen(notifications[i]);
280 for(j=0;j<notifications_count;j++)
282 memcpy( data + pointer , &j , 1 );
295 int growl_udp_notify(
const char *
const server,
const char *
const appname,
const char *
const notify,
const char *
const title,
const char *
const message ,
296 const char *
const password )
298 int notify_header_length = 28 + strlen(appname)+strlen(notify)+strlen(message)+strlen(title);
299 unsigned char *data = (
unsigned char*)malloc(notify_header_length);
303 uint8_t GROWL_PROTOCOL_VERSION = 1;
304 uint8_t GROWL_TYPE_NOTIFICATION = 1;
307 uint16_t appname_length = ntohs(strlen(appname));
308 uint16_t notify_length = ntohs(strlen(notify));
309 uint16_t title_length = ntohs(strlen(title));
310 uint16_t message_length = ntohs(strlen(message));
313 memset( data , 0 , notify_header_length );
316 memcpy( data + pointer , &GROWL_PROTOCOL_VERSION , 1 );
318 memcpy( data + pointer , &GROWL_TYPE_NOTIFICATION , 1 );
320 memcpy( data + pointer , &flags , 2 );
322 memcpy( data + pointer , ¬ify_length , 2 );
324 memcpy( data + pointer , &title_length , 2 );
326 memcpy( data + pointer , &message_length , 2 );
328 memcpy( data + pointer , &appname_length , 2 );
330 strcpy( (
char*)data + pointer , notify );
331 pointer += strlen(notify);
332 strcpy( (
char*)data + pointer , title );
333 pointer += strlen(title);
334 strcpy( (
char*)data + pointer , message );
335 pointer += strlen(message);
336 strcpy( (
char*)data + pointer , appname );
337 pointer += strlen(appname);
350 int growl_udp(
const char *
const server,
const char *
const appname,
const char *
const notify,
const char *
const title,
const char *
const message ,
351 const char *
const icon ,
const char *
const password ,
const char *url )
353 int rc =
growl_udp_register( server , appname , (
const char **
const)¬ify , 1 , password );
356 rc =
growl_udp_notify( server, appname, notify, title, message , password );
364 void GrowlNotify(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine,
int nCmdShow) {
365 char* server =
"127.0.0.1:23053";
366 char* password = NULL;
367 char* appname =
"gntp-send";
368 char* notify =
"gntp-send notify";
370 char* message = NULL;
373 char* first = strdup(lpszCmdLine);
377 if (WSAStartup(MAKEWORD(2, 0), &wsaData) != 0)
return;
378 #define SKIP(x) while (*x && *x != ' ') x++; if (*x == ' ') *x++ = 0;
379 server = ptr; SKIP(ptr);
380 appname = ptr; SKIP(ptr);
381 notify = ptr; SKIP(ptr);
382 title = ptr; SKIP(ptr);
383 message = ptr; SKIP(ptr);
384 icon = ptr; SKIP(ptr);
385 url = ptr; SKIP(ptr);
386 rc =
growl(server,appname,notify,title,message,icon,password,url);
int growl_udp_register(const char *const server, const char *const appname, const char **const notifications, const int notifications_count, const char *const password)
int growl_udp_notify(const char *const server, const char *const appname, const char *const notify, const char *const title, const char *const message, const char *const password)
void md5_update(md5_context *ctx, const uint8_t *input, uint32_t length)
void char * growl_tcp_read(int sock)
char * gen_salt_alloc(int count)
int growl_udp(const char *const server, const char *const appname, const char *const notify, const char *const title, const char *const message, const char *const icon, const char *const password, const char *url)
int growl_tcp_register(const char *const server, const char *const appname, const char **const notifications, const int notifications_count, const char *const password, const char *const icon)
char * gen_password_hash_alloc(const char *password, const char *salt)
void growl_tcp_close(int sock)
void md5_starts(md5_context *ctx)
char * growl_generate_authheader_alloc(const char *const password)
void md5_finish(md5_context *ctx, uint8_t digest[16])
int growl_tcp_notify(const char *const server, const char *const appname, const char *const notify, const char *const title, const char *const message, const char *const password, const char *const url, const char *const icon)
void growl_tcp_write(int sock, const char *const format,...) __attribute__((format(printf
static const char hex_table[]
int growl_tcp_open(const char *server)
static char * string_to_hex_alloc(const char *str, int len)
int growl(const char *const server, const char *const appname, const char *const notify, const char *const title, const char *const message, const char *const icon, const char *const password, const char *url)
void growl_append_md5(unsigned char *const data, const int data_length, const char *const password)
Uint count(const RangeT &range)
Count the elements in a range.
int growl_tcp_datagram(const char *server, const unsigned char *data, const int data_length)