App Store Search & Querying Logic
Relevant source files
The following files were used as context for generating this wiki page:
The App Store Search & Querying Logic module provides the core functionality for discovering and inspecting iOS applications within the Apple ecosystem. This system interfaces with various Apple-hosted APIs—specifically the public iTunes Search/Lookup APIs and private App Store download endpoints—to retrieve application metadata, available versions, and specific release details.
The module is architected around the AppStore interface, which abstracts the complexity of constructing requests with specific country codes (derived from account storefronts), managing authentication tokens, and parsing diverse response formats ranging from JSON to XML-based Property Lists (plists).
Search and Lookup Architecture
The project distinguishes between generic keyword searching and targeted bundle identifier lookups. Both utilize the iTunes API but target different endpoints and query parameters to satisfy different discovery requirements.
Keyword Search
The search functionality allows users to query the App Store using text terms. The system automatically handles country code resolution by extracting it from the user's StoreFront ID before dispatching a GET request to the iTunes search domain.
Targeted Lookup
The lookup logic is used when a specific bundleIdentifier is known. Unlike search, it limits results to a single entry and focuses on resolving a unique application mapping.
Versioning and Metadata Retrieval
Beyond initial discovery, the system provides logic to query the version history of an application and specific metadata for historical versions. This involves interacting with private App Store endpoints that require machine GUIDs (derived from MAC addresses) and account-specific Directory Services IDs (DSID).
Version Listing
The ListVersions function retrieves a list of softwareVersionExternalIdentifiers. This is critical for users who need to download specific older versions of an app rather than just the latest release.
| Parameter | Type | Description |
|---|---|---|
ExternalVersionIdentifiers | []string | A list of all historical version IDs available for the app. |
LatestExternalVersionID | string | The identifier for the current/most recent version. |
Sources: pkg/appstore/appstore_list_versions.go:12-15, pkg/appstore/appstore_list_versions.go:50-70
Metadata Querying
Once a version identifier is obtained, GetVersionMetadata can be used to fetch the human-readable version string and the official release timestamp.
Data Models
The core data structure used across all querying logic is the App struct (and its collection wrapper Apps). This model captures the essential identity and commerce attributes of an iOS application.
| Field | Type | Description |
|---|---|---|
ID | int64 | The unique Apple 'Adam ID'. |
BundleID | string | The reverse-DNS string (e.g., com.example.app). |
Name | string | The display name of the application. |
Version | string | The human-readable version string. |
Price | float64 | The listed price in the storefront's currency. |
Sources: pkg/appstore/app_test.go:14-29, pkg/appstore/appstore_search.go:47-50
Implementation Details
URL Construction Logic
The system maintains a clean separation between request logic and URL generation. For search and lookup, it utilizes url.Values to ensure proper encoding of entities and terms.
// pkg/appstore/appstore_search.go:58-67
func (t *appstore) searchURL(term, countryCode string, limit int64) string {
params := url.Values{}
params.Add("entity", "software,iPadSoftware")
params.Add("limit", strconv.Itoa(int(limit)))
params.Add("media", "software")
params.Add("term", term)
params.Add("country", countryCode)
return fmt.Sprintf("https://%s%s?%s", iTunesAPIDomain, iTunesAPIPathSearch, params.Encode())
}
Sources: pkg/appstore/appstore_search.go:58-67, pkg/appstore/appstore_lookup.go:53-61
Request Context
Querying private endpoints (versioning/metadata) requires additional headers and payload fields compared to public searches.
- Headers:
iCloud-DSIDandX-Dsidfor identification. - Payload:
salableAdamIdfor the target app andguidfor the requesting machine. - Pod Routing: If the account is associated with a specific "Pod," the request URL is prefixed (e.g.,
https://p42-buy.itunes...).
Sources: pkg/appstore/appstore_list_versions.go:76-104, pkg/appstore/appstore_get_version_metadata.go:62-87
Summary
The App Store Search & Querying Logic provides a robust interface for application discovery and version tracking. By combining public iTunes APIs for general discovery with private App Store APIs for granular version control, the module enables the ipatool to precisely identify and prepare applications for download or license purchase.