View Single Post
Old 12-11-2013, 06:11 PM   #724
eureka
but forgot what it's like
eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.eureka ought to be getting tired of karma fortunes by now.
 
Posts: 741
Karma: 2345678
Join Date: Dec 2011
Location: north (by northwest)
Device: Kindle Touch
@ixtab, did you look at Lua scripts in /usr/lib/ccat? In the end, stock Java code works with catalog database through these scripts anyway (and so is Collections Manager). Scripts are more readable than Java bytecode and even if they are slightly changed with firmware updates, changes are easlily tracked with simple diff'ing.

/usr/lib/ccat/worker.lua is executed for answering to HTTP requests to http://127.0.0.1:9101/. It recognizes POST requests to predefined endpoints with JSON-encoded POST data. This JSON request is transfromed by Lua script into SQL query to execute. Useful endpoints inculde http://127.0.0.1:9101/query endpoint for selecting from catalog database and http://127.0.0.1:9101/change endpoint for updating catalog database.

Example of HTTP request:
Code:
curl http://127.0.0.1:9101/query -d '{"type": "QueryRequest", "maxResults": 2}'
Here is a small hack to display system JSON-encoded requests received by worker.lua in log. Backup /usr/lib/ccat/worker.lua. Add this at the top of /usr/lib/ccat/worker.lua (but after all requires):
Code:
local function logged (handler_name, post_data_handler)
  return function (post_data)
    llog.info("ccat_worker", handler_name, post_data, "")
    return post_data_handler(post_data)
  end
end
Then run
Code:
sed -ie 's/^\(_G.\+=\s*\)\([^.]\+\)\(\..\+\)$/\1logged("\2", \2\3)/g' /usr/lib/ccat/worker.lua
Then mntroot ro, restart framework and showlog -f | grep ccat_worker

Format of log entries is 'ccat_worker:<endpoint>:<JSON-encoded data>:'

