comparison libpurple/protocols/simple/simple.c @ 21024:61a87e02da29

Some constification, which also found and fixed some potential double-free errors.
author Stu Tomlinson <stu@nosnilmot.com>
date Sat, 27 Oct 2007 13:12:27 +0000
parents 89c7be36fd61
children 3cc856ca2338
comparison
equal deleted inserted replaced
21022:3f8b32a4786c 21024:61a87e02da29
319 } 319 }
320 320
321 return retval; 321 return retval;
322 } 322 }
323 323
324 static void fill_auth(struct simple_account_data *sip, gchar *hdr, struct sip_auth *auth) { 324 static void fill_auth(struct simple_account_data *sip, const gchar *hdr, struct sip_auth *auth) {
325 int i = 0; 325 int i = 0;
326 const char *authuser; 326 const char *authuser;
327 char *tmp; 327 char *tmp;
328 gchar **parts; 328 gchar **parts;
329 329
590 } 590 }
591 591
592 static struct transaction *transactions_find(struct simple_account_data *sip, struct sipmsg *msg) { 592 static struct transaction *transactions_find(struct simple_account_data *sip, struct sipmsg *msg) {
593 struct transaction *trans; 593 struct transaction *trans;
594 GSList *transactions = sip->transactions; 594 GSList *transactions = sip->transactions;
595 gchar *cseq = sipmsg_find_header(msg, "CSeq"); 595 const gchar *cseq = sipmsg_find_header(msg, "CSeq");
596 596
597 if (cseq) { 597 if (cseq) {
598 while(transactions) { 598 while(transactions) {
599 trans = transactions->data; 599 trans = transactions->data;
600 if(!strcmp(trans->cseq, cseq)) { 600 if(!strcmp(trans->cseq, cseq)) {
798 /* add some jitter */ 798 /* add some jitter */
799 buddy->resubscribe = time(NULL)+1140+(rand()%50); 799 buddy->resubscribe = time(NULL)+1140+(rand()%50);
800 } 800 }
801 801
802 static gboolean simple_add_lcs_contacts(struct simple_account_data *sip, struct sipmsg *msg, struct transaction *tc) { 802 static gboolean simple_add_lcs_contacts(struct simple_account_data *sip, struct sipmsg *msg, struct transaction *tc) {
803 gchar *tmp; 803 const gchar *tmp;
804 xmlnode *item, *group, *isc; 804 xmlnode *item, *group, *isc;
805 const char *name_group; 805 const char *name_group;
806 PurpleBuddy *b; 806 PurpleBuddy *b;
807 PurpleGroup *g = NULL; 807 PurpleGroup *g = NULL;
808 struct simple_buddy *bs; 808 struct simple_buddy *bs;
958 return 1; 958 return 1;
959 } 959 }
960 960
961 static void process_incoming_message(struct simple_account_data *sip, struct sipmsg *msg) { 961 static void process_incoming_message(struct simple_account_data *sip, struct sipmsg *msg) {
962 gchar *from; 962 gchar *from;
963 gchar *contenttype; 963 const gchar *contenttype;
964 gboolean found = FALSE; 964 gboolean found = FALSE;
965 965
966 from = parse_from(sipmsg_find_header(msg, "From")); 966 from = parse_from(sipmsg_find_header(msg, "From"));
967 967
968 if(!from) return; 968 if(!from) return;
1013 g_free(from); 1013 g_free(from);
1014 } 1014 }
1015 1015
1016 1016
1017 gboolean process_register_response(struct simple_account_data *sip, struct sipmsg *msg, struct transaction *tc) { 1017 gboolean process_register_response(struct simple_account_data *sip, struct sipmsg *msg, struct transaction *tc) {
1018 gchar *tmp; 1018 const gchar *tmp;
1019 purple_debug(PURPLE_DEBUG_MISC, "simple", "in process register response response: %d\n", msg->response); 1019 purple_debug(PURPLE_DEBUG_MISC, "simple", "in process register response response: %d\n", msg->response);
1020 switch (msg->response) { 1020 switch (msg->response) {
1021 case 200: 1021 case 200:
1022 if(sip->registerstatus < SIMPLE_REGISTER_COMPLETE) { /* registered */ 1022 if(sip->registerstatus < SIMPLE_REGISTER_COMPLETE) { /* registered */
1023 if(purple_account_get_bool(sip->account, "dopublish", TRUE)) { 1023 if(purple_account_get_bool(sip->account, "dopublish", TRUE)) {
1070 return TRUE; 1070 return TRUE;
1071 } 1071 }
1072 1072
1073 static void process_incoming_notify(struct simple_account_data *sip, struct sipmsg *msg) { 1073 static void process_incoming_notify(struct simple_account_data *sip, struct sipmsg *msg) {
1074 gchar *from; 1074 gchar *from;
1075 gchar *fromhdr; 1075 const gchar *fromhdr;
1076 gchar *basicstatus_data; 1076 gchar *basicstatus_data;
1077 xmlnode *pidf; 1077 xmlnode *pidf;
1078 xmlnode *basicstatus = NULL, *tuple, *status; 1078 xmlnode *basicstatus = NULL, *tuple, *status;
1079 gboolean isonline = FALSE; 1079 gboolean isonline = FALSE;
1080 1080
1253 const char *from_hdr = sipmsg_find_header(msg, "From"); 1253 const char *from_hdr = sipmsg_find_header(msg, "From");
1254 gchar *from = parse_from(from_hdr); 1254 gchar *from = parse_from(from_hdr);
1255 gchar *theirtag = find_tag(from_hdr); 1255 gchar *theirtag = find_tag(from_hdr);
1256 gchar *ourtag = find_tag(sipmsg_find_header(msg, "To")); 1256 gchar *ourtag = find_tag(sipmsg_find_header(msg, "To"));
1257 gboolean tagadded = FALSE; 1257 gboolean tagadded = FALSE;
1258 gchar *callid = sipmsg_find_header(msg, "Call-ID"); 1258 const gchar *callid = sipmsg_find_header(msg, "Call-ID");
1259 gchar *expire = sipmsg_find_header(msg, "Expire"); 1259 const gchar *expire = sipmsg_find_header(msg, "Expire");
1260 gchar *tmp; 1260 gchar *tmp;
1261 struct simple_watcher *watcher = watcher_find(sip, from); 1261 struct simple_watcher *watcher = watcher_find(sip, from);
1262 if(!ourtag) { 1262 if(!ourtag) {
1263 tagadded = TRUE; 1263 tagadded = TRUE;
1264 ourtag = gentag(); 1264 ourtag = gentag();
1265 } 1265 }
1266 if(!watcher) { /* new subscription */ 1266 if(!watcher) { /* new subscription */
1267 gchar *acceptheader = sipmsg_find_header(msg, "Accept"); 1267 const gchar *acceptheader = sipmsg_find_header(msg, "Accept");
1268 gboolean needsxpidf = FALSE; 1268 gboolean needsxpidf = FALSE;
1269 if(!purple_privacy_check(sip->account, from)) { 1269 if(!purple_privacy_check(sip->account, from)) {
1270 send_sip_response(sip->gc, msg, 202, "Ok", NULL); 1270 send_sip_response(sip->gc, msg, 202, "Ok", NULL);
1271 goto privend; 1271 goto privend;
1272 } 1272 }
1273 if(acceptheader) { 1273 if(acceptheader) {
1274 gchar *tmp = acceptheader; 1274 const gchar *tmp = acceptheader;
1275 gboolean foundpidf = FALSE; 1275 gboolean foundpidf = FALSE;
1276 gboolean foundxpidf = FALSE; 1276 gboolean foundxpidf = FALSE;
1277 while(tmp && tmp < acceptheader + strlen(acceptheader)) { 1277 while(tmp && tmp < acceptheader + strlen(acceptheader)) {
1278 gchar *tmp2 = strchr(tmp, ','); 1278 gchar *tmp2 = strchr(tmp, ',');
1279 if(tmp2) *tmp2 = '\0'; 1279 if(tmp2) *tmp2 = '\0';
1287 while(*tmp == ' ') tmp++; 1287 while(*tmp == ' ') tmp++;
1288 } else 1288 } else
1289 tmp = 0; 1289 tmp = 0;
1290 } 1290 }
1291 if(!foundpidf && foundxpidf) needsxpidf = TRUE; 1291 if(!foundpidf && foundxpidf) needsxpidf = TRUE;
1292 g_free(acceptheader);
1293 } 1292 }
1294 watcher = watcher_create(sip, from, callid, ourtag, theirtag, needsxpidf); 1293 watcher = watcher_create(sip, from, callid, ourtag, theirtag, needsxpidf);
1295 } 1294 }
1296 if(tagadded) { 1295 if(tagadded) {
1297 gchar *to = g_strdup_printf("%s;tag=%s", sipmsg_find_header(msg, "To"), ourtag); 1296 gchar *to = g_strdup_printf("%s;tag=%s", sipmsg_find_header(msg, "To"), ourtag);
1312 send_notify(sip, watcher); 1311 send_notify(sip, watcher);
1313 privend: 1312 privend:
1314 g_free(from); 1313 g_free(from);
1315 g_free(theirtag); 1314 g_free(theirtag);
1316 g_free(ourtag); 1315 g_free(ourtag);
1317 g_free(callid);
1318 g_free(expire);
1319 } 1316 }
1320 1317
1321 static void process_input_message(struct simple_account_data *sip, struct sipmsg *msg) { 1318 static void process_input_message(struct simple_account_data *sip, struct sipmsg *msg) {
1322 gboolean found = FALSE; 1319 gboolean found = FALSE;
1323 if(msg->response == 0) { /* request */ 1320 if(msg->response == 0) { /* request */
1335 } 1332 }
1336 } else { /* response */ 1333 } else { /* response */
1337 struct transaction *trans = transactions_find(sip, msg); 1334 struct transaction *trans = transactions_find(sip, msg);
1338 if(trans) { 1335 if(trans) {
1339 if(msg->response == 407) { 1336 if(msg->response == 407) {
1340 gchar *resend, *auth, *ptmp; 1337 gchar *resend, *auth;
1338 const gchar *ptmp;
1341 1339
1342 if(sip->proxy.retries > 3) return; 1340 if(sip->proxy.retries > 3) return;
1343 sip->proxy.retries++; 1341 sip->proxy.retries++;
1344 /* do proxy authentication */ 1342 /* do proxy authentication */
1345 1343
1379 } else { 1377 } else {
1380 if(msg->response == 401) { 1378 if(msg->response == 401) {
1381 /* This is encountered when a generic (MESSAGE, NOTIFY, etc) 1379 /* This is encountered when a generic (MESSAGE, NOTIFY, etc)
1382 * was denied until further authorization is provided. 1380 * was denied until further authorization is provided.
1383 */ 1381 */
1384 gchar *resend, *auth, *ptmp; 1382 gchar *resend, *auth;
1383 const gchar *ptmp;
1385 1384
1386 if(sip->registrar.retries > SIMPLE_REGISTER_RETRY_MAX) return; 1385 if(sip->registrar.retries > SIMPLE_REGISTER_RETRY_MAX) return;
1387 sip->registrar.retries++; 1386 sip->registrar.retries++;
1388 1387
1389 ptmp = sipmsg_find_header(msg, "WWW-Authenticate"); 1388 ptmp = sipmsg_find_header(msg, "WWW-Authenticate");