annotate .svn/pristine/db/db9d5de4e29d812e502d8ee4c3a6a7311df17b3f.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

Fix failure to interpret Javascript when autocompleting members for project
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 11 Sep 2014 10:24:38 +0100
parents cbb26bc654de
children
rev   line source
Chris@909 1 # $Id: dataset.rb 78 2006-04-26 02:57:34Z blackhedd $
Chris@909 2 #
Chris@909 3 #
Chris@909 4 #----------------------------------------------------------------------------
Chris@909 5 #
Chris@909 6 # Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
Chris@909 7 #
Chris@909 8 # Gmail: garbagecat10
Chris@909 9 #
Chris@909 10 # This program is free software; you can redistribute it and/or modify
Chris@909 11 # it under the terms of the GNU General Public License as published by
Chris@909 12 # the Free Software Foundation; either version 2 of the License, or
Chris@909 13 # (at your option) any later version.
Chris@909 14 #
Chris@909 15 # This program is distributed in the hope that it will be useful,
Chris@909 16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@909 17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@909 18 # GNU General Public License for more details.
Chris@909 19 #
Chris@909 20 # You should have received a copy of the GNU General Public License
Chris@909 21 # along with this program; if not, write to the Free Software
Chris@909 22 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Chris@909 23 #
Chris@909 24 #---------------------------------------------------------------------------
Chris@909 25 #
Chris@909 26 #
Chris@909 27
Chris@909 28
Chris@909 29
Chris@909 30
Chris@909 31 module Net
Chris@909 32 class LDAP
Chris@909 33
Chris@909 34 class Dataset < Hash
Chris@909 35
Chris@909 36 attr_reader :comments
Chris@909 37
Chris@909 38
Chris@909 39 def Dataset::read_ldif io
Chris@909 40 ds = Dataset.new
Chris@909 41
Chris@909 42 line = io.gets && chomp
Chris@909 43 dn = nil
Chris@909 44
Chris@909 45 while line
Chris@909 46 io.gets and chomp
Chris@909 47 if $_ =~ /^[\s]+/
Chris@909 48 line << " " << $'
Chris@909 49 else
Chris@909 50 nextline = $_
Chris@909 51
Chris@909 52 if line =~ /^\#/
Chris@909 53 ds.comments << line
Chris@909 54 elsif line =~ /^dn:[\s]*/i
Chris@909 55 dn = $'
Chris@909 56 ds[dn] = Hash.new {|k,v| k[v] = []}
Chris@909 57 elsif line.length == 0
Chris@909 58 dn = nil
Chris@909 59 elsif line =~ /^([^:]+):([\:]?)[\s]*/
Chris@909 60 # $1 is the attribute name
Chris@909 61 # $2 is a colon iff the attr-value is base-64 encoded
Chris@909 62 # $' is the attr-value
Chris@909 63 # Avoid the Base64 class because not all Ruby versions have it.
Chris@909 64 attrvalue = ($2 == ":") ? $'.unpack('m').shift : $'
Chris@909 65 ds[dn][$1.downcase.intern] << attrvalue
Chris@909 66 end
Chris@909 67
Chris@909 68 line = nextline
Chris@909 69 end
Chris@909 70 end
Chris@909 71
Chris@909 72 ds
Chris@909 73 end
Chris@909 74
Chris@909 75
Chris@909 76 def initialize
Chris@909 77 @comments = []
Chris@909 78 end
Chris@909 79
Chris@909 80
Chris@909 81 def to_ldif
Chris@909 82 ary = []
Chris@909 83 ary += (@comments || [])
Chris@909 84
Chris@909 85 keys.sort.each {|dn|
Chris@909 86 ary << "dn: #{dn}"
Chris@909 87
Chris@909 88 self[dn].keys.map {|sym| sym.to_s}.sort.each {|attr|
Chris@909 89 self[dn][attr.intern].each {|val|
Chris@909 90 ary << "#{attr}: #{val}"
Chris@909 91 }
Chris@909 92 }
Chris@909 93
Chris@909 94 ary << ""
Chris@909 95 }
Chris@909 96
Chris@909 97 block_given? and ary.each {|line| yield line}
Chris@909 98
Chris@909 99 ary
Chris@909 100 end
Chris@909 101
Chris@909 102
Chris@909 103 end # Dataset
Chris@909 104
Chris@909 105 end # LDAP
Chris@909 106 end # Net
Chris@909 107
Chris@909 108