Ticket #553: PUBLISH callback is not called when authentication fails (thanks Ruud Klaver for the report)

git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@2095 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjsip/src/pjsip-simple/publishc.c b/pjsip/src/pjsip-simple/publishc.c
index a620606..072a08d 100644
--- a/pjsip/src/pjsip-simple/publishc.c
+++ b/pjsip/src/pjsip-simple/publishc.c
@@ -435,19 +435,15 @@
 
     entry->id = 0;
     status = pjsip_publishc_publish(pubc, 1, &tdata);
-    if (status == PJ_SUCCESS) {
-	status = pjsip_publishc_send(pubc, tdata);
-    } 
-    
-    // Callback should have been called.
-    // Calling it here will crash the system since pubc might have been
-    // destroyed
-    //
-    //if (status != PJ_SUCCESS) {
-    //	char errmsg[PJ_ERR_MSG_SIZE];
-    //	pj_str_t reason = pj_strerror(status, errmsg, sizeof(errmsg));
-    //	call_callback(pubc, status, 400, &reason, NULL, -1);
-    //}
+    if (status != PJ_SUCCESS) {
+	char errmsg[PJ_ERR_MSG_SIZE];
+	pj_str_t reason = pj_strerror(status, errmsg, sizeof(errmsg));
+	call_callback(pubc, status, 400, &reason, NULL, -1);
+	return;
+    }
+
+    status = pjsip_publishc_send(pubc, tdata);
+    /* No need to call callback as it should have been called */
 }
 
 static void tsx_callback(void *token, pjsip_event *event)
@@ -478,22 +474,13 @@
 					    rdata, 
 					    tsx->last_tx,  
 					    &tdata);
-
-	if (status == PJ_SUCCESS) {
-	    status = pjsip_publishc_send(pubc, tdata);
-	} 
-	
-	// Callback should have been called.
-	// Calling it here will crash the system since pubc might have been
-	// destroyed
-	//
-	//if (status != PJ_SUCCESS) {
-	//    call_callback(pubc, status, tsx->status_code, 
-	//		  &rdata->msg_info.msg->line.status.reason,
-	//		  rdata, -1);
-	//}
-
-	return;
+	if (status != PJ_SUCCESS) {
+	    call_callback(pubc, status, tsx->status_code, 
+			  &rdata->msg_info.msg->line.status.reason,
+			  rdata, -1);
+	} else {
+    	    status = pjsip_publishc_send(pubc, tdata);
+	}
 
     } else {
 	pjsip_rx_data *rdata;