RTBKit  0.9
Open-source framework to create real-time ad bidding systems.
openrtb/openrtb_parsing.cc
00001 /* openrtb_parsing.cc
00002    Jeremy Barnes, 22 February 2013
00003    Copyright (c) 2013 Datacratic Inc.  All rights reserved.
00004 
00005    Structure descriptions for OpenRTB.
00006 */
00007 
00008 #include "openrtb_parsing.h"
00009 #include "soa/types/json_parsing.h"
00010 
00011 using namespace OpenRTB;
00012 //using namespace RTBKIT;
00013 using namespace std;
00014 
00015 namespace Datacratic {
00016 
00017 DefaultDescription<BidRequest>::
00018 DefaultDescription()
00019 {
00020     onUnknownField = [=] (BidRequest * br, JsonParsingContext & context)
00021         {
00022             //cerr << "got unknown field " << context.printPath() << endl;
00023 
00024             std::function<Json::Value & (int, Json::Value &)> getEntry
00025             = [&] (int n, Json::Value & curr) -> Json::Value &
00026             {
00027                 if (n == context.path.size())
00028                     return curr;
00029                 else if (context.path[n].index != -1)
00030                     return getEntry(n + 1, curr[context.path[n].index]);
00031                 else return getEntry(n + 1, curr[context.path[n].fieldName()]);
00032             };
00033 
00034             getEntry(0, br->unparseable)
00035                 = context.expectJson();
00036         };
00037 
00038     addField("id", &BidRequest::id, "Bid Request ID");
00039     addField("imp", &BidRequest::imp, "Impressions");
00040     //addField("context", &BidRequest::context, "Context of bid request");
00041     addField("site", &BidRequest::site, "Information about site the request is on");
00042     addField("app", &BidRequest::app, "Information about the app the request is being shown in");
00043     addField("device", &BidRequest::device, "Information about the device on which the request was made");
00044     addField("user", &BidRequest::user, "Information about the user who is making the request");
00045     addField("at", &BidRequest::at, "Type of auction: 1(st) or 2(nd)");
00046     addField("tmax", &BidRequest::tmax, "Maximum response time (ms)");
00047     addField("wseat", &BidRequest::wseat, "Allowable seats");
00048     addField("allimps", &BidRequest::allimps, "Set to 1 if all impressions on this page are in the bid request");
00049     addField("cur", &BidRequest::cur, "List of acceptable currencies to bid in");
00050     addField("bcat", &BidRequest::bcat, "Blocked advertiser content categories");
00051     addField("badv", &BidRequest::badv, "Blocked adversiser domains");
00052     addField("ext", &BidRequest::ext, "Extended fields outside of protocol");
00053     addField("unparseable", &BidRequest::unparseable, "Unparseable fields are collected here");
00054 }
00055 
00056 DefaultDescription<Impression>::
00057 DefaultDescription()
00058 {
00059     addField("id", &Impression::id, "Impression ID within bid request");
00060     addField("banner", &Impression::banner, "Banner information if a banner ad");
00061     addField("video", &Impression::video, "Video information if a video ad");
00062     addField("displaymanager", &Impression::displaymanager, "Display manager that renders the ad");
00063     addField("displaymanagerver", &Impression::displaymanagerver, "Version of the display manager");
00064     addField("instl", &Impression::instl, "Is the ad interstitial");
00065     addField("tagid", &Impression::tagid, "Add tag ID for auction");
00066     addField("bidfloor", &Impression::bidfloor, "Bid floor in CPM of currency");
00067     addField("bidfloorcur", &Impression::bidfloorcur, "Currency for bid floor");
00068     addField("iframebuster", &Impression::iframebuster, "Supported iframe busters");
00069     addField("ext", &Impression::ext, "Extended impression attributes");
00070 }
00071 
00072 DefaultDescription<OpenRTB::Content>::
00073 DefaultDescription()
00074 {
00075     addField("id", &Content::id, "Unique identifier representing the content");
00076     addField("episode", &Content::episode, "Unique identifier representing the episode");
00077     addField("title", &Content::title, "Title of the content");
00078     addField("series", &Content::series, "Series to which the content belongs");
00079     addField("season", &Content::season, "Season to which the content belongs");
00080     addField("url", &Content::url, "URL of the content's original location");
00081     addField("cat", &Content::cat, "IAB content categories of the content");
00082     addField("videoquality", &Content::videoquality, "Quality of the video");
00083     ValueDescriptionT<std::string> * kwdesc = new CommaSeparatedListDescription();
00084     addField("keywords", &Content::keywords, "Keywords describing the keywords", kwdesc);
00085     addField("contentrating", &Content::contentrating, "Rating of the content");
00086     addField("userrating", &Content::userrating, "User-provided rating of the content");
00087     addField("context", &Content::context, "Rating context");
00088     addField("livestream", &Content::livestream, "Is this being live streamed?");
00089     addField("sourcerelationship", &Content::sourcerelationship, "Relationship with content source");
00090     addField("producer", &Content::producer, "Content producer");
00091     addField("len", &Content::len, "Content length in seconds");
00092 }
00093 
00094 DefaultDescription<OpenRTB::Banner>::
00095 DefaultDescription()
00096 {
00097     addField<List<int>>("w", &Banner::w, "Width of ad in pixels",
00098              new FormatListDescription());
00099     addField<List<int>>("h", &Banner::h, "Height of ad in pixels",
00100              new FormatListDescription());
00101     addField("id", &Banner::id, "Ad ID");
00102     addField("pos", &Banner::pos, "Ad position");
00103     addField("btype", &Banner::btype, "Blocked creative types");
00104     addField("battr", &Banner::battr, "Blocked creative attributes");
00105     addField("mimes", &Banner::mimes, "Whitelist of content MIME types (none = all)");
00106     addField("topframe", &Banner::topframe, "Is it in the top frame or an iframe?");
00107     addField("expdir", &Banner::expdir, "Expandable ad directions");
00108     addField("api", &Banner::api, "Supported APIs");
00109 }
00110 
00111 DefaultDescription<OpenRTB::Video>::
00112 DefaultDescription()
00113 {
00114     addField("mimes", &Video::mimes, "Content MIME types supported");
00115     addField("linearity", &Video::linearity, "Ad linearity");
00116     addField("minduration", &Video::minduration, "Minimum duration in seconds");
00117     addField("maxduration", &Video::maxduration, "Maximum duration in seconds");
00118     addField("protocol", &Video::protocol, "Bid response protocols supported");
00119     addField("w", &Video::w, "Width of player in pixels");
00120     addField("h", &Video::h, "Height of player in pixels");
00121     addField("startdelay", &Video::startdelay, "Starting delay in seconds of video");
00122     addField("sequence", &Video::sequence, "Which ad number in the video");
00123     addField("battr", &Video::battr, "Which creative attributes are blocked");
00124     addField("maxextended", &Video::maxextended, "Maximum extended video ad duration");
00125     addField("minbitrate", &Video::minbitrate, "Minimum bitrate for ad in kbps");
00126     addField("maxbitrate", &Video::maxbitrate, "Maximum bitrate for ad in kbps");
00127     addField("boxingallowed", &Video::boxingallowed, "Is letterboxing allowed?");
00128     addField("playbackmethod", &Video::playbackmethod, "Available playback methods");
00129     addField("delivery", &Video::delivery, "Available delivery methods");
00130     addField("pos", &Video::pos, "Ad position");
00131     addField("companionad", &Video::companionad, "List of companion banners available");
00132     addField("api", &Video::api, "List of supported API frameworks");
00133 }
00134 
00135 DefaultDescription<OpenRTB::Publisher>::
00136 DefaultDescription()
00137 {
00138     addField("id", &Publisher::id, "Unique ID representing the publisher/producer");
00139     addField("name", &Publisher::name, "Publisher/producer name");
00140     addField("cat", &Publisher::cat, "Content categories");
00141     addField("domain", &Publisher::domain, "Domain name of publisher");
00142 }
00143 
00144 DefaultDescription<OpenRTB::Context>::
00145 DefaultDescription()
00146 {
00147     addField("id", &Context::id, "Site or app ID on the exchange");
00148     addField("name", &Context::name, "Site or app name");
00149     addField("domain", &Context::domain, "Site or app domain");
00150     addField("cat", &Context::cat, "IAB content categories for the site/app");
00151     addField("sectioncat", &Context::sectioncat, "IAB content categories for site/app section");
00152     addField("pagecat", &Context::pagecat, "IAB content categories for site/app page");
00153     addField("privacypolicy", &Context::privacypolicy, "Site or app has a privacy policy");
00154     addField("publisher", &Context::publisher, "Publisher of site or app");
00155     addField("content", &Context::content, "Content of site or app");
00156     ValueDescriptionT<std::string> * kwdesc = new CommaSeparatedListDescription();
00157     addField("keywords", &Context::keywords, "Keywords describing siter or app", kwdesc);
00158     addField("ext", &Context::ext, "Extensions to the protocol go here");
00159 }
00160 
00161 DefaultDescription<OpenRTB::Site>::
00162 DefaultDescription()
00163 {
00164     addParent<OpenRTB::Context>();
00165 
00166     //addField("id",   &Context::id,   "Site ID");
00167     addField("page",   &SiteInfo::page,   "URL of the page");
00168     addField("ref",    &SiteInfo::ref,    "Referrer URL to the page");
00169     addField("search", &SiteInfo::search, "Search string to page");
00170 }
00171 
00172 DefaultDescription<OpenRTB::App>::
00173 DefaultDescription()
00174 {
00175     addParent<OpenRTB::Context>();
00176 
00177     addField("ver",    &AppInfo::ver,     "Application version");
00178     addField("bundle", &AppInfo::bundle,  "Application bundle name");
00179     addField("paid",   &AppInfo::paid,    "Is a paid version of the app");
00180 }
00181 
00182 DefaultDescription<OpenRTB::Geo>::
00183 DefaultDescription()
00184 {
00185     addField("lat", &Geo::lat, "Latiture of user in degrees from equator");
00186     addField("lon", &Geo::lon, "Longtitude of user in degrees (-180 to 180)");
00187     addField("country", &Geo::country, "ISO 3166-1 country code");
00188     addField("region", &Geo::region, "ISO 3166-2 Region code");
00189     addField("regionfips104", &Geo::regionfips104, "FIPS 10-4 region code");
00190     addField("metro", &Geo::metro, "Metropolitan region (Google Metro code");
00191     addField("city", &Geo::city, "City name (UN Code for Trade and Transport)");
00192     addField("zip", &Geo::zip, "Zip or postal code");
00193     addField("type", &Geo::type, "Source of location data");
00194     addField("latlonconsent", &Geo::latlonconsent, "User has given consent for lat/lon information to be used");
00195 }
00196 
00197 DefaultDescription<OpenRTB::Device>::
00198 DefaultDescription()
00199 {
00200     addField("dnt", &Device::dnt, "Is do not track set");
00201     addField("ua", &Device::ua, "User agent of device");
00202     addField("ip", &Device::ip, "IP address of device");
00203     addField("geo", &Device::geo, "Geographic location of device");
00204     addField("didsha1", &Device::didsha1, "SHA-1 Device ID");
00205     addField("didmd5", &Device::didmd5, "MD5 Device ID");
00206     addField("dpidsha1", &Device::dpidsha1, "SHA-1 Device Platform ID");
00207     addField("dpidmd5", &Device::dpidmd5, "MD5 Device Platform ID");
00208     addField("ipv6", &Device::ipv6, "Device IPv6 address");
00209     addField("carrier", &Device::carrier, "Carrier or ISP derived from IP address");
00210     addField("language", &Device::language, "Browser language");
00211     addField("make", &Device::make, "Device make");
00212     addField("model", &Device::model, "Device model");
00213     addField("os", &Device::os, "Device OS");
00214     addField("osv", &Device::osv, "Device OS version");
00215     addField("js", &Device::js, "Javascript is supported");
00216     addField("connectiontype", &Device::connectiontype, "Device connection type");
00217     addField("devicetype", &Device::devicetype, "Device type");
00218     addField("flashver", &Device::flashver, "Flash version on device");
00219     addField("ext", &Device::ext, "Extensions to device field go here");
00220 }
00221 
00222 DefaultDescription<OpenRTB::Segment>::
00223 DefaultDescription()
00224 {
00225     addField("id", &Segment::id, "Segment ID");
00226     addField("name", &Segment::name, "Segment name");
00227     addField("value", &Segment::value, "Segment value");
00228     addField("segmentusecost", &Segment::segmentusecost, "Segment use cost in CPM");
00229 }
00230 
00231 DefaultDescription<OpenRTB::Data>::
00232 DefaultDescription()
00233 {
00234     addField("id", &Data::id, "Segment ID");
00235     addField("name", &Data::name, "Segment name");
00236     addField("segment", &Data::segment, "Data segment");
00237     addField("datausecost", &Data::datausecost, "Cost of using data in CPM");
00238     addField("usecostcurrency", &Data::usecostcurrency, "Currency for use cost");
00239 }
00240 
00241 DefaultDescription<OpenRTB::User>::
00242 DefaultDescription()
00243 {
00244     addField("id", &User::id, "Exchange specific user ID");
00245     addField("buyeruid", &User::buyeruid, "Seat specific user ID");
00246     addField("yob", &User::yob, "Year of birth");
00247     addField("gender", &User::gender, "Gender");
00248     ValueDescriptionT<std::string> * kwdesc = new CommaSeparatedListDescription();
00249     addField("keywords", &User::keywords, "Keywords about user", kwdesc);
00250     addField("customdata", &User::customdata, "Exchange-specific custom data");
00251     addField("geo", &User::geo, "Geolocation of user at registration");
00252     addField("data", &User::data, "User segment data");
00253     addField("tz", &User::tz, "Timezone offset of user in seconds wrt GMT");
00254     addField("sessiondepth", &User::sessiondepth, "Session depth of user in visits");
00255 }
00256 
00257 DefaultDescription<OpenRTB::Bid>::
00258 DefaultDescription()
00259 {
00260     addField("id", &Bid::id, "Bidder's ID to identify the bid");
00261     addField("impid", &Bid::impid, "ID of impression");
00262     addField("price", &Bid::price, "CPM price to bid for the impression");
00263     addField("adid", &Bid::adid, "ID of ad to be served if bid is won");
00264     addField("nurl", &Bid::nurl, "Win notice/ad markup URL");
00265     addField("adm", &Bid::adm, "Ad markup");
00266     addField("adomain", &Bid::adomain, "Advertiser domain(s)");
00267     addField("iurl", &Bid::iurl, "Image URL for content checking");
00268     addField("cid", &Bid::cid, "Campaign ID");
00269     addField("crid", &Bid::crid, "Creative ID");
00270     addField("attr", &Bid::attr, "Creative attributes");
00271     addField("ext", &Bid::ext, "Extensions");
00272 }
00273 
00274 DefaultDescription<OpenRTB::SeatBid>::
00275 DefaultDescription()
00276 {
00277     addField("bid", &SeatBid::bid, "Bids made for this seat");
00278     addField("seat", &SeatBid::seat, "Seat name who is bidding");
00279     addField("group", &SeatBid::group, "Do we require all bids to be won in a group?");
00280     addField("ext", &SeatBid::ext, "Extensions");
00281 }
00282 
00283 DefaultDescription<OpenRTB::BidResponse>::
00284 DefaultDescription()
00285 {
00286     addField("id", &BidResponse::id, "ID of auction");
00287     addField("seatbid", &BidResponse::seatbid, "Array of bids for each seat");
00288     addField("bidid", &BidResponse::bidid, "Bidder's internal ID for this bid");
00289     addField("cur", &BidResponse::cur, "Currency in which we're bidding");
00290     addField("customData", &BidResponse::customData, "Custom data to be stored for user");
00291     addField("ext", &BidResponse::ext, "Extensions");
00292 }
00293 
00294 } // namespace Datacratic
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator