Ignore:
Timestamp:
Nov 6, 2013 8:05:11 AM (9 years ago)
Author:
bennylp
Message:

Re #1519: Added persistent API in pjsua2, with JSON as the format. The API is extensible to support more formats. All config structures are serializable now. Tested in Python.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/projects/pjsua2/pjsip/include/pjsua2/types.hpp

    r4639 r4644  
    11/* $Id$ */ 
    22/*  
    3  * Copyright (C) 2008-2012 Teluu Inc. (http://www.teluu.com) 
     3 * Copyright (C) 2013 Teluu Inc. (http://www.teluu.com) 
    44 * 
    55 * This program is free software; you can redistribute it and/or modify 
     
    2121 
    2222/** 
    23  * @file pjsua2/ua.hpp 
    24  * @brief PJSUA2 Base Agent Operation 
     23 * @file pjsua2/types.hpp 
     24 * @brief PJSUA2 Base Types 
    2525 */ 
    2626#include <pjsua2/config.hpp> 
     
    207207}; 
    208208 
    209 ////////////////////////////////////////////////////////////////////////////// 
    210  
    211 /** 
    212  * Credential information. Credential contains information to authenticate 
    213  * against a service. 
    214  */ 
    215 struct AuthCredInfo 
    216 { 
    217     /** 
    218      * The authentication scheme (e.g. "digest"). 
    219      */ 
    220     string      scheme; 
    221  
    222     /** 
    223      * Realm on which this credential is to be used. Use "*" to make 
    224      * a credential that can be used to authenticate against any challenges. 
    225      */ 
    226     string      realm; 
    227  
    228     /** 
    229      * Authentication user name. 
    230      */ 
    231     string      username; 
    232  
    233     /** 
    234      * Type of data that is contained in the "data" field. Use 0 if the data 
    235      * contains plain text password. 
    236      */ 
    237     int         dataType; 
    238  
    239     /** 
    240      * The data, which can be a plain text password or a hashed digest. 
    241      */ 
    242     string      data; 
    243  
    244     /* 
    245      * Digest AKA credential information. Note that when AKA credential 
    246      * is being used, the \a data field of this #pjsip_cred_info is 
    247      * not used, but it still must be initialized to an empty string. 
    248      * Please see \ref PJSIP_AUTH_AKA_API for more information. 
    249      */ 
    250  
    251     /** Permanent subscriber key. */ 
    252     string      akaK; 
    253  
    254     /** Operator variant key. */ 
    255     string      akaOp; 
    256  
    257     /** Authentication Management Field */ 
    258     string      akaAmf; 
    259  
    260     /** Default constructor */ 
    261     AuthCredInfo(); 
    262  
    263     /** Construct a credential with the specified parameters */ 
    264     AuthCredInfo(const string &scheme, 
    265                  const string &realm, 
    266                  const string &user_name, 
    267                  const int data_type, 
    268                  const string data); 
    269  
    270 }; 
    271  
    272  
    273 ////////////////////////////////////////////////////////////////////////////// 
    274  
    275 /** 
    276  * TLS transport settings, to be specified in TransportConfig. 
    277  */ 
    278 struct TlsConfig 
    279 { 
    280     /** 
    281      * Certificate of Authority (CA) list file. 
    282      */ 
    283     string              CaListFile; 
    284  
    285     /** 
    286      * Public endpoint certificate file, which will be used as client- 
    287      * side  certificate for outgoing TLS connection, and server-side 
    288      * certificate for incoming TLS connection. 
    289      */ 
    290     string              certFile; 
    291  
    292     /** 
    293      * Optional private key of the endpoint certificate to be used. 
    294      */ 
    295     string              privKeyFile; 
    296  
    297     /** 
    298      * Password to open private key. 
    299      */ 
    300     string              password; 
    301  
    302     /** 
    303      * TLS protocol method from #pjsip_ssl_method. 
    304      * 
    305      * Default is PJSIP_SSL_UNSPECIFIED_METHOD (0), which in turn will 
    306      * use PJSIP_SSL_DEFAULT_METHOD, which default value is 
    307      * PJSIP_TLSV1_METHOD. 
    308      */ 
    309     pjsip_ssl_method    method; 
    310  
    311     /** 
    312      * Ciphers and order preference. The Endpoint::utilSslGetAvailableCiphers() 
    313      * can be used to check the available ciphers supported by backend. 
    314      * If the array is empty, then default cipher list of the backend 
    315      * will be used. 
    316      */ 
    317     IntVector           ciphers; 
    318  
    319     /** 
    320      * Specifies TLS transport behavior on the server TLS certificate 
    321      * verification result: 
    322      * - If \a verifyServer is disabled, TLS transport will just notify 
    323      *   the application via #pjsip_tp_state_callback with state 
    324      *   PJSIP_TP_STATE_CONNECTED regardless TLS verification result. 
    325      * - If \a verifyServer is enabled, TLS transport will be shutdown 
    326      *   and application will be notified with state 
    327      *   PJSIP_TP_STATE_DISCONNECTED whenever there is any TLS verification 
    328      *   error, otherwise PJSIP_TP_STATE_CONNECTED will be notified. 
    329      * 
    330      * In any cases, application can inspect #pjsip_tls_state_info in the 
    331      * callback to see the verification detail. 
    332      * 
    333      * Default value is false. 
    334      */ 
    335     bool                verifyServer; 
    336  
    337     /** 
    338      * Specifies TLS transport behavior on the client TLS certificate 
    339      * verification result: 
    340      * - If \a verifyClient is disabled, TLS transport will just notify 
    341      *   the application via #pjsip_tp_state_callback with state 
    342      *   PJSIP_TP_STATE_CONNECTED regardless TLS verification result. 
    343      * - If \a verifyClient is enabled, TLS transport will be shutdown 
    344      *   and application will be notified with state 
    345      *   PJSIP_TP_STATE_DISCONNECTED whenever there is any TLS verification 
    346      *   error, otherwise PJSIP_TP_STATE_CONNECTED will be notified. 
    347      * 
    348      * In any cases, application can inspect #pjsip_tls_state_info in the 
    349      * callback to see the verification detail. 
    350      * 
    351      * Default value is PJ_FALSE. 
    352      */ 
    353     bool                verifyClient; 
    354  
    355     /** 
    356      * When acting as server (incoming TLS connections), reject incoming 
    357      * connection if client doesn't supply a TLS certificate. 
    358      * 
    359      * This setting corresponds to SSL_VERIFY_FAIL_IF_NO_PEER_CERT flag. 
    360      * Default value is PJ_FALSE. 
    361      */ 
    362     bool                requireClientCert; 
    363  
    364     /** 
    365      * TLS negotiation timeout to be applied for both outgoing and incoming 
    366      * connection, in milliseconds. If zero, the SSL negotiation doesn't 
    367      * have a timeout. 
    368      * 
    369      * Default: zero 
    370      */ 
    371     unsigned            msecTimeout; 
    372  
    373     /** 
    374      * QoS traffic type to be set on this transport. When application wants 
    375      * to apply QoS tagging to the transport, it's preferable to set this 
    376      * field rather than \a qosParam fields since this is more portable. 
    377      * 
    378      * Default value is PJ_QOS_TYPE_BEST_EFFORT. 
    379      */ 
    380     pj_qos_type         qosType; 
    381  
    382     /** 
    383      * Set the low level QoS parameters to the transport. This is a lower 
    384      * level operation than setting the \a qosType field and may not be 
    385      * supported on all platforms. 
    386      * 
    387      * By default all settings in this structure are disabled. 
    388      */ 
    389     pj_qos_params       qosParams; 
    390  
    391     /** 
    392      * Specify if the transport should ignore any errors when setting the QoS 
    393      * traffic type/parameters. 
    394      * 
    395      * Default: PJ_TRUE 
    396      */ 
    397     bool                qosIgnoreError; 
    398  
    399 public: 
    400     /** Default constructor initialises with default values */ 
    401     TlsConfig(); 
    402  
    403     /** Convert to pjsip */ 
    404     pjsip_tls_setting toPj() const; 
    405  
    406     /** Convert from pjsip */ 
    407     void fromPj(const pjsip_tls_setting &prm); 
    408 }; 
    409  
    410  
    411 /** 
    412  * Parameters to create a transport instance. 
    413  */ 
    414 struct TransportConfig 
    415 { 
    416     /** 
    417      * UDP port number to bind locally. This setting MUST be specified 
    418      * even when default port is desired. If the value is zero, the 
    419      * transport will be bound to any available port, and application 
    420      * can query the port by querying the transport info. 
    421      */ 
    422     unsigned            port; 
    423  
    424     /** 
    425      * Specify the port range for socket binding, relative to the start 
    426      * port number specified in \a port. Note that this setting is only 
    427      * applicable when the start port number is non zero. 
    428      * 
    429      * Default value is zero. 
    430      */ 
    431     unsigned            portRange; 
    432  
    433     /** 
    434      * Optional address to advertise as the address of this transport. 
    435      * Application can specify any address or hostname for this field, 
    436      * for example it can point to one of the interface address in the 
    437      * system, or it can point to the public address of a NAT router 
    438      * where port mappings have been configured for the application. 
    439      * 
    440      * Note: this option can be used for both UDP and TCP as well! 
    441      */ 
    442     string              publicAddress; 
    443  
    444     /** 
    445      * Optional address where the socket should be bound to. This option 
    446      * SHOULD only be used to selectively bind the socket to particular 
    447      * interface (instead of 0.0.0.0), and SHOULD NOT be used to set the 
    448      * published address of a transport (the public_addr field should be 
    449      * used for that purpose). 
    450      * 
    451      * Note that unlike public_addr field, the address (or hostname) here 
    452      * MUST correspond to the actual interface address in the host, since 
    453      * this address will be specified as bind() argument. 
    454      */ 
    455     string              boundAddress; 
    456  
    457     /** 
    458      * This specifies TLS settings for TLS transport. It is only be used 
    459      * when this transport config is being used to create a SIP TLS 
    460      * transport. 
    461      */ 
    462     TlsConfig           tlsConfig; 
    463  
    464     /** 
    465      * QoS traffic type to be set on this transport. When application wants 
    466      * to apply QoS tagging to the transport, it's preferable to set this 
    467      * field rather than \a qosParam fields since this is more portable. 
    468      * 
    469      * Default is QoS not set. 
    470      */ 
    471     pj_qos_type         qosType; 
    472  
    473     /** 
    474      * Set the low level QoS parameters to the transport. This is a lower 
    475      * level operation than setting the \a qosType field and may not be 
    476      * supported on all platforms. 
    477      * 
    478      * Default is QoS not set. 
    479      */ 
    480     pj_qos_params       qosParams; 
    481  
    482 public: 
    483     /** Default constructor initialises with default values */ 
    484     TransportConfig(); 
    485  
    486     /** Convert from pjsip */ 
    487     void fromPj(const pjsua_transport_config &prm); 
    488  
    489     /** Convert to pjsip */ 
    490     pjsua_transport_config toPj() const; 
    491 }; 
    492  
    493 /** 
    494  * This structure describes transport information returned by 
    495  * Endpoint::transportGetInfo() function. 
    496  */ 
    497 struct TransportInfo 
    498 { 
    499     /** PJSUA transport identification. */ 
    500     TransportId             id; 
    501  
    502     /** Transport type. */ 
    503     pjsip_transport_type_e  type; 
    504  
    505     /** Transport type name. */ 
    506     string                  typeName; 
    507  
    508     /** Transport string info/description. */ 
    509     string                  info; 
    510  
    511     /** Transport flags (see #pjsip_transport_flags_e). */ 
    512     unsigned                flags; 
    513  
    514     /** Local/bound address. */ 
    515     SocketAddress           localAddress; 
    516  
    517     /** Published address (or transport address name). */ 
    518     SocketAddress           localName; 
    519  
    520     /** Current number of objects currently referencing this transport. */ 
    521     unsigned                usageCount; 
    522  
    523     /** Construct from pjsip */ 
    524     TransportInfo(const pjsua_transport_info &info); 
    525  
    526 }; 
    527  
    528 ////////////////////////////////////////////////////////////////////////////// 
    529  
    530 /** 
    531  * This structure describes an incoming SIP message. It corresponds to the 
    532  * pjsip_rx_data structure in PJSIP library. 
    533  */ 
    534 struct SipRxData 
    535 { 
    536     /** 
    537      * A short info string describing the request, which normally contains 
    538      * the request method and its CSeq. 
    539      */ 
    540     string              info; 
    541  
    542     /** 
    543      * The whole message data as a string, containing both the header section 
    544      * and message body section. 
    545      */ 
    546     string              wholeMsg; 
    547  
    548     /** 
    549      * Source IP address of the message. 
    550      */ 
    551     string              srcIp; 
    552  
    553     /** 
    554      * Source port number of the message. 
    555      */ 
    556     unsigned            srcPort; 
    557  
    558     /** 
    559      * Construct from PJSIP's pjsip_rx_data 
    560      */ 
    561     void fromPj(pjsip_rx_data &rdata); 
    562 }; 
    563  
    564  
    565 ////////////////////////////////////////////////////////////////////////////// 
    566  
    567 /** 
    568  * SIP media type containing type and subtype. For example, for 
    569  * "application/sdp", the type is "application" and the subtype is "sdp". 
    570  */ 
    571 struct SipMediaType 
    572 { 
    573     /** Media type. */ 
    574     string              type; 
    575  
    576     /** Media subtype. */ 
    577     string              subType; 
    578 }; 
    579  
    580 /** 
    581  * Simple SIP header. 
    582  */ 
    583 struct SipHeader 
    584 { 
    585     /** 
    586      * Header name. 
    587      */ 
    588     string              hName; 
    589  
    590     /** 
    591      * Header value. 
    592      */ 
    593     string              hValue; 
    594  
    595     /** 
    596      * Initiaize from PJSIP header. 
    597      */ 
    598     void fromPj(const pjsip_hdr *) throw(Error); 
    599  
    600     /** 
    601      * Convert to PJSIP header. 
    602      */ 
    603     pjsip_generic_string_hdr &toPj() const; 
    604  
    605 private: 
    606     /** Interal buffer for conversion to PJSIP header */ 
    607     mutable pjsip_generic_string_hdr    pjHdr; 
    608 }; 
    609  
    610  
    611 /** Array of strings */ 
    612 typedef std::vector<SipHeader> SipHeaderVector; 
    613  
    614 /** 
    615  * This describes each multipart part. 
    616  */ 
    617 struct SipMultipartPart 
    618 { 
    619     /** 
    620      * Optional headers to be put in this multipart part. 
    621      */ 
    622     SipHeaderVector     headers; 
    623  
    624     /** 
    625      * The MIME type of the body part of this multipart part. 
    626      */ 
    627     SipMediaType        contentType; 
    628  
    629     /** 
    630      * The body part of tthis multipart part. 
    631      */ 
    632     string              body; 
    633 }; 
    634  
    635 /** Array of multipart parts */ 
    636 typedef std::vector<SipMultipartPart> SipMultipartPartVector; 
    637  
    638 /** 
    639  * Additional options when sending outgoing SIP message. This corresponds to 
    640  * pjsua_msg_data structure in PJSIP library. 
    641  */ 
    642 struct SipTxOption 
    643 { 
    644     /** 
    645      * Optional remote target URI (i.e. Target header). If NULL, the target 
    646      * will be set to the remote URI (To header). At the moment this field 
    647      * is only used when sending initial INVITE and MESSAGE requests. 
    648      */ 
    649     string              targetUri; 
    650  
    651     /** 
    652      * Additional message headers to be included in the outgoing message. 
    653      */ 
    654     SipHeaderVector     headers; 
    655  
    656     /** 
    657      * MIME type of the message body, if application specifies the messageBody 
    658      * in this structure. 
    659      */ 
    660     string              contentType; 
    661  
    662     /** 
    663      * Optional message body to be added to the message, only when the 
    664      * message doesn't have a body. 
    665      */ 
    666     string              msgBody; 
    667  
    668     /** 
    669      * Content type of the multipart body. If application wants to send 
    670      * multipart message bodies, it puts the parts in multipartParts and set 
    671      * the content type in multipartContentType. If the message already 
    672      * contains a body, the body will be added to the multipart bodies. 
    673      */ 
    674     SipMediaType        multipartContentType; 
    675  
    676     /** 
    677      * Array of multipart parts. If application wants to send multipart 
    678      * message bodies, it puts the parts in \a parts and set the content 
    679      * type in \a multipart_ctype. If the message already contains a body, 
    680      * the body will be added to the multipart bodies. 
    681      */ 
    682     SipMultipartPartVector      multipartParts; 
    683  
    684 }; 
    685  
    686209 
    687210} // namespace pj 
Note: See TracChangeset for help on using the changeset viewer.