Changeset de30ea9a40e3c6c47f37331e1c311513058f924d
- Timestamp:
- 01/26/12 16:13:49
(1 year ago)
- Author:
- Philip Maddox <pmaddox@circonus.com>
- git-committer:
- Philip Maddox <pmaddox@circonus.com> 1327594429 -0500
- git-parent:
[4a0da0e513a734ae484e56cee0fdc99f321e3766]
- git-author:
- Philip Maddox <pmaddox@circonus.com> 1327594429 -0500
- Message:
Moved split from smtp.lua into extras.lua, a new file for extra non-task-specific functions. Added extras.lua to the build.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r4adb4fb |
rde30ea9 |
|
| 30 | 30 | LUA=noit/timeval.lua \ |
|---|
| 31 | 31 | noit/HttpClient.lua \ |
|---|
| | 32 | noit/extras.lua \ |
|---|
| 32 | 33 | noit/module/varnish.lua \ |
|---|
| 33 | 34 | noit/module/smtp.lua \ |
|---|
| r4a0da0e |
rde30ea9 |
|
| 146 | 146 | |
|---|
| 147 | 147 | if phase == 'ehlo' and message ~= nil then |
|---|
| 148 | | local fields = string.split(message, "\r\n") |
|---|
| | 148 | local fields = noit.extras.split(message, "\r\n") |
|---|
| 149 | 149 | if fields ~= nil then |
|---|
| 150 | 150 | local response = "" |
|---|
| … | … | |
| 159 | 159 | if value ~= nil and value ~= "" then |
|---|
| 160 | 160 | value = value:gsub("^%s*(.-)%s*$", "%1") |
|---|
| 161 | | local subfields = string.split(value, "%s+", 1) |
|---|
| | 161 | local subfields = noit.extras.split(value, "%s+", 1) |
|---|
| 162 | 162 | if subfields ~= nil and subfields[1] ~= nil then |
|---|
| 163 | 163 | local header = subfields[1] |
|---|
| … | … | |
| 243 | 243 | end |
|---|
| 244 | 244 | |
|---|
| 245 | | -- from http://www.wellho.net/resources/ex.php4?item=u108/split |
|---|
| 246 | | -- modified to split up to 'max' times |
|---|
| 247 | | function string:split(delimiter, max) |
|---|
| 248 | | local result = { } |
|---|
| 249 | | local from = 1 |
|---|
| 250 | | local delim_from, delim_to = string.find( self, delimiter, from ) |
|---|
| 251 | | local nb = 0 |
|---|
| 252 | | if max == nil then |
|---|
| 253 | | max = 0 |
|---|
| 254 | | end |
|---|
| 255 | | while delim_from do |
|---|
| 256 | | local insert_string = string.sub( self, from , delim_from-1 ) |
|---|
| 257 | | nb = nb + 1 |
|---|
| 258 | | table.insert( result, insert_string ) |
|---|
| 259 | | from = delim_to + 1 |
|---|
| 260 | | delim_from, delim_to = string.find( self, delimiter, from ) |
|---|
| 261 | | if nb == max then |
|---|
| 262 | | break |
|---|
| 263 | | end |
|---|
| 264 | | end |
|---|
| 265 | | local last_res = string.sub (self, from) |
|---|
| 266 | | if last_res ~= nil and last_res ~= "" then |
|---|
| 267 | | table.insert( result, last_res ) |
|---|
| 268 | | end |
|---|
| 269 | | return result |
|---|
| 270 | | end |
|---|
| 271 | | |
|---|
| r9d3260a |
rde30ea9 |
|
| 892 | 892 | |
|---|
| 893 | 893 | require(noit.timeval); |
|---|
| | 894 | require(noit.extras); |
|---|
| 894 | 895 | |
|---|
| 895 | 896 | lua_gc(L, LUA_GCRESTART, 0); |
|---|