Changeset 5055 for pjproject/trunk


Ignore:
Timestamp:
Apr 8, 2015 10:10:44 AM (10 years ago)
Author:
riza
Message:

Re #1838: Enable application to provide its own external resolver implementation.

Location:
pjproject/trunk/pjsip
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/include/pjsip/sip_endpoint.h

    r4275 r5055  
    392392 
    393393/** 
     394 * Set the DNS external resolver implementation to use in the SIP resolver.  
     395 * 
     396 * Note that naturally when implementing its own resolver, application would not 
     397 * need the internal resolver, hence this function will also destroy the  
     398 * PJLIB-UTIL DNS resolver if any (e.g: set using #pjsip_endpt_set_resolver()).  
     399 * Application that needs it, still be able create its own instance.  
     400 * 
     401 * @param res       The SIP resolver engine. 
     402 * @param ext_res   The external resolver implementation callback. This argument 
     403 *                  can be NULL to reset the whole external implementation.  
     404 *                  However, it is prohibited to reset individual callback. 
     405 *  
     406 * @return          PJ_SUCCESS on success, or the appropriate error code. 
     407 */ 
     408PJ_DECL(pj_status_t) pjsip_endpt_set_ext_resolver(pjsip_endpoint *endpt, 
     409                                                  pjsip_ext_resolver *ext_res); 
     410 
     411/** 
    394412 * Get the DNS resolver being used by the SIP resolver. 
    395413 * 
  • pjproject/trunk/pjsip/include/pjsip/sip_resolve.h

    r3553 r5055  
    119119 *    response caching, query aggregation, parallel nameservers, fallback 
    120120 *    nameserver, etc., which will be described below. 
     121 *  - Enable application to provide its own resolver implementation.   
    121122 *  
    122123 * 
     
    156157 * PJSIP needs to send SIP request/response messages. 
    157158 * 
     159 * \section PJSIP_RESOLVE_EXT_RESOLVER External Resolver 
     160 *  
     161 * As an alternative to enabling PJLIB-UTIL DNS resolver, application can  
     162 * provide its own resolver implementation by defining the callback in  
     163 * pjsip_ext_resolver and pass the callback to  
     164 * #pjsip_resolver_set_ext_resolver() function. Please note that if the  
     165 * implementation needs feature from PJLIB-UTL DNS resolver, it has to create 
     166 * its own PJLIB-UTL DNS resolver instance. 
    158167 * 
    159168 * \section PJSIP_RESOLVE_REFERENCE Reference 
     
    208217 
    209218/** 
     219 * This structure describes application callback to receive various event from  
     220 * the SIP resolver engine. Application can use this for its own resolver 
     221 * implementation.  
     222 */ 
     223typedef struct pjsip_ext_resolver 
     224{ 
     225    /** 
     226     * Notify application when the resolution should begin. 
     227     * 
     228     * @param resolver      The resolver engine. 
     229     * @param pool          The pool to allocate resolver job. 
     230     * @param target        The target specification to be resolved. 
     231     * @param token         A user defined token to be passed back to callback  
     232     *                      function. 
     233     * @param cb            The callback function. 
     234     */ 
     235    void (*resolve) (pjsip_resolver_t *resolver, pj_pool_t *pool, 
     236                     const pjsip_host_info *target, void *token, 
     237                     pjsip_resolver_callback *cb); 
     238 
     239} pjsip_ext_resolver; 
     240 
     241 
     242/** 
    210243 * Create SIP resolver engine. Note that this function is normally called 
    211244 * internally by pjsip_endpoint instance. 
     
    237270                                                 pj_dns_resolver *dns_res); 
    238271 
     272 
     273/** 
     274 * Set the DNS external resolver implementation to use in the SIP resolver  
     275 * engine. Naturally when implementing its own resolver, application would not 
     276 * need the internal resolver, hence this function will also destroy the  
     277 * PJLIB-UTIL DNS resolver if any (e.g: set using  
     278 * #pjsip_resolver_set_resolver()). Application that needs it, still be able  
     279 * create its own instance. 
     280 * 
     281 * Note that application normally will use #pjsip_endpt_set_ext_resolver()  
     282 * instead since it does not normally have access to the SIP resolver instance.  
     283 * 
     284 * @param res       The SIP resolver engine. 
     285 * @param ext_res   The external resolver implementation callback. This argument 
     286 *                  can be NULL to reset the whole external implementation.  
     287 *                  However, it is prohibited to reset individual callback. 
     288 *  
     289 * @return          PJ_SUCCESS on success, or the appropriate error code. 
     290 */ 
     291PJ_DECL(pj_status_t) pjsip_resolver_set_ext_resolver( 
     292                                                pjsip_resolver_t *res, 
     293                                                pjsip_ext_resolver *ext_res); 
    239294 
    240295/** 
  • pjproject/trunk/pjsip/src/pjsip/sip_endpoint.c

    r4704 r5055  
    11291129 
    11301130/* 
     1131 * Set DNS external resolver implementation to be used by the SIP resolver. 
     1132 */ 
     1133PJ_DEF(pj_status_t) pjsip_endpt_set_ext_resolver(pjsip_endpoint *endpt, 
     1134                                                 pjsip_ext_resolver *ext_res) 
     1135{ 
     1136    return pjsip_resolver_set_ext_resolver(endpt->resolver, ext_res); 
     1137} 
     1138 
     1139/* 
    11311140 * Get the DNS resolver being used by the SIP resolver. 
    11321141 */ 
  • pjproject/trunk/pjsip/src/pjsip/sip_resolve.c

    r4954 r5055  
    7171{ 
    7272    pj_dns_resolver *res; 
     73    pjsip_ext_resolver *ext_res; 
    7374}; 
    7475 
     
    115116} 
    116117 
     118/* 
     119 * Public API to set the DNS external resolver implementation for the SIP  
     120 * resolver. 
     121 */ 
     122PJ_DEF(pj_status_t) pjsip_resolver_set_ext_resolver(pjsip_resolver_t *res, 
     123                                                    pjsip_ext_resolver *ext_res) 
     124{ 
     125    if (ext_res && !ext_res->resolve) 
     126        return PJ_EINVAL; 
     127 
     128    if (ext_res && res->res) { 
     129#if PJSIP_HAS_RESOLVER 
     130        pj_dns_resolver_destroy(res->res, PJ_FALSE); 
     131#endif 
     132        res->res = NULL; 
     133    } 
     134    res->ext_res = ext_res; 
     135    return PJ_SUCCESS; 
     136} 
     137 
    117138 
    118139/* 
     
    175196    struct query *query; 
    176197    pjsip_transport_type_e type = target->type; 
     198 
     199    /* If an external implementation has been provided use it instead */ 
     200    if (resolver->ext_res) { 
     201        (*resolver->ext_res->resolve)(resolver, pool, target, token, cb); 
     202        return; 
     203    } 
    177204 
    178205    /* Is it IP address or hostname? And if it's an IP, which version? */ 
Note: See TracChangeset for help on using the changeset viewer.