12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/vobject/vcard/v3_0/paramcheck.rb', line 12
def paramcheck(strict, prop, params, ctx)
errors = []
if params && params[:TYPE]
parse_err(strict, errors, "multiple values for :TYPE parameter of #{prop}", ctx) if params[:TYPE].is_a?(Array) && params[:TYPE].length > 1 && prop != :EMAIL && prop != :ADR && prop != :TEL && prop != :LABEL && prop != :IMPP
end
case prop
when :NAME, :PROFILE, :GEO, :PRODID, :URL, :VERSION, :CLASS
parse_err(strict, errors, "illegal parameters #{params} given for #{prop}", ctx) unless params.empty?
when :CALURI, :CAPURI, :CALADRURI, :FBURL
params.each do |key, val|
parse_err(strict, errors, "illegal parameter #{key} given for #{prop}", ctx) unless key == :TYPE
if params[:TYPE].is_a?(Array)
val.each do |v|
parse_err(strict, errors, "illegal parameter value #{v} given for parameter #{key} of #{prop}", ctx) unless v == "PREF"
end
else
parse_err(strict, errors, "illegal parameter value #{val} given for parameter #{key} of #{prop}", ctx) unless val == "PREF"
end
end
when :SOURCE
params.each do |key, val|
parse_err(strict, errors, "illegal parameter #{key} given for #{prop}", ctx) unless key == :VALUE || key == :CONTEXT || key =~ /^x/i
parse_err(strict, errors, "illegal value #{val} given for parameter #{key} of #{prop}", ctx) if key == :VALUE && val != "uri"
parse_err(strict, errors, "illegal value #{val} given for parameter #{key} of #{prop}", ctx) if key == :CONTEXT && val != "word"
end
when :FN, :N, :NICKNAME, :MAILER, :TITLE, :ROLE, :ORG, :CATEGORIES, :NOTE, :SORT_STRING
params.each do |key, val|
parse_err(strict, errors, "illegal parameter #{key} given for #{prop}", ctx) unless key == :VALUE || key == :LANGUAGE || key =~ /^x/i
parse_err(strict, errors, "illegal value #{val} given for parameter #{key} of #{prop}", ctx) if key == :VALUE && val != "ptext"
end
when :TEL, :IMPP, :UID
params.each_key do |key|
parse_err(strict, errors, "illegal parameter #{key} given for #{prop}", ctx) unless key == :TYPE
end
when :EMAIL
params.each_key do |key|
parse_err(strict, errors, "illegal parameter #{key} given for #{prop}", ctx) unless key == :TYPE
end
when :ADR, :LABEL
params.each do |key, val|
parse_err(strict, errors, "illegal parameter #{key} given for #{prop}", ctx) unless [:VALUE, :LANGUAGE, :TYPE].include? key || key =~ /^x/i
parse_err(strict, errors, "illegal value #{val} given for parameter #{key} of #{prop}", ctx) if key == :VALUE && val != "ptext"
end
when :KEY
params.each do |key, val|
parse_err(strict, errors, "illegal parameter #{key} given for #{prop}", ctx) unless [:TYPE, :ENCODING, :VALUE].include? key
parse_err(strict, errors, "illegal value #{val} given for parameter #{key} of #{prop}", ctx) if key == :VALUE && val != "binary"
end
when :PHOTO, :LOGO, :SOUND
params.each_key do |key|
parse_err(strict, errors, "illegal parameter #{key} given for #{prop}", ctx) unless [:VALUE, :TYPE, :ENCODING].include? key
end
parse_err(strict, errors, "illegal value #{params[:VALUE]} of :VALUE given for #{prop}", ctx) if params[:VALUE] && params[:VALUE] != "binary" && params[:VALUE] != "uri"
parse_err(strict, errors, "illegal value #{params[:ENCODING]} of :ENCODING given for #{prop}", ctx) if params[:ENCODING] && (params[:ENCODING] != "b" || params[:VALUE] == "uri")
parse_err(strict, errors, "mandatory parameter of :ENCODING missing for #{prop}", ctx) if !params.has_key?(:ENCODING) && (!params.key?(:VALUE) || params[:VALUE] == "binary")
when :BDAY, :REV
params.each_key do |key|
parse_err(strict, errors, "illegal parameter #{key} given for #{prop}", ctx) unless key == :VALUE
end
parse_err(strict, errors, "illegal value #{params[:VALUE]} of :VALUE given for #{prop}", ctx) if params[:VALUE] && params[:VALUE] != "date" && params[:VALUE] != "date-time"
when :AGENT
params.each_key do |key|
parse_err(strict, errors, "illegal parameter #{key} given for #{prop}", ctx) unless key == :VALUE
end
parse_err(strict, errors, "illegal value #{params[:VALUE]} of :VALUE given for #{prop}", ctx) if params[:VALUE] && params[:VALUE] != "uri"
when :TZ
params.each_key do |key|
parse_err(strict, errors, "illegal parameter #{key} given for #{prop}", ctx) unless key == :VALUE
end
parse_err(strict, errors, "illegal value #{params[:VALUE]} of :VALUE given for #{prop}", ctx) if params[:VALUE] && params[:VALUE] != "text"
else
params.each_key do |key|
parse_err(strict, errors, "illegal parameter #{key} given for #{prop}", ctx) unless key == :VALUE || key == :LANGUAGE || key =~ /^x/i
parse_err(strict, errors, "illegal value #{val} given for parameter #{key} of #{prop}") if key == :VALUE && val != "ptext"
end
end
errors
end
|