From: Piotr S. <ps...@us...> - 2009-09-17 12:05:39
|
Update of /cvsroot/ayttm/ayttm/modules/livejournal In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv12682/modules/livejournal Modified Files: lj.c lj.h lj_httplib.c lj_httplib.h Log Message: reformatted source code Index: lj.c =================================================================== RCS file: /cvsroot/ayttm/ayttm/modules/livejournal/lj.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- lj.c 19 Aug 2009 04:07:04 -0000 1.5 +++ lj.c 17 Sep 2009 12:04:59 -0000 1.6 @@ -49,30 +49,28 @@ ******************************************************************************/ /* Module defines */ #ifndef USE_POSIX_DLOPEN - #define plugin_info lj_LTX_plugin_info - #define SERVICE_INFO lj_LTX_SERVICE_INFO - #define module_version lj_LTX_module_version +#define plugin_info lj_LTX_plugin_info +#define SERVICE_INFO lj_LTX_SERVICE_INFO +#define module_version lj_LTX_module_version #endif - /* Function Prototypes */ static int plugin_init(); static int plugin_finish(); -struct service_callbacks * query_callbacks(); +struct service_callbacks *query_callbacks(); static int is_setting_state = 0; static int ref_count = 0; -static char lj_url[MAX_PREF_LEN]="http://www.livejournal.com/interface/flat"; -static char lj_host[MAX_PREF_LEN]=""; +static char lj_url[MAX_PREF_LEN] = "http://www.livejournal.com/interface/flat"; +static char lj_host[MAX_PREF_LEN] = ""; static int lj_port; static char lj_path[MAX_PREF_LEN]; static int do_lj_debug = 0; /* Module Exports */ -PLUGIN_INFO plugin_info = -{ +PLUGIN_INFO plugin_info = { PLUGIN_SERVICE, "LiveJournal", "Ayttm client for LiveJournal (http://www.livejournal.com/)", @@ -83,17 +81,22 @@ plugin_finish, NULL }; + struct service SERVICE_INFO = { "LiveJournal", -1, SERVICE_CAN_OFFLINEMSG | /* all messages are offline */ - SERVICE_CAN_FILETRANSFER, /* true so i can prevent file - transfer altogether */ + SERVICE_CAN_FILETRANSFER, /* true so i can prevent file + transfer altogether */ NULL }; + /* End Module Exports */ -unsigned int module_version() {return CORE_VERSION;} +unsigned int module_version() +{ + return CORE_VERSION; +} static int plugin_init() { @@ -126,9 +129,8 @@ * End Module Code ******************************************************************************/ - #ifdef __STDC__ -int LJ_DEBUGLOG(char *fmt,...) +int LJ_DEBUGLOG(char *fmt, ...) #else int LJ_DEBUGLOG(fmt, va_alist) char *fmt; @@ -149,7 +151,6 @@ return 0; } - #define LOG(x) if(do_lj_debug) { LJ_DEBUGLOG("%s:%d: ", __FILE__, __LINE__); \ LJ_DEBUGLOG x; \ LJ_DEBUGLOG("\n"); } @@ -158,25 +159,27 @@ LJ_DEBUGLOG x; \ LJ_DEBUGLOG("\n"); } - #define LJ_MSG_COLOUR "#20b2aa" -static char *ay_lj_get_color(void) { return LJ_MSG_COLOUR; } +static char *ay_lj_get_color(void) +{ + return LJ_MSG_COLOUR; +} enum lj_status_code { LJ_STATUS_ONLINE, LJ_STATUS_OFFLINE }; - + typedef struct lj_account_data { int status; /* always online */ } lj_account_data; typedef struct lj_local_account { char password[MAX_PREF_LEN]; - int status; /* always online */ + int status; /* always online */ int connect_progress_tag; LList *buddies; char last_update[255]; int poll_timeout_tag; - int poll_interval; /* 0 means don't poll */ + int poll_interval; /* 0 means don't poll */ } lj_local_account; static void lj_account_prefs_init(eb_local_account *ela) @@ -200,12 +203,12 @@ } -static eb_local_account *ay_lj_read_local_account_config(LList * pairs) +static eb_local_account *ay_lj_read_local_account_config(LList *pairs) { eb_local_account *ela; lj_local_account *lla; - if(!pairs) { + if (!pairs) { WARNING(("ay_lj_read_local_account_config: pairs == NULL")); return NULL; } @@ -226,7 +229,7 @@ return ela; } -static LList *ay_lj_write_local_config(eb_local_account * account) +static LList *ay_lj_write_local_config(eb_local_account *account) { return eb_input_to_value_pair(account->prefs); } @@ -241,34 +244,42 @@ return states; } -static int lj_find_and_handle_errors(int success, eb_local_account *ela, LList *pairs) +static int lj_find_and_handle_errors(int success, eb_local_account *ela, + LList *pairs) { - char buff[1024]="", *str; - switch(success) { - case LJ_HTTP_NETWORK: - snprintf(buff, sizeof(buff), _("Could not connect %s to LiveJournal service.\n\nThere was a network error."), ela->handle); - break; - case LJ_HTTP_NOK: - snprintf(buff, sizeof(buff), _("Could not connect %s to LiveJournal service.\n\nThe server returned an unknown HTTP error."), ela->handle); - break; - case LJ_HTTP_OK: - str = value_pair_get_value(pairs, "success"); - if(!str) { - snprintf(buff, sizeof(buff), - _("Incomplete read from LiveJournal service.\n\nData lost.")); - } else if(strcmp(str, "OK") != 0) { - free(str); - str = value_pair_get_value(pairs, "errmsg"); - snprintf(buff, sizeof(buff), - _("%s!\n\n%s"), ela->handle, str); - free(str); - } - - break; + char buff[1024] = "", *str; + switch (success) { + case LJ_HTTP_NETWORK: + snprintf(buff, sizeof(buff), + _ + ("Could not connect %s to LiveJournal service.\n\nThere was a network error."), + ela->handle); + break; + case LJ_HTTP_NOK: + snprintf(buff, sizeof(buff), + _ + ("Could not connect %s to LiveJournal service.\n\nThe server returned an unknown HTTP error."), + ela->handle); + break; + case LJ_HTTP_OK: + str = value_pair_get_value(pairs, "success"); + if (!str) { + snprintf(buff, sizeof(buff), + _ + ("Incomplete read from LiveJournal service.\n\nData lost.")); + } else if (strcmp(str, "OK") != 0) { + free(str); + str = value_pair_get_value(pairs, "errmsg"); + snprintf(buff, sizeof(buff), + _("%s!\n\n%s"), ela->handle, str); + free(str); + } + + break; } - if(buff[0]) { - ay_do_warning( _("LiveJournal Error"), buff); + if (buff[0]) { + ay_do_warning(_("LiveJournal Error"), buff); return 1; } else { return 0; @@ -282,11 +293,11 @@ return lla->status; } -static void ay_lj_set_idle(eb_local_account * account, int idle) +static void ay_lj_set_idle(eb_local_account *account, int idle) { } -static void ay_lj_set_away(eb_local_account * account, char * message) +static void ay_lj_set_away(eb_local_account *account, char *message) { } @@ -307,22 +318,22 @@ static void _ay_lj_user_added(int success, eb_local_account *ela, LList *pairs) { - int nadded=0, i; + int nadded = 0, i; char *str, buff[1024]; eb_account *ea; lj_find_and_handle_errors(success, ela, pairs); str = value_pair_get_value(pairs, "friends_added"); - if(str) { + if (str) { nadded = atoi(str); free(str); } - for(i=1; i<=nadded; i++) { + for (i = 1; i <= nadded; i++) { snprintf(buff, sizeof(buff), "friend_%d_user", i); str = value_pair_get_value(pairs, buff); - if(!str) + if (!str) continue; ea = find_account_with_ela(str, ela); @@ -331,14 +342,14 @@ snprintf(buff, sizeof(buff), "friend_%d_name", i); str = value_pair_get_value(pairs, buff); - if(!ea || !str) + if (!ea || !str) continue; - if(strcmp(ea->account_contact->nick, str)) + if (strcmp(ea->account_contact->nick, str)) rename_contact(ea->account_contact, str); free(str); } - + } static void ay_lj_add_user(eb_account *ea) @@ -347,8 +358,9 @@ lj_local_account *lla = ela->protocol_local_account_data; char buff[1024]; - snprintf(buff, sizeof(buff), "mode=editfriends&user=%s&password=%s&editfriend_add_1_user=%s", - ela->handle, lla->password, ea->handle); + snprintf(buff, sizeof(buff), + "mode=editfriends&user=%s&password=%s&editfriend_add_1_user=%s", + ela->handle, lla->password, ea->handle); send_http_request(buff, _ay_lj_user_added, ela); } @@ -359,13 +371,14 @@ lj_local_account *lla = ela->protocol_local_account_data; char buff[1024]; - snprintf(buff, sizeof(buff), "mode=editfriends&user=%s&password=%s&editfriend_delete_%s", - ela->handle, lla->password, ea->handle); + snprintf(buff, sizeof(buff), + "mode=editfriends&user=%s&password=%s&editfriend_delete_%s", + ela->handle, lla->password, ea->handle); send_http_request(buff, NULL, NULL); } -static eb_account *ay_lj_read_account_config(eb_account *ea, LList * config) +static eb_account *ay_lj_read_account_config(eb_account *ea, LList *config) { lj_account_data *lad = calloc(1, sizeof(lj_account_data)); lad->status = LJ_STATUS_OFFLINE; @@ -374,7 +387,7 @@ return ea; } -static int ay_lj_query_connected(eb_account * account) +static int ay_lj_query_connected(eb_account *account) { lj_account_data *lad = account->protocol_account_data; @@ -386,21 +399,20 @@ "Offline" }; -static char *ay_lj_get_status_string(eb_account * account) +static char *ay_lj_get_status_string(eb_account *account) { lj_account_data *lad = account->protocol_account_data; return status_strings[lad->status]; } - -static char ** ay_lj_get_status_pixmap(eb_account * account) +static char **ay_lj_get_status_pixmap(eb_account *account) { lj_account_data *lad; lad = account->protocol_account_data; - if(lad->status == LJ_STATUS_ONLINE) + if (lad->status == LJ_STATUS_ONLINE) return NULL; else return NULL; @@ -409,10 +421,12 @@ static void ay_lj_send_file(eb_local_account *from, eb_account *to, char *file) { - ay_do_info( _("LiveJournal Warning"), _("You cannot send files through LiveJournal...") ); + ay_do_info(_("LiveJournal Warning"), + _("You cannot send files through LiveJournal...")); } -static void ay_lj_send_im(eb_local_account *account_from, eb_account *account_to, char *message) +static void ay_lj_send_im(eb_local_account *account_from, + eb_account *account_to, char *message) { } @@ -426,36 +440,41 @@ lj_find_and_handle_errors(success, ela, pairs); str = value_pair_get_value(pairs, "lastupdate"); - if(str && str[0]) + if (str && str[0]) strncpy(lla->last_update, str, sizeof(lla->last_update)); - if(str) + if (str) free(str); str = value_pair_get_value(pairs, "new"); - if(str) { - if(!strcmp(str, "1")) { - eb_account *ea = find_account_with_ela(ela->handle, ela); - if(!ea) { + if (str) { + if (!strcmp(str, "1")) { + eb_account *ea = + find_account_with_ela(ela->handle, ela); + if (!ea) { ea = ay_lj_new_account(ela, ela->handle); add_dummy_contact(ela->handle, ea); } eb_timeout_remove(lla->poll_timeout_tag); lla->poll_timeout_tag = 0; - - snprintf(buff, sizeof(buff), _("%s, your LiveJournal friends view has been updated.<br>" - "<a href=\"http://www.livejournal.com/users/%s/friends\">Go there now</a>"), - ela->alias, ela->handle); + + snprintf(buff, sizeof(buff), + _ + ("%s, your LiveJournal friends view has been updated.<br>" + "<a href=\"http://www.livejournal.com/users/%s/friends\">Go there now</a>"), + ela->alias, ela->handle); eb_parse_incoming_message(ela, ea, buff); } free(str); } str = value_pair_get_value(pairs, "interval"); - if(str) { - if(lla->poll_interval != atoi(str)) { + if (str) { + if (lla->poll_interval != atoi(str)) { lla->poll_interval = atoi(str); - if(lla->poll_timeout_tag) { + if (lla->poll_timeout_tag) { eb_timeout_remove(lla->poll_timeout_tag); - lla->poll_timeout_tag = eb_timeout_add(lla->poll_interval * 1000, ay_lj_ping_timeout_callback, ela); + lla->poll_timeout_tag = + eb_timeout_add(lla->poll_interval * + 1000, ay_lj_ping_timeout_callback, ela); } } free(str); @@ -468,8 +487,9 @@ lj_local_account *lla = ela->protocol_local_account_data; char buff[1024]; - snprintf(buff, sizeof(buff), "mode=checkfriends&user=%s&password=%s&lastupdate=%s", - ela->handle, lla->password, lla->last_update); + snprintf(buff, sizeof(buff), + "mode=checkfriends&user=%s&password=%s&lastupdate=%s", + ela->handle, lla->password, lla->last_update); send_http_request(buff, _ay_lj_got_update, ela); return 1; @@ -480,21 +500,21 @@ lj_local_account *lla = ela->protocol_local_account_data; eb_account *ea = NULL; int changed = 0; - int i, nfriends=0; + int i, nfriends = 0; char *str, buff[1024]; - if(lj_find_and_handle_errors(success, ela, pairs)) + if (lj_find_and_handle_errors(success, ela, pairs)) goto end_buddy_list; str = value_pair_get_value(pairs, "friend_count"); - if(!str) + if (!str) goto end_buddy_list; nfriends = atoi(str); free(str); - for(i=1; i<=nfriends; i++) { - char *uname=NULL, *real_name=NULL; + for (i = 1; i <= nfriends; i++) { + char *uname = NULL, *real_name = NULL; struct contact *con; grouplist *g; @@ -503,7 +523,7 @@ ea = find_account_with_ela(str, ela); - if(ea) { + if (ea) { free(uname); continue; } @@ -513,15 +533,16 @@ g = find_grouplist_by_name("LiveJournal"); con = find_contact_in_group_by_nick(real_name, g); - if(!con) + if (!con) con = find_contact_in_group_by_nick(uname, g); - if(!con) + if (!con) con = find_contact_by_nick(real_name); - if(!con) + if (!con) con = find_contact_by_nick(uname); - if(!con) { + if (!con) { changed = 1; - con=add_new_contact("LiveJournal", real_name, SERVICE_INFO.protocol_id); + con = add_new_contact("LiveJournal", real_name, + SERVICE_INFO.protocol_id); } ea = ay_lj_new_account(ela, uname); add_account(con->nick, ea); @@ -531,14 +552,14 @@ free(real_name); } - if(changed) { + if (changed) { update_contact_list(); } -end_buddy_list: - if(lla->connect_progress_tag) { + end_buddy_list: + if (lla->connect_progress_tag) { ay_activity_bar_remove(lla->connect_progress_tag); - lla->connect_progress_tag=0; + lla->connect_progress_tag = 0; } } @@ -547,11 +568,12 @@ lj_local_account *lla = ela->protocol_local_account_data; char buff[1024]; - snprintf(buff, sizeof(buff), _("Fetching buddies for %s..."), ela->handle); + snprintf(buff, sizeof(buff), _("Fetching buddies for %s..."), + ela->handle); ay_activity_bar_update_label(lla->connect_progress_tag, buff); - snprintf(buff, sizeof(buff), "mode=getfriends&user=%s&password=%s", - ela->handle, lla->password); + snprintf(buff, sizeof(buff), "mode=getfriends&user=%s&password=%s", + ela->handle, lla->password); send_http_request(buff, _ay_lj_got_buddies, ela); } @@ -560,20 +582,20 @@ { lj_local_account *lla = ela->protocol_local_account_data; - if(lj_find_and_handle_errors(success, ela, pairs)) { + if (lj_find_and_handle_errors(success, ela, pairs)) { ref_count--; - if(lla->connect_progress_tag) { + if (lla->connect_progress_tag) { ay_activity_bar_remove(lla->connect_progress_tag); - lla->connect_progress_tag=0; + lla->connect_progress_tag = 0; } } else { char *str = value_pair_get_value(pairs, "name"); strncpy(ela->alias, str, sizeof(ela->alias)); free(str); - + str = value_pair_get_value(pairs, "message"); - if(str) { + if (str) { ay_do_info(_("LiveJournal System Message"), str); free(str); } @@ -583,12 +605,15 @@ lla->status = LJ_STATUS_ONLINE; is_setting_state = 1; - if(ela->status_menu) - eb_set_active_menu_status(ela->status_menu, lla->status); + if (ela->status_menu) + eb_set_active_menu_status(ela->status_menu, + lla->status); is_setting_state = 0; lj_get_buddies(ela); - lla->poll_timeout_tag = eb_timeout_add(lla->poll_interval * 1000, ay_lj_ping_timeout_callback, ela); + lla->poll_timeout_tag = + eb_timeout_add(lla->poll_interval * 1000, + ay_lj_ping_timeout_callback, ela); } } @@ -598,15 +623,16 @@ char buff[1024]; char buff2[1024]; - if(ela->connecting || ela->connected) + if (ela->connecting || ela->connected) return; url_to_host_port_path(lj_url, lj_host, &lj_port, lj_path); - snprintf(buff, sizeof(buff), "clientversion=%s-%s/%s&mode=login&user=%s&password=%s", - HOST, PACKAGE, VERSION, - ela->handle, lla->password); - snprintf(buff2, sizeof(buff2), _("Logging in to LiveJournal account: %s"), ela->handle); + snprintf(buff, sizeof(buff), + "clientversion=%s-%s/%s&mode=login&user=%s&password=%s", HOST, + PACKAGE, VERSION, ela->handle, lla->password); + snprintf(buff2, sizeof(buff2), + _("Logging in to LiveJournal account: %s"), ela->handle); ela->connecting = 1; lla->connect_progress_tag = ay_activity_bar_add(buff2, NULL, NULL); @@ -628,7 +654,7 @@ free(uname); l_list_free_1(l); } -*/ ela->connected=0; +*/ ela->connected = 0; ref_count--; } @@ -636,25 +662,36 @@ { lj_local_account *lla = account->protocol_local_account_data; - if(is_setting_state) + if (is_setting_state) return; - if(lla->status == LJ_STATUS_OFFLINE && state == LJ_STATUS_ONLINE) + if (lla->status == LJ_STATUS_OFFLINE && state == LJ_STATUS_ONLINE) ay_lj_login(account); - else if(lla->status == LJ_STATUS_ONLINE && state == LJ_STATUS_OFFLINE) + else if (lla->status == LJ_STATUS_ONLINE && state == LJ_STATUS_OFFLINE) ay_lj_logout(account); lla->status = state; } -static char * ay_lj_check_login(char * user, char * pass) +static char *ay_lj_check_login(char *user, char *pass) { return NULL; } -const char * ext_lj_host() { return (const char *)lj_host; } -int ext_lj_port() { return lj_port; } -const char * ext_lj_path() { return (const char *)lj_path; } +const char *ext_lj_host() +{ + return (const char *)lj_host; +} + +int ext_lj_port() +{ + return lj_port; +} + +const char *ext_lj_path() +{ + return (const char *)lj_path; +} struct service_callbacks *query_callbacks() { @@ -662,35 +699,34 @@ sc = calloc(1, sizeof(struct service_callbacks)); - sc->query_connected = ay_lj_query_connected; - sc->login = ay_lj_login; - sc->logout = ay_lj_logout; - sc->check_login = ay_lj_check_login; - - sc->send_im = ay_lj_send_im; - - sc->read_local_account_config = ay_lj_read_local_account_config; - sc->write_local_config = ay_lj_write_local_config; - sc->read_account_config = ay_lj_read_account_config; - - sc->get_states = ay_lj_get_states; - sc->get_current_state = ay_lj_get_current_state; - sc->set_current_state = ay_lj_set_current_state; - - sc->new_account = ay_lj_new_account; - sc->add_user = ay_lj_add_user; - sc->del_user = ay_lj_del_user; - - sc->get_status_string = ay_lj_get_status_string; - sc->get_status_pixmap = ay_lj_get_status_pixmap; + sc->query_connected = ay_lj_query_connected; + sc->login = ay_lj_login; + sc->logout = ay_lj_logout; + sc->check_login = ay_lj_check_login; + + sc->send_im = ay_lj_send_im; + + sc->read_local_account_config = ay_lj_read_local_account_config; + sc->write_local_config = ay_lj_write_local_config; + sc->read_account_config = ay_lj_read_account_config; - sc->set_idle = ay_lj_set_idle; - sc->set_away = ay_lj_set_away; + sc->get_states = ay_lj_get_states; + sc->get_current_state = ay_lj_get_current_state; + sc->set_current_state = ay_lj_set_current_state; - sc->send_file = ay_lj_send_file; + sc->new_account = ay_lj_new_account; + sc->add_user = ay_lj_add_user; + sc->del_user = ay_lj_del_user; - sc->get_color = ay_lj_get_color; + sc->get_status_string = ay_lj_get_status_string; + sc->get_status_pixmap = ay_lj_get_status_pixmap; + + sc->set_idle = ay_lj_set_idle; + sc->set_away = ay_lj_set_away; + + sc->send_file = ay_lj_send_file; + + sc->get_color = ay_lj_get_color; return sc; } - Index: lj.h =================================================================== RCS file: /cvsroot/ayttm/ayttm/modules/livejournal/lj.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- lj.h 1 Aug 2003 09:52:29 -0000 1.1 +++ lj.h 17 Sep 2009 12:04:59 -0000 1.2 @@ -1,3 +1,3 @@ -const char *ext_lj_host( void ); -int ext_lj_port( void ); -const char *ext_lj_path( void ); +const char *ext_lj_host(void); +int ext_lj_port(void); +const char *ext_lj_path(void); Index: lj_httplib.c =================================================================== RCS file: /cvsroot/ayttm/ayttm/modules/livejournal/lj_httplib.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- lj_httplib.c 19 Aug 2009 04:07:04 -0000 1.2 +++ lj_httplib.c 17 Sep 2009 12:04:59 -0000 1.3 @@ -40,9 +40,9 @@ int url_to_host_port_path(const char *url, char *host, int *port, char *path) { - char *urlcopy=NULL; - char *slash=NULL; - char *colon=NULL; + char *urlcopy = NULL; + char *slash = NULL; + char *colon = NULL; /* * http://hostname @@ -55,24 +55,24 @@ * http://hostname:port/path:foo */ - if(strstr(url, "http://") == url) { - urlcopy = strdup(url+7); + if (strstr(url, "http://") == url) { + urlcopy = strdup(url + 7); } else { - /*WARNING(("Weird url - unknown protocol: %s", url));*/ + /*WARNING(("Weird url - unknown protocol: %s", url)); */ return 0; } slash = strchr(urlcopy, '/'); colon = strchr(urlcopy, ':'); - if(!colon || (slash && slash < colon)) { + if (!colon || (slash && slash < colon)) { *port = 80; } else { *colon = 0; - *port = atoi(colon+1); + *port = atoi(colon + 1); } - if(!slash) { + if (!slash) { strcpy(path, "/"); } else { strcpy(path, slash); @@ -93,71 +93,71 @@ char *urlencode(const char *instr) { - int ipos=0, bpos=0; + int ipos = 0, bpos = 0; char *str = NULL; int len = strlen(instr); - if(!(str = malloc(sizeof(char) * (3*len + 1)) )) + if (!(str = malloc(sizeof(char) * (3 * len + 1)))) return ""; - while(instr[ipos]) { - while(isurlchar(instr[ipos])) + while (instr[ipos]) { + while (isurlchar(instr[ipos])) str[bpos++] = instr[ipos++]; - if(!instr[ipos]) + if (!instr[ipos]) break; snprintf(&str[bpos], 4, "%%%.2x", instr[ipos]); - bpos+=3; + bpos += 3; ipos++; } - str[bpos]='\0'; + str[bpos] = '\0'; /* free extra alloc'ed mem. */ len = strlen(str); - str = realloc(str, sizeof(char) * (len+1)); + str = realloc(str, sizeof(char) * (len + 1)); return (str); } char *urldecode(const char *instr) { - int ipos=0, bpos=0; + int ipos = 0, bpos = 0; char *str = NULL; - char entity[3]={0,0,0}; + char entity[3] = { 0, 0, 0 }; unsigned dec; int len = strlen(instr); - if(!(str = malloc(sizeof(char) * (len+1)) )) + if (!(str = malloc(sizeof(char) * (len + 1)))) return ""; - while(instr[ipos]) { - while(instr[ipos] && instr[ipos]!='%') - if(instr[ipos]=='+') { - str[bpos++]=' '; + while (instr[ipos]) { + while (instr[ipos] && instr[ipos] != '%') + if (instr[ipos] == '+') { + str[bpos++] = ' '; ipos++; } else str[bpos++] = instr[ipos++]; - if(!instr[ipos]) + if (!instr[ipos]) break; ipos++; - entity[0]=instr[ipos++]; - entity[1]=instr[ipos++]; + entity[0] = instr[ipos++]; + entity[1] = instr[ipos++]; sscanf(entity, "%2x", &dec); str[bpos++] = (char)dec; } - str[bpos]='\0'; + str[bpos] = '\0'; /* free extra alloc'ed mem. */ len = strlen(str); - str = realloc(str, sizeof(char) * (len+1)); + str = realloc(str, sizeof(char) * (len + 1)); return (str); } struct callback_data { int tag; - lj_callback callback; + lj_callback callback; eb_local_account *ela; char *request; }; @@ -167,27 +167,28 @@ struct callback_data *ccd = data; char buff[MAX_PREF_LEN]; - int n=0; + int n = 0; - LList *pairs=NULL; - char key[MAX_PREF_NAME_LEN]=""; + LList *pairs = NULL; + char key[MAX_PREF_NAME_LEN] = ""; - int success=LJ_HTTP_NETWORK; + int success = LJ_HTTP_NETWORK; - while(success != LJ_HTTP_OK && (n=ay_tcp_readline(buff, sizeof(buff), fd)) > 0) { + while (success != LJ_HTTP_OK + && (n = ay_tcp_readline(buff, sizeof(buff), fd)) > 0) { /* read up to blank line */ - if(!strcmp(buff, "")) - success=LJ_HTTP_OK; - else if(!strncmp(buff, "HTTP/", strlen("HTTP/"))) - if(!strstr(buff, " 200 ")) - success=LJ_HTTP_NOK; + if (!strcmp(buff, "")) + success = LJ_HTTP_OK; + else if (!strncmp(buff, "HTTP/", strlen("HTTP/"))) + if (!strstr(buff, " 200 ")) + success = LJ_HTTP_NOK; } - if(n==0) + if (n == 0) goto end_of_read; - while((n=ay_tcp_readline(buff, sizeof(buff), fd)) > 0) { - if(!strcmp(key, "")) { + while ((n = ay_tcp_readline(buff, sizeof(buff), fd)) > 0) { + if (!strcmp(key, "")) { strncpy(key, buff, sizeof(key)); } else { pairs = value_pair_add(pairs, key, buff); @@ -195,8 +196,8 @@ } } -end_of_read: - if(ccd->callback) + end_of_read: + if (ccd->callback) ccd->callback(success, ccd->ela, pairs); value_pair_free(pairs); @@ -210,7 +211,7 @@ static void lj_got_connected(int fd, int error, void *data) { struct callback_data *ccd = data; - if(error == 0 && fd > 0) { + if (error == 0 && fd > 0) { write(fd, ccd->request, strlen(ccd->request)); fsync(fd); } @@ -218,23 +219,24 @@ ccd->tag = eb_input_add(fd, EB_INPUT_READ, read_http_response, ccd); } -void send_http_request(const char *request, lj_callback callback, eb_local_account *ela) +void send_http_request(const char *request, lj_callback callback, + eb_local_account *ela) { char buff[1024]; - struct callback_data *ccd=calloc(1, sizeof(struct callback_data)); + struct callback_data *ccd = calloc(1, sizeof(struct callback_data)); snprintf(buff, sizeof(buff), - "POST %s HTTP/1.0\r\n" - "Host: %s\r\n" - "Content-Type: application/x-www-form-urlencoded\r\n" - "Content-Length: %u\r\n" - "\r\n" - "%s", - ext_lj_path(), ext_lj_host(), strlen(request), request); + "POST %s HTTP/1.0\r\n" + "Host: %s\r\n" + "Content-Type: application/x-www-form-urlencoded\r\n" + "Content-Length: %u\r\n" + "\r\n" + "%s", ext_lj_path(), ext_lj_host(), strlen(request), request); ccd->callback = callback; ccd->request = strdup(buff); ccd->ela = ela; - ccd->tag = ay_socket_new_async(ext_lj_host(), ext_lj_port(), lj_got_connected, ccd, NULL); + ccd->tag = + ay_socket_new_async(ext_lj_host(), ext_lj_port(), + lj_got_connected, ccd, NULL); } - Index: lj_httplib.h =================================================================== RCS file: /cvsroot/ayttm/ayttm/modules/livejournal/lj_httplib.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- lj_httplib.h 1 Aug 2003 09:52:29 -0000 1.1 +++ lj_httplib.h 17 Sep 2009 12:04:59 -0000 1.2 @@ -14,13 +14,15 @@ extern "C" { #endif -typedef void (*lj_callback)(int success, eb_local_account *ela, LList *pairs); + typedef void (*lj_callback) (int success, eb_local_account *ela, + LList *pairs); -void send_http_request(const char *request, lj_callback callback, eb_local_account *ela); -int url_to_host_port_path(const char *url, char *host, int *port, char *path); + void send_http_request(const char *request, lj_callback callback, + eb_local_account *ela); + int url_to_host_port_path(const char *url, char *host, int *port, + char *path); #ifdef __cplusplus } #endif - #endif |