| 91 | |
| 92 | |
| 93 | int __register_script_cb( cb_function f, int type, void *param, int prio) |
| 94 | { |
| 95 | /* type checkings */ |
| 96 | if ( (type&(REQ_TYPE_CB|RPL_TYPE_CB|PARSE_ERR_CB))==0 ) { |
| 97 | LM_CRIT("request / reply / error type not specified\n"); |
| 98 | goto error; |
| 99 | } |
| 100 | if ( (type&(PRE_SCRIPT_CB|POST_SCRIPT_CB|PARSE_ERR_CB))==0 || |
| 101 | (type&PRE_SCRIPT_CB && type&POST_SCRIPT_CB) ) { |
| 102 | LM_CRIT("callback POST or PRE type must be exactly one\n"); |
| 103 | goto error; |
| 104 | } |
| 105 | |
| 106 | if (type&PARSE_ERR_CB) { |
| 107 | if (add_callback( &parse_err_cb, f, param, prio)<0) |
| 108 | goto add_error; |
| 109 | } |
| 110 | |
| 111 | if (type&REQ_TYPE_CB) { |
| 112 | /* callback for request script */ |
| 113 | if (type&PRE_SCRIPT_CB) { |
| 114 | if (add_callback( &pre_req_cb, f, param, prio)<0) |
| 115 | goto add_error; |
| 116 | } else if (type&POST_SCRIPT_CB) { |
| 117 | if (add_callback( &post_req_cb, f, param, prio)<0) |
| 118 | goto add_error; |
| 119 | } |
| 120 | } |
| 121 | if (type&RPL_TYPE_CB) { |
| 122 | /* callback (also) for reply script */ |
| 123 | if (type&PRE_SCRIPT_CB) { |
| 124 | if (add_callback( &pre_rpl_cb, f, param, prio)<0) |
| 125 | goto add_error; |
| 126 | } else if (type&POST_SCRIPT_CB) { |
| 127 | if (add_callback( &post_rpl_cb, f, param, prio)<0) |
| 128 | goto add_error; |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | return 0; |
| 133 | add_error: |
| 134 | LM_ERR("failed to add callback\n"); |
| 135 | error: |
| 136 | return -1; |
| 137 | } |
| 138 | |
| 139 | |
| 140 | static inline void destroy_cb_list(struct script_cb **list) |
no test coverage detected