Here are sample log entries recorded right after invoking of Collections Manager from Home screen:
Spoiler:
Code:
cvm[4642]: I ccat_worker:query:{"filter":{"And":[{"ValueIn":{"choices":["\/mnt\/us\/documents\/CollectionsManager.azw2"],"path":"location"}},{"Not":{"ValueIn":{"choices":[true],"path":"isArchived"}}}]},"type":"QueryRequest","maxResults":1,"sortOrder":[{"order":"ascending","path":"titles[0].collation"},{"order":"ascending","path":"credits[0].name.collation"},{"order":"descending","path":"publicationDate"}],"startIndex":0,"id":21,"resultType":"fast"}:
cvm[4642]: I ccat_worker:change:{"commands":[{"update":{"uuid":"78a758fa-3e2f-4081-b4bd-4c01ede9dd35","displayTags":["DEV"],"lastAccess":1386802717}}],"type":"ChangeRequest","id":5}:
cvm[4642]: I ccat_worker:query:{"filter":{"And":[{"ValueIn":{"choices":[true],"path":"isVisibleInHome"}},{"Not":{"ValueIn":{"choices":[true],"path":"isDownloading"}}},{"Equals":{"value":"Entry:Item:Notice","path":"type"}}]},"type":"QueryRequest","maxResults":40,"sortOrder":[{"order":"descending","path":"lastAccess"},{"order":"ascending","path":"titles[0].collation"}],"startIndex":0,"id":22,"resultType":"fast"}:
cvm[4642]: I ccat_worker:query:{"filter":{"And":[{"ValueIn":{"choices":[true],"path":"isVisibleInHome"}},{"Not":{"ValueIn":{"choices":[true],"path":"isArchived"}}},{"Not":{"ValueIn":{"choices":[true],"path":"isDownloading"}}},{"ValueIn":{"choices":[true],"path":"isLatestItem"}},{"Not":{"ValueIn":{"choices":["Entry:Item:AI","Entry:Item:Dictionary","Entry:Item:Notice"],"path":"type"}}}]},"type":"QueryRequest","maxResults":40,"sortOrder":[{"order":"descending","path":"lastAccess"},{"order":"ascending","path":"titles[0].collation"}],"startIndex":0,"id":23,"resultType":"fast"}:
cvm[4642]: I ccat_worker:query:{"filter":{"And":[{"StartsWith":{"prefix":"","path":"titles[0].display"}},{"And":[{"Not":{"ValueIn":{"choices":[true],"path":"isArchived"}}},{"Not":{"ValueIn":{"choices":[true],"path":"isDownloading"}}},{"Not":{"Equals":{"value":"application\/x-kindle-acx","path":"mimeType"}}},{"Or":[{"Equals":{"value":"Collection","path":"type"}},{"StartsWith":{"prefix":"Entry:Item","path":"type"}}]}]}]},"type":"QueryRequest","maxResults":5,"sortOrder":[{"order":"ascending","path":"titles[0].display"},{"order":"ascending","path":"credits[0].name.collation"},{"order":"descending","path":"publicationDate"}],"startIndex":0,"id":24,"resultType":"full"}:
cvm[4642]: I ccat_worker:query:{"filter":{"And":[{"StartsWith":{"prefix":"","path":"titles[0].display"}},{"And":[{"Not":{"ValueIn":{"choices":[true],"path":"isArchived"}}},{"Not":{"ValueIn":{"choices":[true],"path":"isDownloading"}}},{"Not":{"Equals":{"value":"application\/x-kindle-acx","path":"mimeType"}}},{"Or":[{"Equals":{"value":"Collection","path":"type"}},{"StartsWith":{"prefix":"Entry:Item","path":"type"}}]}]}]},"type":"QueryRequest","maxResults":5,"sortOrder":[{"order":"ascending","path":"titles[0].display"},{"order":"ascending","path":"credits[0].name.collation"},{"order":"descending","path":"publicationDate"}],"startIndex":0,"id":25,"resultType":"full"}:
cvm[4642]: I ccat_worker:query:{"filter":{"And":[{"StartsWith":{"prefix":"","path":"titles[0].display"}},{"And":[{"Not":{"ValueIn":{"choices":[true],"path":"isArchived"}}},{"Not":{"ValueIn":{"choices":[true],"path":"isDownloading"}}},{"Not":{"Equals":{"value":"application\/x-kindle-acx","path":"mimeType"}}},{"Or":[{"Equals":{"value":"Collection","path":"type"}},{"StartsWith":{"prefix":"Entry:Item","path":"type"}}]}]}]},"type":"QueryRequest","maxResults":5,"sortOrder":[{"order":"ascending","path":"titles[0].display"},{"order":"ascending","path":"credits[0].name.collation"},{"order":"descending","path":"publicationDate"}],"startIndex":0,"id":26,"resultType":"full"}:
cvm[4642]: I ccat_worker:query:{"filter":{"And":[{"StartsWith":{"prefix":"","path":"titles[0].display"}},{"And":[{"Not":{"ValueIn":{"choices":[true],"path":"isArchived"}}},{"Not":{"ValueIn":{"choices":[true],"path":"isDownloading"}}},{"Not":{"Equals":{"value":"application\/x-kindle-acx","path":"mimeType"}}},{"Or":[{"Equals":{"value":"Collection","path":"type"}},{"StartsWith":{"prefix":"Entry:Item","path":"type"}}]}]}]},"type":"QueryRequest","maxResults":5,"sortOrder":[{"order":"ascending","path":"titles[0].display"},{"order":"ascending","path":"credits[0].name.collation"},{"order":"descending","path":"publicationDate"}],"startIndex":0,"id":27,"resultType":"full"}:

This is not my discovery, there was Kindle_Touch_Hacking#Collections and some old threads mentioned this way too.
eureka is offline   Reply With Quote