⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wap_push_ppg.c

📁 The Kannel Open Source WAP and SMS gateway works as both an SMS gateway, for implementing keyword b
💻 C
📖 第 1 页 / 共 5 页
字号:
            debug("wap.push.ppg", 0, "your configuration uses %s",                  octstr_get_cstr(ppg_url));                       not_found = octstr_imm("Service not specified\n");            http_send_reply(client, http_status, push_headers, not_found);            goto ferror;        }        http_status = HTTP_UNAUTHORIZED;           if (!ip_allowed_by_ppg(ip)) {            error(0,  "Request <%s> from <%s>: ip forbidden, closing the"                  " client", octstr_get_cstr(url), octstr_get_cstr(ip));            http_close_client(client);            goto ferror;         }        if (!trusted_pi && user_configuration) {	    if (!wap_push_ppg_pushuser_authenticate(client, cgivars, ip,                                                     push_headers, &username)) {	             error(0,  "Request <%s> from <%s>: authorisation failure",                       octstr_get_cstr(url), octstr_get_cstr(ip));                 goto ferror;            }        } else {                        /* J鰎g, this wont disappear again */	    username = octstr_imm("");	}        http_status = HTTP_ACCEPTED;        info(0, "PPG: Accept request <%s> from <%s>", octstr_get_cstr(url),              octstr_get_cstr(ip));                if (octstr_len(mime_content) == 0) {	    warning(0, "PPG: No MIME content received, the request"                    " unacceptable");            send_bad_message_response(&client, octstr_imm("No MIME content"),                                       PAP_BAD_REQUEST, http_status);            if (client == NULL)	            break;            goto ferror;        }        if (!push_headers) {            warning(0, "PPG: No push headers received , the request"                    " unacceptable");            send_bad_message_response(&client, octstr_imm("No push headers"),                                       PAP_BAD_REQUEST, http_status);            if (client == NULL)	            break;            goto ferror;        }        octstr_destroy(ip);                http_remove_hop_headers(push_headers);        remove_mime_headers(&push_headers);        remove_link_headers(&push_headers);        if (!headers_acceptable(push_headers, &content_header)) {	        warning(0,  "PPG: Unparsable push headers, the request"                    " unacceptable");            send_bad_message_response(&client, content_header, PAP_BAD_REQUEST,                                      http_status);            if (client == NULL)	            break;	        goto herror;        }                if (get_mime_boundary(push_headers, content_header, &boundary) == -1) {	        warning(0, "PPG: No MIME boundary, the request unacceptable");            send_bad_message_response(&client, content_header, PAP_BAD_REQUEST,                                      http_status);            if (client == NULL) 	            break;	        goto berror;        }        gw_assert(mime_content);        if (!mime_parse(boundary, mime_content, &pap_content, &push_data,                         &content_headers, &rdf_content)) {            send_bad_message_response(&client, mime_content, PAP_BAD_REQUEST,                                      http_status);            if (client == NULL)	            break;            warning(0, "PPG: unable to parse mime content, the request"                    " unacceptable");            goto clean;        } else {	        debug("wap.push.ppg", 0, "PPG: http_read_thread: pap multipart"                  " accepted");        }                push_len = octstr_len(push_data);         http_header_remove_all(push_headers, "Content-Type");	http_append_headers(push_headers, content_headers);        change_header_value(&push_headers, "Content-Length",             octstr_get_cstr(plos = octstr_format("%d", push_len)));        octstr_destroy(plos);        octstr_destroy(content_header);	http_destroy_headers(content_headers);        ppg_event = NULL;        if ((compiler_status = pap_compile(pap_content, &ppg_event)) == -2) {	    send_bad_message_response(&client, pap_content, PAP_BAD_REQUEST,                                       http_status);            if (client == NULL)	        break;            warning(0, "PPG: pap control entity erroneous, the request"                     " unacceptable");            goto no_compile;        } else if (compiler_status == -1) {            send_bad_message_response(&client, pap_content, PAP_BAD_REQUEST,                                      http_status);            if (client == NULL)	        break;            warning(0, "PPG: non implemented pap feature requested, the"                    " request unacceptable");            goto no_compile;        } else {	    if (!dict_put_once(http_clients, 		    ppg_event->u.Push_Message.pi_push_id, client)) {                warning(0, "PPG: duplicate push id, the request unacceptable");	        tell_fatal_error(&client, ppg_event, url, http_status,                                  PAP_DUPLICATE_PUSH_ID);                if (client == NULL)	            break;                goto not_acceptable;	    }             dict_put(urls, ppg_event->u.Push_Message.pi_push_id, url);              if (is_phone_number(ppg_event->u.Push_Message.address_type)) {                if (!trusted_pi && user_configuration &&                         !wap_push_ppg_pushuser_client_phone_number_acceptable(                        username, ppg_event->u.Push_Message.address_value)) {                    tell_fatal_error(&client, ppg_event, url, http_status,                                     PAP_FORBIDDEN);                    if (client == NULL)	                break;	                goto not_acceptable;	            }               }                                debug("wap.push.ppg", 0, "PPG: http_read_thread: pap control"                  " entity compiled ok");            ppg_event->u.Push_Message.push_data = octstr_duplicate(push_data);            ppg_event->u.Push_Message.smsc_id = set_smsc_id(push_headers, username,                                                            trusted_pi);            dlr_url = set_dlr_url(push_headers, username, trusted_pi);            ppg_event->u.Push_Message.dlr_url = dlr_url;            ppg_event->u.Push_Message.dlr_mask = set_dlr_mask(push_headers, dlr_url);            ppg_event->u.Push_Message.smsbox_id = set_smsbox_id(push_headers, username,                                                                trusted_pi);            ppg_event->u.Push_Message.service_name = set_service_name();            remove_x_kannel_headers(&push_headers);            ppg_event->u.Push_Message.push_headers = http_header_duplicate(push_headers);                        if (!handle_push_message(&client, ppg_event, http_status)) {	        if (client == NULL)		    break;                goto no_transform;            }        }        pap_event_destroy(p);        http_destroy_headers(push_headers);        http_destroy_cgiargs(cgivars);        octstr_destroy(username);        octstr_destroy(mime_content);        octstr_destroy(pap_content);        octstr_destroy(push_data);        octstr_destroy(rdf_content);        octstr_destroy(boundary);        continue;no_transform:        pap_event_destroy(p);        http_destroy_headers(push_headers);        http_destroy_cgiargs(cgivars);        octstr_destroy(username);        octstr_destroy(mime_content);        octstr_destroy(pap_content);        octstr_destroy(push_data);        octstr_destroy(rdf_content);        octstr_destroy(boundary);        continue;no_compile:        pap_event_destroy(p);        http_destroy_headers(push_headers);        http_destroy_cgiargs(cgivars);        octstr_destroy(username);        octstr_destroy(mime_content);        octstr_destroy(push_data);        octstr_destroy(rdf_content);        octstr_destroy(boundary);        octstr_destroy(url);        continue;not_acceptable:        pap_event_destroy(p);        http_destroy_headers(push_headers);        http_destroy_cgiargs(cgivars);        octstr_destroy(username);        octstr_destroy(mime_content);        octstr_destroy(pap_content);        octstr_destroy(push_data);        octstr_destroy(rdf_content);        octstr_destroy(boundary);        octstr_destroy(url);        continue;clean:        pap_event_destroy(p);        http_destroy_headers(push_headers);        http_destroy_headers(content_headers);        octstr_destroy(pap_content);        octstr_destroy(push_data);        octstr_destroy(rdf_content);        octstr_destroy(content_header);        octstr_destroy(boundary);        octstr_destroy(url);        continue;ferror:        pap_event_destroy(p);        http_destroy_headers(push_headers);        http_destroy_cgiargs(cgivars);        octstr_destroy(username);        octstr_destroy(url);        octstr_destroy(ip);        octstr_destroy(mime_content);        continue;herror:        pap_event_destroy(p);        http_destroy_headers(push_headers);        http_destroy_cgiargs(cgivars);        octstr_destroy(username);        octstr_destroy(url);        continue;berror:        pap_event_destroy(p);        http_destroy_headers(push_headers);        http_destroy_cgiargs(cgivars);        octstr_destroy(username);        octstr_destroy(mime_content);        octstr_destroy(content_header);        octstr_destroy(boundary);        octstr_destroy(url);        continue;    }}/* * Operations needed when push proxy gateway receives a new push message are  * defined in ppg Chapter 6. We create machines when error, too, because we  * must then have a reportable message error state. * Output: current HTTP Client state. * Return 1 if the push content was OK, 0 if it was not transformable. */static int handle_push_message(HTTPClient **c, WAPEvent *e, int status){    int cless,        session_exists,        bearer_supported,        dummy,        constraints,        message_transformable,        coriented_possible;    long coded_appid_value;    PPGPushMachine *pm;    PPGSessionMachine *sm;    WAPAddrTuple *tuple;    Octstr *push_data,           *cliaddr,           *type;    List *push_headers;       push_data = e->u.Push_Message.push_data;    push_headers = e->u.Push_Message.push_headers;    cliaddr = e->u.Push_Message.address_value;    session_exists = 0;    sm = session_find_using_pi_client_address(cliaddr);    coded_appid_value = check_x_wap_application_id_header(&push_headers);    cless = cless_accepted(e, sm);    message_transformable = transform_message(&e, &tuple, push_headers, cless,                                               &type);    if (!sm && !cless) {        sm = store_session_data(sm, e, tuple, &session_exists);     }    if (!store_push_data(&pm, sm, e, tuple, cless)) {        warning(0, "PPG: handle_push_message: duplicate push id");        *c = response_push_message(pm, PAP_DUPLICATE_PUSH_ID, status);        goto no_start;    }        if (!message_transformable) {	pm = update_push_data_with_attribute(&sm, pm,         PAP_TRANSFORMATION_FAILURE, PAP_UNDELIVERABLE1);          if (tuple != NULL)   	    *c = response_push_message(pm, PAP_TRANSFORMATION_FAILURE, status);        else	    *c = response_push_message(pm, PAP_ADDRESS_ERROR, status);        goto no_transformation;    }        dummy = 0;    pm = update_push_data_with_attribute(&sm, pm, dummy, PAP_PENDING);        bearer_supported = select_bearer_network(&e);    if (!bearer_supported) {        pm = update_push_data_with_attribute(&sm, pm, dummy,             PAP_UNDELIVERABLE2);        *c = response_push_message(pm, PAP_REQUIRED_BEARER_NOT_AVAILABLE, status);	    goto no_start;    }        if ((constraints = delivery_time_constraints(e, pm)) == TIME_EXPIRED) {        pm = update_push_data_with_attribute(&sm, pm, PAP_FORBIDDEN,                                              PAP_EXPIRED);        *c = response_push_message(pm, PAP_FORBIDDEN, status);	    goto no_start;    }/* * If time is to early for delivering the push message, we do not remove push * data. We response PI here, so that "accepted for processing" means "no  * error messages to come". */     *c = response_push_message(pm, PAP_ACCEPTED_FOR_PROCESSING, status);    info(0, "PPG: handle_push_message: push message accepted for processing");    if (constraints == TIME_TOO_EARLY)	    goto store_push;    if (constraints == NO_CONSTRAINTS) {	http_header_mark_transformation(pm->push_headers, pm->push_data, type);        if (sm)            sm = update_session_data_with_headers(sm, pm);         if (!confirmation_requested(e)) {            pm = deliver_unit_push(NOT_LAST, pm, sm, session_exists);            goto unit_push_delivered;	} 	              if (session_exists) {            deliver_confirmed_push(NOT_LAST, pm, sm);           } else {             coriented_possible = coriented_deliverable(coded_appid_value); 	    http_header_remove_all(e->u.Push_Message.push_headers,                                    "Content-Type");              if (coriented_possible) {                create_session(e, pm);            } else {                warning(0, "PPG: handle_push_message: wrong app id for confirmed"                        " push session creation");                *c = response_push_message(pm, PAP_BAD_REQUEST, status);            }        }    }    wap_addr_tuple_destroy(tuple);    octstr_destroy(type);    wap_event_destroy(e);    return 1;unit_push_delivered:    wap_addr_tuple_destroy(tuple);    remove_push_data(sm, pm, cless);    octstr_destroy(type);    wap_event_destroy(e);    return 1;store_push:    wap_addr_tuple_destroy(tuple);    octstr_destroy(type);    wap_event_destroy(e);    return 1;no_transformation:    wap_addr_tuple_destroy(tuple);    remove_push_data(sm, pm, cless);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -