Subversion Repositories public

Rev

Rev 53 | Rev 57 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 53 Rev 55
Line 60... Line 60...
60
  else {
60
  else {
61
    if (m_fNoLoop)
61
    if (m_fNoLoop)
62
      m.append(",IN_NO_LOOP");
62
      m.append(",IN_NO_LOOP");
63
  }
63
  }
64
 
64
 
65
  ss << m_path << " " << m << " " << m_cmd;
65
  ss << GetSafePath(m_path) << " " << m << " " << m_cmd;
66
  return ss.str();
66
  return ss.str();
67
}
67
}
68
68
69
bool InCronTabEntry::Parse(const std::string& rStr, InCronTabEntry& rEntry)
69
bool InCronTabEntry::Parse(const std::string& rStr, InCronTabEntry& rEntry)
70
{
70
{
71
  char s1[1000], s2[1000], s3[1000];
-
 
72
  unsigned long u;
71
  unsigned long u;
-
 
72
  std::string s1, s2, s3;
73
 
73
 
74
  if (sscanf(rStr.c_str(), "%s %s %[^\n]", s1, s2, s3) != 3)
74
  StringTokenizer tok(rStr, ' ', '\\');
-
 
75
  if (!tok.HasMoreTokens())
-
 
76
    return false;
-
 
77
   
-
 
78
  s1 = tok.GetNextToken(true);
-
 
79
  if (!tok.HasMoreTokens())
-
 
80
    return false;
-
 
81
   
-
 
82
  s2 = tok.GetNextToken(true);
-
 
83
  if (!tok.HasMoreTokens())
75
    return false;
84
    return false;
76
 
85
 
-
 
86
  tok.SetNoPrefix();
-
 
87
  s3 = tok.GetRemainder();
-
 
88
  SIZE len = s3.length();
-
 
89
  if (len > 0 && s3[len-1] == '\n')
-
 
90
    s3.resize(len-1);
-
 
91
 
77
  rEntry.m_path = s1;
92
  rEntry.m_path = s1;
78
  rEntry.m_cmd = s3;
93
  rEntry.m_cmd = s3;
79
  rEntry.m_uMask = 0;
94
  rEntry.m_uMask = 0;
80
  rEntry.m_fNoLoop = false;
95
  rEntry.m_fNoLoop = false;
81
 
96
 
82
  if (sscanf(s2, "%lu", &u) == 1) {
97
  if (sscanf(s2.c_str(), "%lu", &u) == 1) {
83
    rEntry.m_uMask = (uint32_t) u;
98
    rEntry.m_uMask = (uint32_t) u;
84
  }
99
  }
85
  else {
100
  else {
86
    StringTokenizer tok(s2);
101
    StringTokenizer tok(s2);
87
    while (tok.HasMoreTokens()) {
102
    while (tok.HasMoreTokens()) {
Line 94... Line 109...
94
  }
109
  }
95
 
110
 
96
  return true;
111
  return true;
97
}
112
}
98
113
-
 
114
std::string InCronTabEntry::GetSafePath(const std::string& rPath)
-
 
115
{
-
 
116
  std::ostringstream stream;
-
 
117
 
-
 
118
  SIZE len = rPath.length();
-
 
119
  for (SIZE i = 0; i < len; i++) {
-
 
120
    if (rPath[i] == ' ') {
-
 
121
      stream << "\\ ";
-
 
122
    }
-
 
123
    else if (rPath[i] == '\\') {
-
 
124
      stream << "\\\\";
-
 
125
    }
-
 
126
    else {
-
 
127
      stream << rPath[i];
-
 
128
    }
-
 
129
  }
-
 
130
 
-
 
131
  return stream.str();
-
 
132
}
-
 
133
99
bool InCronTab::Load(const std::string& rPath)
134
bool InCronTab::Load(const std::string& rPath)
100
{
135
{
101
  m_tab.clear();
136
  m_tab.clear();
102
 
137
 
103
  FILE* f = fopen(rPath.c_str(), "r");
138
  FILE* f = fopen(rPath.c_str(), "r");
Line 179... Line 214...
179
  std::string s(INCRON_TABLE_BASE);
214
  std::string s(INCRON_TABLE_BASE);
180
  s.append(rUser);
215
  s.append(rUser);
181
  return s;
216
  return s;
182
}
217
}
183
218
-
 
219
-
 
220