uci.luadoc 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. ---[[
  2. LuCI UCI model library.
  3. The typical workflow for UCI is: Get a cursor instance from the
  4. cursor factory, modify data (via Cursor.add, Cursor.delete, etc.),
  5. save the changes to the staging area via Cursor.save and finally
  6. Cursor.commit the data to the actual config files.
  7. LuCI then needs to Cursor.apply the changes so daemons etc. are
  8. reloaded.
  9. @cstyle instance
  10. ]]
  11. module "luci.model.uci"
  12. ---[[
  13. Create a new UCI-Cursor.
  14. @class function
  15. @name cursor
  16. @return UCI-Cursor
  17. ]]
  18. ---[[
  19. Create a new Cursor initialized to the state directory.
  20. @class function
  21. @name cursor_state
  22. @return UCI cursor
  23. ]]
  24. ---[[
  25. Applies UCI configuration changes.
  26. If the rollback parameter is set to true, the apply function will invoke the
  27. rollback mechanism which causes the configuration to be automatically reverted
  28. if no confirm() call occurs within a certain timeout.
  29. The current default timeout is 30s and can be increased using the
  30. "luci.apply.timeout" uci configuration key.
  31. @class function
  32. @name Cursor.apply
  33. @param rollback Enable rollback mechanism
  34. @return Boolean whether operation succeeded
  35. ]]
  36. ---[[
  37. Confirms UCI apply process.
  38. If a previous UCI apply with rollback has been invoked using apply(true),
  39. this function confirms the process and cancels the pending rollback timer.
  40. If no apply with rollback session is active, the function has no effect and
  41. returns with a "No data" error.
  42. @class function
  43. @name Cursor.confirm
  44. @return Boolean whether operation succeeded
  45. ]]
  46. ---[[
  47. Cancels UCI apply process.
  48. If a previous UCI apply with rollback has been invoked using apply(true),
  49. this function cancels the process and rolls back the configuration to the
  50. pre-apply state.
  51. If no apply with rollback session is active, the function has no effect and
  52. returns with a "No data" error.
  53. @class function
  54. @name Cursor.rollback
  55. @return Boolean whether operation succeeded
  56. ]]
  57. ---[[
  58. Checks whether a pending rollback is scheduled.
  59. If a previous UCI apply with rollback has been invoked using apply(true),
  60. and has not been confirmed or rolled back yet, this function returns true
  61. and the remaining time until rollback in seconds. If no rollback is pending,
  62. the function returns false. On error, the function returns false and an
  63. additional string describing the error.
  64. @class function
  65. @name Cursor.rollback_pending
  66. @return Boolean whether rollback is pending
  67. @return Remaining time in seconds
  68. ]]
  69. ---[[
  70. Delete all sections of a given type that match certain criteria.
  71. @class function
  72. @name Cursor.delete_all
  73. @param config UCI config
  74. @param type UCI section type
  75. @param comparator Function that will be called for each section and returns
  76. a boolean whether to delete the current section (optional)
  77. ]]
  78. ---[[
  79. Create a new section and initialize it with data.
  80. @class function
  81. @name Cursor.section
  82. @param config UCI config
  83. @param type UCI section type
  84. @param name UCI section name (optional)
  85. @param values Table of key - value pairs to initialize the section with
  86. @return Name of created section
  87. ]]
  88. ---[[
  89. Updated the data of a section using data from a table.
  90. @class function
  91. @name Cursor.tset
  92. @param config UCI config
  93. @param section UCI section name (optional)
  94. @param values Table of key - value pairs to update the section with
  95. ]]
  96. ---[[
  97. Get a boolean option and return it's value as true or false.
  98. @class function
  99. @name Cursor.get_bool
  100. @param config UCI config
  101. @param section UCI section name
  102. @param option UCI option
  103. @return Boolean
  104. ]]
  105. ---[[
  106. Get an option or list and return values as table.
  107. @class function
  108. @name Cursor.get_list
  109. @param config UCI config
  110. @param section UCI section name
  111. @param option UCI option
  112. @return table. If the option was not found, you will simply get an empty
  113. table.
  114. ]]
  115. ---[[
  116. Get the given option from the first section with the given type.
  117. @class function
  118. @name Cursor.get_first
  119. @param config UCI config
  120. @param type UCI section type
  121. @param option UCI option (optional)
  122. @param default Default value (optional)
  123. @return UCI value
  124. ]]
  125. ---[[
  126. Set given values as list. Setting a list option to an empty list
  127. has the same effect as deleting the option.
  128. @class function
  129. @name Cursor.set_list
  130. @param config UCI config
  131. @param section UCI section name
  132. @param option UCI option
  133. @param value Value or table. Non-table values will be set as single
  134. item UCI list.
  135. @return Boolean whether operation succeeded
  136. ]]
  137. ---[[
  138. Create a sub-state of this cursor.
  139. The sub-state is tied to the parent cursor, means it the parent unloads or
  140. loads configs, the sub state will do so as well.
  141. @class function
  142. @name Cursor.substate
  143. @return UCI state cursor tied to the parent cursor
  144. ]]
  145. ---[[
  146. Add an anonymous section.
  147. @class function
  148. @name Cursor.add
  149. @param config UCI config
  150. @param type UCI section type
  151. @return Name of created section
  152. ]]
  153. ---[[
  154. Get a table of saved but uncommitted changes.
  155. @class function
  156. @name Cursor.changes
  157. @param config UCI config
  158. @return Table of changes
  159. @see Cursor.save
  160. ]]
  161. ---[[
  162. Commit saved changes.
  163. @class function
  164. @name Cursor.commit
  165. @param config UCI config
  166. @return Boolean whether operation succeeded
  167. @see Cursor.revert
  168. @see Cursor.save
  169. ]]
  170. ---[[
  171. Deletes a section or an option.
  172. @class function
  173. @name Cursor.delete
  174. @param config UCI config
  175. @param section UCI section name
  176. @param option UCI option (optional)
  177. @return Boolean whether operation succeeded
  178. ]]
  179. ---[[
  180. Call a function for every section of a certain type.
  181. @class function
  182. @name Cursor.foreach
  183. @param config UCI config
  184. @param type UCI section type
  185. @param callback Function to be called
  186. @return Boolean whether operation succeeded
  187. ]]
  188. ---[[
  189. Get a section type or an option
  190. @class function
  191. @name Cursor.get
  192. @param config UCI config
  193. @param section UCI section name
  194. @param option UCI option (optional)
  195. @return UCI value
  196. ]]
  197. ---[[
  198. Get all sections of a config or all values of a section.
  199. @class function
  200. @name Cursor.get_all
  201. @param config UCI config
  202. @param section UCI section name (optional)
  203. @return Table of UCI sections or table of UCI values
  204. ]]
  205. ---[[
  206. Manually load a config.
  207. @class function
  208. @name Cursor.load
  209. @param config UCI config
  210. @return Boolean whether operation succeeded
  211. @see Cursor.save
  212. @see Cursor.unload
  213. ]]
  214. ---[[
  215. Revert saved but uncommitted changes.
  216. @class function
  217. @name Cursor.revert
  218. @param config UCI config
  219. @return Boolean whether operation succeeded
  220. @see Cursor.commit
  221. @see Cursor.save
  222. ]]
  223. ---[[
  224. Saves changes made to a config to make them committable.
  225. @class function
  226. @name Cursor.save
  227. @param config UCI config
  228. @return Boolean whether operation succeeded
  229. @see Cursor.load
  230. @see Cursor.unload
  231. ]]
  232. ---[[
  233. Set a value or create a named section.
  234. When invoked with three arguments `config`, `sectionname`, `sectiontype`,
  235. then a named section of the given type is created.
  236. When invoked with four arguments `config`, `sectionname`, `optionname` and
  237. `optionvalue` then the value of the specified option is set to the given value.
  238. @class function
  239. @name Cursor.set
  240. @param config UCI config
  241. @param section UCI section name
  242. @param option UCI option or UCI section type
  243. @param value UCI value or nothing if you want to create a section
  244. @return Boolean whether operation succeeded
  245. ]]
  246. ---[[
  247. Get the configuration directory.
  248. @class function
  249. @name Cursor.get_confdir
  250. @return Configuration directory
  251. ]]
  252. ---[[
  253. Get the directory for uncomitted changes.
  254. @class function
  255. @name Cursor.get_savedir
  256. @return Save directory
  257. ]]
  258. ---[[
  259. Get the effective session ID.
  260. @class function
  261. @name Cursor.get_session_id
  262. @return String containing the session ID
  263. ]]
  264. ---[[
  265. Set the configuration directory.
  266. @class function
  267. @name Cursor.set_confdir
  268. @param directory UCI configuration directory
  269. @return Boolean whether operation succeeded
  270. ]]
  271. ---[[
  272. Set the directory for uncommitted changes.
  273. @class function
  274. @name Cursor.set_savedir
  275. @param directory UCI changes directory
  276. @return Boolean whether operation succeeded
  277. ]]
  278. ---[[
  279. Set the effective session ID.
  280. @class function
  281. @name Cursor.set_session_id
  282. @param id String containing the session ID to set
  283. @return Boolean whether operation succeeded
  284. ]]
  285. ---[[
  286. Discard changes made to a config.
  287. @class function
  288. @name Cursor.unload
  289. @param config UCI config
  290. @return Boolean whether operation succeeded
  291. @see Cursor.load
  292. @see Cursor.save
  293. ]]