Changeset 268 for pjproject/trunk/pjsip/src/pjsip-simple/presence.c
- Timestamp:
- Mar 2, 2006 9:18:58 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/src/pjsip-simple/presence.c
r230 r268 787 787 788 788 /* 789 * Process the content of incoming NOTIFY request and update temporary 790 * status. 791 * 792 * return PJ_SUCCESS if incoming request is acceptable. If return value 793 * is not PJ_SUCCESS, res_hdr may be added with Warning header. 794 */ 795 static pj_status_t pres_process_rx_notify( pjsip_pres *pres, 796 pjsip_rx_data *rdata, 797 int *p_st_code, 798 pj_str_t **p_st_text, 799 pjsip_hdr *res_hdr) 800 { 801 pjsip_ctype_hdr *ctype_hdr; 802 pj_status_t status; 803 804 *p_st_text = NULL; 805 806 /* Check Content-Type and msg body are present. */ 807 ctype_hdr = rdata->msg_info.ctype; 808 809 if (ctype_hdr==NULL || rdata->msg_info.msg->body==NULL) { 810 811 pjsip_warning_hdr *warn_hdr; 812 pj_str_t warn_text; 813 814 *p_st_code = PJSIP_SC_BAD_REQUEST; 815 816 warn_text = pj_str("Message body is not present"); 817 warn_hdr = pjsip_warning_hdr_create(rdata->tp_info.pool, 399, 818 pjsip_endpt_name(pres->dlg->endpt), 819 &warn_text); 820 pj_list_push_back(res_hdr, warn_hdr); 821 822 return PJSIP_ERRNO_FROM_SIP_STATUS(PJSIP_SC_BAD_REQUEST); 823 } 824 825 /* Parse content. */ 826 827 if (pj_stricmp(&ctype_hdr->media.type, &STR_APPLICATION)==0 && 828 pj_stricmp(&ctype_hdr->media.subtype, &STR_PIDF_XML)==0) 829 { 830 status = pres_parse_pidf( pres, rdata, &pres->tmp_status); 831 } 832 else 833 if (pj_stricmp(&ctype_hdr->media.type, &STR_APPLICATION)==0 && 834 pj_stricmp(&ctype_hdr->media.subtype, &STR_XPIDF_XML)==0) 835 { 836 status = pres_parse_xpidf( pres, rdata, &pres->tmp_status); 837 } 838 else 839 { 840 status = PJSIP_SIMPLE_EBADCONTENT; 841 } 842 843 if (status != PJ_SUCCESS) { 844 /* Unsupported or bad Content-Type */ 845 pjsip_accept_hdr *accept_hdr; 846 pjsip_warning_hdr *warn_hdr; 847 848 *p_st_code = PJSIP_SC_NOT_ACCEPTABLE_HERE; 849 850 /* Add Accept header */ 851 accept_hdr = pjsip_accept_hdr_create(rdata->tp_info.pool); 852 accept_hdr->values[accept_hdr->count++] = STR_APP_PIDF_XML; 853 accept_hdr->values[accept_hdr->count++] = STR_APP_XPIDF_XML; 854 pj_list_push_back(res_hdr, accept_hdr); 855 856 /* Add Warning header */ 857 warn_hdr = pjsip_warning_hdr_create_from_status( 858 rdata->tp_info.pool, 859 pjsip_endpt_name(pres->dlg->endpt), 860 status); 861 pj_list_push_back(res_hdr, warn_hdr); 862 863 return status; 864 } 865 866 /* If application calls pres_get_status(), redirect the call to 867 * retrieve the temporary status. 868 */ 869 pres->tmp_status._is_valid = PJ_TRUE; 870 871 return PJ_SUCCESS; 872 } 873 874 875 /* 789 876 * Called when NOTIFY is received. 790 877 */ … … 796 883 pjsip_msg_body **p_body) 797 884 { 798 pjsip_ctype_hdr *ctype_hdr;799 885 pjsip_pres *pres; 800 886 pj_status_t status; … … 803 889 PJ_ASSERT_ON_FAIL(pres!=NULL, {return;}); 804 890 805 /* Check Content-Type and msg body are present. */ 806 ctype_hdr = rdata->msg_info.ctype; 807 808 if (ctype_hdr==NULL || rdata->msg_info.msg->body==NULL) { 809 810 pjsip_warning_hdr *warn_hdr; 811 pj_str_t warn_text; 812 813 *p_st_code = PJSIP_SC_BAD_REQUEST; 814 815 warn_text = pj_str("Message body is not present"); 816 warn_hdr = pjsip_warning_hdr_create(rdata->tp_info.pool, 399, 817 pjsip_endpt_name(pres->dlg->endpt), 818 &warn_text); 819 pj_list_push_back(res_hdr, warn_hdr); 820 821 return; 822 } 823 824 /* Parse content. */ 825 826 if (pj_stricmp(&ctype_hdr->media.type, &STR_APPLICATION)==0 && 827 pj_stricmp(&ctype_hdr->media.subtype, &STR_PIDF_XML)==0) 828 { 829 status = pres_parse_pidf( pres, rdata, &pres->tmp_status); 830 } 831 else 832 if (pj_stricmp(&ctype_hdr->media.type, &STR_APPLICATION)==0 && 833 pj_stricmp(&ctype_hdr->media.subtype, &STR_XPIDF_XML)==0) 834 { 835 status = pres_parse_xpidf( pres, rdata, &pres->tmp_status); 836 } 837 else 838 { 839 status = PJSIP_SIMPLE_EBADCONTENT; 840 } 841 842 if (status != PJ_SUCCESS) { 843 /* Unsupported or bad Content-Type */ 844 pjsip_accept_hdr *accept_hdr; 845 pjsip_warning_hdr *warn_hdr; 846 847 *p_st_code = PJSIP_SC_NOT_ACCEPTABLE_HERE; 848 849 /* Add Accept header */ 850 accept_hdr = pjsip_accept_hdr_create(rdata->tp_info.pool); 851 accept_hdr->values[accept_hdr->count++] = STR_APP_PIDF_XML; 852 accept_hdr->values[accept_hdr->count++] = STR_APP_XPIDF_XML; 853 pj_list_push_back(res_hdr, accept_hdr); 854 855 /* Add Warning header */ 856 warn_hdr = pjsip_warning_hdr_create_from_status( 857 rdata->tp_info.pool, 858 pjsip_endpt_name(pres->dlg->endpt), 859 status); 860 pj_list_push_back(res_hdr, warn_hdr); 861 862 return; 863 } 864 865 /* If application calls pres_get_status(), redirect the call to 866 * retrieve the temporary status. 891 /* Only process the message body if it exists, otherwise treat as 892 * presence status is closed. 867 893 */ 868 pres->tmp_status._is_valid = PJ_TRUE; 894 if (rdata->msg_info.msg->body) { 895 status = pres_process_rx_notify( pres, rdata, p_st_code, p_st_text, 896 res_hdr ); 897 if (status != PJ_SUCCESS) 898 return; 899 900 } else { 901 unsigned i; 902 903 /* Subscription is terminated. Consider contact is offline */ 904 pres->tmp_status._is_valid = PJ_TRUE; 905 for (i=0; i<pres->tmp_status.info_cnt; ++i) 906 pres->tmp_status.info[i].basic_open = PJ_FALSE; 907 } 869 908 870 909 /* Notify application. */
Note: See TracChangeset
for help on using the changeset viewer.