ah ok merci
je demanderai si c est possible de le mettre sur un ftp pour un test
ben j aurai bien aime qu ils me payent aussi , mais on fait avec
tant que j apprend , ca me va ^^
Version imprimable
ah ok merci
je demanderai si c est possible de le mettre sur un ftp pour un test
ben j aurai bien aime qu ils me payent aussi , mais on fait avec
tant que j apprend , ca me va ^^
ben disons que ce stage est necessaire pour mon passage en bts 2 eme annee , donc faut se plier a leurs conditions
bon, ben merci a tous de votre aide. je n aurai jamais reussi sans vous , c est grace a vous que j ai pu finir mon projet dans les temps , malgre mon ignorance totale
sauf que la , j ai un petit probleme(oui je sais , je suis chiant ,desole)
XD
ben en fait , c est que la partie 3de mon prog ne marche pas , alors que le code et la compilation sont correct. je suppose que c est a cause des nombreux warning se rapportant a mes fonctions que j ai, et qui pollue mon programme
si vous pouvez m aider a les resoudre , ca serait sympa de votre part^^
le code de mes fonctions:
Code:
1
2
3
4
5
6
7
8
9
10
11
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279 //recupere l'heure du systeme char * recupheure() { /* Lecture de la date et de l'heure */ time_t timestamp=time (NULL); struct tm t = *localtime(×tamp); char * sheure=(char *)malloc(11*sizeof(char)); if(sheure == NULL) { printf("memoire insuffisante."); exit(1); } /* Affiche la date et l'heure courante (format français) */ setlocale(LC_ALL, ""); strftime(sheure,sizeof sheure, "%X",&t); sheure = couperFin(sheure,3); return(sheure); } //recupere la date du systeme char * recupdate() { time_t timestamp=time (NULL); struct tm t = *localtime(×tamp); char * sdate=(char *)malloc(11*sizeof(char)); if(sdate == NULL) { printf("memoire insuffisante."); exit(1); } /* Affiche la date et l'heure courante (format français) */ setlocale(LC_ALL, ""); strftime(sdate,sizeof sdate,"%x ", &t); return(sdate); } int * timer(char sheure,char sdate) { FILE * fp = NULL; short int i=-1; unsigned int j=0; char * chaine = (char *)malloc(256*sizeof(char)); int bool1=0; int bool2=0; int lignes[256]; int count; if(chaine == NULL) { printf("Memoire insuffisante, arret du programme."); exit(1); } if((fp = fopen("C:\\Users\\Habib\\Documents\\Visual Studio 2008\\Projects\\fenetre2\\Debug\\data.xml","r+"))==NULL) { printf("ERREUR LORS DE L'OUVERTURE DU FICHIER\n"); exit(1); } /* lecture du fichier xml */ while(fgets(chaine, 255, fp)) { if(!strcmp(chaine, "</automatisation>")) break; //si i=4, chaine = heurexml, si i=5, chaine = datexml chaine = formatAff(chaine,i,j); //compare heures if(i==4) { if(compareheures(sheure,chaine)) { bool1=1; } } if(i==5) { if(comparedates(chaine,sdate)) { bool2=1; } } if(i==6) { i=1; j++; } else i++; if(bool1 && bool2) { lignes[count] = j; count++; } } fclose(fp); return(lignes); } void modifXML(int * lignes) { int i=0; int count=0; char * chaine = (char*) malloc(256*sizeof(char)); FILE * fp; if(chaine == NULL) { printf("memoire insuffisante."); exit(1); } if((fp=fopen("C:\\Users\\Habib\\Documents\\Visual Studio 2008\\Projects\\fenetre2\\Debug\\data.xml","r+"))) { exit(1); } while(i<500) { while(fgets(chaine,255,fp)!=NULL) { if(count==lignes[i] ) { fseek(fp, count, 0 ); //modification fputs("<date>nouvelle date</date>",fp); rewind(fp); count=0; break; } if(count==lignes[i] ) { fseek(fp, count, 0 ); fputs("<date>nouvelle date</date>",fp); rewind(fp); count=0; break; } count++; } i++; } fclose(fp); } //heure1>heure2 ==> 1 int compareheures(char * heure1_p, char * heure2_p) { char * heure1 = (char *)malloc(3*sizeof(char)); char * min1 = (char *)malloc(3*sizeof(char)); char * heure2 = (char *)malloc(3*sizeof(char)); char * min2 = (char *)malloc(3*sizeof(char)); int retour=0; /* verification de l'allocation */ if(heure1==NULL) { printf("memoire insuffisante."); exit(1); } if(min1==NULL) { printf("memoire insuffisante."); exit(1); } if(heure2==NULL) { printf("memoire insuffisante."); exit(1); } if(min2==NULL) { printf("memoire insuffisante."); exit(1); } heure1=couperFin(heure1_p,3); min1 = couperDebut(heure1_p,3); heure2=couperFin(heure2_p,3); min2 = couperDebut(heure2_p,3); if(heure1>heure2) { retour =1; } else if(heure1==heure2 && min1>min2) { retour = 1; } return(retour); } int comparedates(char * date1,char * date2) { char * jour1 = (char *)malloc(3*sizeof(char)); char * mois1 = (char *)malloc(3*sizeof(char)); char * annee1 = (char *)malloc(3*sizeof(char)); char * jour2 = (char *)malloc(3*sizeof(char)); char * mois2 = (char *)malloc(3*sizeof(char)); char * annee2 = (char *)malloc(3*sizeof(char)); int retour=0; /* verification de l'allocation */ if(jour1==NULL) { printf("memoire insuffisante."); exit(1); } if(mois1==NULL) { printf("memoire insuffisante."); exit(1); } if(annee1==NULL) { printf("memoire insuffisante."); exit(1); } if(jour2==NULL) { printf("memoire insuffisante."); exit(1); } if(mois2==NULL) { printf("memoire insuffisante."); exit(1); } if(annee2==NULL) { printf("memoire insuffisante."); exit(1); } jour1=couperFin(date1,8); annee1 = couperDebut(date1,6); mois1 = couperDebut(date1,3); mois1 = couperFin(mois1,5); jour2=couperFin(date2,8); annee2 = couperDebut(date2,6); mois2 = couperDebut(date2,3); mois2 = couperFin(mois2,5); if(annee1>annee2) { retour =1; } else if(annee1==annee2 && mois1>mois2) { retour = 1; } else if(mois1==mois2 && jour1>jour2) { retour = 1; } return(retour); }
et le rapport de mes warning
Code:
1
2
3
4
5
6
7
8
9
10
11
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 : Projet : sendIP, Configuration : Debug Win32 ------ 1>Compilation en cours... 1>sendIP.c 1>c:\users\habib\documents\visual studio 2008\projects\cpp\sendip.c(125) : warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 1> c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(366) : voir la déclaration de 'sprintf' 1>c:\users\habib\documents\visual studio 2008\projects\cpp\sendip.c(168) : warning C4047: 'fonction' : 'char' diffère de 'char *' dans les niveaux d'indirection 1>c:\users\habib\documents\visual studio 2008\projects\cpp\sendip.c(168) : warning C4024: 'timer' : types différents pour le paramètre formel et réel 1 1>c:\users\habib\documents\visual studio 2008\projects\cpp\sendip.c(168) : warning C4047: 'fonction' : 'char' diffère de 'char *' dans les niveaux d'indirection 1>c:\users\habib\documents\visual studio 2008\projects\cpp\sendip.c(168) : warning C4024: 'timer' : types différents pour le paramètre formel et réel 2 1>c:\users\habib\documents\visual studio 2008\projects\cpp\sendip.c(322) : warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 1> c:\program files\microsoft visual studio 9.0\vc\include\string.h(79) : voir la déclaration de 'strcat' 1>c:\users\habib\documents\visual studio 2008\projects\cpp\sendip.c(468) : warning C4996: 'localtime': This function or variable may be unsafe. Consider using localtime_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 1> c:\program files\microsoft visual studio 9.0\vc\include\time.inl(114) : voir la déclaration de 'localtime' 1>c:\users\habib\documents\visual studio 2008\projects\cpp\sendip.c(470) : warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 1> c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(366) : voir la déclaration de 'sprintf' 1>c:\users\habib\documents\visual studio 2008\projects\cpp\sendip.c(593) : warning C4996: 'localtime': This function or variable may be unsafe. Consider using localtime_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 1> c:\program files\microsoft visual studio 9.0\vc\include\time.inl(114) : voir la déclaration de 'localtime' 1>c:\users\habib\documents\visual studio 2008\projects\cpp\sendip.c(616) : warning C4996: 'localtime': This function or variable may be unsafe. Consider using localtime_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 1> c:\program files\microsoft visual studio 9.0\vc\include\time.inl(114) : voir la déclaration de 'localtime' 1>c:\users\habib\documents\visual studio 2008\projects\cpp\sendip.c(649) : warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 1> c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(237) : voir la déclaration de 'fopen' 1>c:\users\habib\documents\visual studio 2008\projects\cpp\sendip.c(667) : warning C4047: 'fonction' : 'char *' diffère de 'char' dans les niveaux d'indirection 1>c:\users\habib\documents\visual studio 2008\projects\cpp\sendip.c(667) : warning C4024: 'compareheures' : types différents pour le paramètre formel et réel 1 1>c:\users\habib\documents\visual studio 2008\projects\cpp\sendip.c(675) : warning C4047: 'fonction' : 'char *' diffère de 'char' dans les niveaux d'indirection 1>c:\users\habib\documents\visual studio 2008\projects\cpp\sendip.c(675) : warning C4024: 'comparedates' : types différents pour le paramètre formel et réel 2 1>c:\users\habib\documents\visual studio 2008\projects\cpp\sendip.c(698) : warning C4172: retourne l'adresse d'une variable locale ou temporaire 1>c:\users\habib\documents\visual studio 2008\projects\cpp\sendip.c(717) : warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 1> c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(237) : voir la déclaration de 'fopen' 1>c:\users\habib\documents\visual studio 2008\projects\cpp\sendip.c(692) : warning C4700: variable locale 'count' non initialisée utilisée 1>Édition des liens en cours... 1>LINK : warning LNK4076: fichier d'état incrémentiel non valide '.\Debug/sendIP.ilk' ; édition de liens non incrémentielle 1>Incorporation du manifeste en cours... 1>Création d'un fichier d'informations de consultation... 1>Microsoft Browse Information Maintenance Utility Version 9.00.21022 1>Copyright (C) Microsoft Corporation. All rights reserved. 1>Le journal de génération a été enregistré à l'emplacement "file://c:\Users\Habib\Documents\Visual Studio 2008\Projects\cpp\Debug\BuildLog.htm" 1>sendIP - 0 erreur(s), 19 avertissement(s) ========== Génération : 1 a réussi, 0 a échoué, 0 mis à jour, 0 a été ignoré ==========
je pense que les warning qui sont instead ou unsafe comme scanf ou fopen sont normales non ? car j en ai toujours eu , et j ai jamais su comment les resoudre
mes prototypes
c est peut etre avec l histoire des const comme me l a suggere medinoc que j ai tout ces warning?Code:
1
2
3
4
5
6
7
8
9
10
11
12
13 void myThread( void *ch ); void *ThreadTimer (void *data); char * formatAff(char * chaine,int i,int j); char * couperDebut(char * chaine, int n); char * couperFin(char * chaine, int n); int * timer(char sheure,char sdate); void modifXML(int * lignes ); char * recupdate(); char * recupheure(); int compareheures(char * heure1_p, char * heure2_p); int comparedates(char * date1, char * date2);
Ce code est incomplet. On doit deviner ce qui manque ?
donneCode:
1
2
3
4
5
6
7
8
9
10
11
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303 #include <time.h> #include <stdlib.h> #include <locale.h> #include <stdio.h> void myThread( void *ch ); void *ThreadTimer (void *data); char * formatAff(char * chaine,int i,int j); char * couperDebut(char * chaine, int n); char * couperFin(char * chaine, int n); int * timer(char sheure,char sdate); void modifXML(int * lignes ); char * recupdate(); char * recupheure(); int compareheures(char * heure1_p, char * heure2_p); int comparedates(char * date1, char * date2); /* recupere l'heure du systeme */ char *recupheure (void) { /* Lecture de la date et de l'heure */ time_t timestamp = time (NULL); struct tm t = *localtime (×tamp); char *sheure = (char *) malloc (11 * sizeof (char)); if (sheure == NULL) { printf ("memoire insuffisante."); exit (1); } /* Affiche la date et l'heure courante (format français) */ setlocale (LC_ALL, ""); strftime (sheure, sizeof sheure, "%X", &t); sheure = couperFin (sheure, 3); return (sheure); } /* recupere la date du systeme */ char *recupdate () { time_t timestamp = time (NULL); struct tm t = *localtime (×tamp); char *sdate = (char *) malloc (11 * sizeof (char)); if (sdate == NULL) { printf ("memoire insuffisante."); exit (1); } /* Affiche la date et l'heure courante (format français) */ setlocale (LC_ALL, ""); strftime (sdate, sizeof sdate, "%x ", &t); return (sdate); } int *timer (char sheure, char sdate) { FILE *fp = NULL; short int i = -1; unsigned int j = 0; char *chaine = (char *) malloc (256 * sizeof (char)); int bool1 = 0; int bool2 = 0; int lignes[256]; int count; if (chaine == NULL) { printf ("Memoire insuffisante, arret du programme."); exit (1); } if ((fp = fopen ("C:\\Users\\Habib\\Documents\\Visual Studio 2008\\Projects\\fenetre2\\Debug\\data.xml", "r+")) == NULL) { printf ("ERREUR LORS DE L'OUVERTURE DU FICHIER\n"); exit (1); } /* lecture du fichier xml */ while (fgets (chaine, 255, fp)) { if (!strcmp (chaine, "</automatisation>")) break; /* si i=4, chaine = heurexml, si i=5, chaine = datexml */ chaine = formatAff (chaine, i, j); /* compare heures */ if (i == 4) { if (compareheures (sheure, chaine)) { bool1 = 1; } } if (i == 5) { if (comparedates (chaine, sdate)) { bool2 = 1; } } if (i == 6) { i = 1; j++; } else i++; if (bool1 && bool2) { lignes[count] = j; count++; } } fclose (fp); return (lignes); } void modifXML (int *lignes) { int i = 0; int count = 0; char *chaine = (char *) malloc (256 * sizeof (char)); FILE *fp; if (chaine == NULL) { printf ("memoire insuffisante."); exit (1); } if ((fp = fopen ("C:\\Users\\Habib\\Documents\\Visual Studio 2008\\Projects\\fenetre2\\Debug\\data.xml", "r+"))) { exit (1); } while (i < 500) { while (fgets (chaine, 255, fp) != NULL) { if (count == lignes[i]) { fseek (fp, count, 0); /* modification */ fputs ("<date>nouvelle date</date>", fp); rewind (fp); count = 0; break; } if (count == lignes[i]) { fseek (fp, count, 0); fputs ("<date>nouvelle date</date>", fp); rewind (fp); count = 0; break; } count++; } i++; } fclose (fp); } /* heure1>heure2 ==> 1 */ int compareheures (char *heure1_p, char *heure2_p) { char *heure1 = (char *) malloc (3 * sizeof (char)); char *min1 = (char *) malloc (3 * sizeof (char)); char *heure2 = (char *) malloc (3 * sizeof (char)); char *min2 = (char *) malloc (3 * sizeof (char)); int retour = 0; /* verification de l'allocation */ if (heure1 == NULL) { printf ("memoire insuffisante."); exit (1); } if (min1 == NULL) { printf ("memoire insuffisante."); exit (1); } if (heure2 == NULL) { printf ("memoire insuffisante."); exit (1); } if (min2 == NULL) { printf ("memoire insuffisante."); exit (1); } heure1 = couperFin (heure1_p, 3); min1 = couperDebut (heure1_p, 3); heure2 = couperFin (heure2_p, 3); min2 = couperDebut (heure2_p, 3); if (heure1 > heure2) { retour = 1; } else if (heure1 == heure2 && min1 > min2) { retour = 1; } return (retour); } int comparedates (char *date1, char *date2) { char *jour1 = (char *) malloc (3 * sizeof (char)); char *mois1 = (char *) malloc (3 * sizeof (char)); char *annee1 = (char *) malloc (3 * sizeof (char)); char *jour2 = (char *) malloc (3 * sizeof (char)); char *mois2 = (char *) malloc (3 * sizeof (char)); char *annee2 = (char *) malloc (3 * sizeof (char)); int retour = 0; /* verification de l'allocation */ if (jour1 == NULL) { printf ("memoire insuffisante."); exit (1); } if (mois1 == NULL) { printf ("memoire insuffisante."); exit (1); } if (annee1 == NULL) { printf ("memoire insuffisante."); exit (1); } if (jour2 == NULL) { printf ("memoire insuffisante."); exit (1); } if (mois2 == NULL) { printf ("memoire insuffisante."); exit (1); } if (annee2 == NULL) { printf ("memoire insuffisante."); exit (1); } jour1 = couperFin (date1, 8); annee1 = couperDebut (date1, 6); mois1 = couperDebut (date1, 3); mois1 = couperFin (mois1, 5); jour2 = couperFin (date2, 8); annee2 = couperDebut (date2, 6); mois2 = couperDebut (date2, 3); mois2 = couperFin (mois2, 5); if (annee1 > annee2) { retour = 1; } else if (annee1 == annee2 && mois1 > mois2) { retour = 1; } else if (mois1 == mois2 && jour1 > jour2) { retour = 1; } return (retour); }
Code:
1
2
3
4
5
6
7
8
9
10
11
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 -------------- Build: Debug in hello --------------- Compiling: main.c C:\dev\hello\main.c:14: warning: function declaration isn't a prototype C:\dev\hello\main.c:15: warning: function declaration isn't a prototype C:\dev\hello\main.c:44: warning: function declaration isn't a prototype C:\dev\hello\main.c: In function `timer': C:\dev\hello\main.c:93: warning: implicit declaration of function `strcmp' C:\dev\hello\main.c:104: warning: passing arg 1 of `compareheures' makes pointer from integer without a cast C:\dev\hello\main.c:112: warning: passing arg 2 of `comparedates' makes pointer from integer without a cast C:\dev\hello\main.c:134: warning: function returns address of local variable C:\dev\hello\main.c:72: warning: 'count' might be used uninitialized in this function C:\dev\hello\main.c: In function `modifXML': C:\dev\hello\main.c:174: warning: will never be executed C:\dev\hello\main.c:174: warning: will never be executed Linking console executable: bin\Debug\hello.exe obj\Debug\main.o: In function `recupheure': C:/dev/hello/main.c:37: undefined reference to `_couperFin' obj\Debug\main.o: In function `timer': C:/dev/hello/main.c:98: undefined reference to `_formatAff' obj\Debug\main.o: In function `compareheures': C:/dev/hello/main.c:222: undefined reference to `_couperFin' C:/dev/hello/main.c:223: undefined reference to `_couperDebut' C:/dev/hello/main.c:224: undefined reference to `_couperFin' C:/dev/hello/main.c:225: undefined reference to `_couperDebut' obj\Debug\main.o: In function `comparedates': C:/dev/hello/main.c:280: undefined reference to `_couperFin' C:/dev/hello/main.c:281: undefined reference to `_couperDebut' C:/dev/hello/main.c:282: undefined reference to `_couperDebut' C:/dev/hello/main.c:283: undefined reference to `_couperFin' C:/dev/hello/main.c:284: undefined reference to `_couperFin' C:/dev/hello/main.c:285: undefined reference to `_couperDebut' C:/dev/hello/main.c:286: undefined reference to `_couperDebut' C:/dev/hello/main.c:287: undefined reference to `_couperFin' C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libmingw32.a(main.o):main.c:(.text+0x104): undefined reference to `_WinMain@16' collect2: ld returned 1 exit status Process terminated with status 1 (0 minutes, 0 seconds) 15 errors, 10 warnings
ben en fait , j ai mis que les fonctions ou il y a des problemes dans les parametres au niveau des types
le code complet est ceci , mais le service ne rentre pas en compte
Code:
1
2
3
4
5
6
7
8
9
10
11
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841 #include <windows.h> #include <stdlib.h> #include <process.h> /* _beginthread, _endthread */ #include <stdio.h> #include <time.h> #include <string.h> #include<wininet.h> #include <time.h> #include <locale.h> #include <pthread.h> /***********************************************************************************/ void myThread( void *ch ); void *ThreadTimer (void *data); char * formatAff(char * chaine,int i,int j); char * couperDebut(char * chaine, int n); char * couperFin(char * chaine, int n); int * timer(char sheure,char sdate); void modifXML(int * lignes ); char * recupdate(); char * recupheure(); int compareheures(char * heure1_p, char * heure2_p); int comparedates(char * date1, char * date2); typedef struct _MyData { const char *site; const char *url; const char *script; DWORD loopMs; } MYDATA, *PMYDATA; /***********************************************************************************/ // *** Some usefull defines #define _YES_ 0x01 #define _NO_ 0x00 #define _OK_ 0x00 #define _ERROR_ 0x01 int nId; // *** User Functions short isServiceInstalled(void); short installService(void); short uninstallService(void); // *** API Functions // These functions are prototype pre-defined. You can name them as you want. void WINAPI sendIPMain(DWORD dwNumServiceArgs, LPTSTR *lpServiceArgs); void WINAPI XControlHandler(DWORD dwControl); // *** Global Variables /***********************************************************************************/ BOOL repeat = TRUE; /* Global repeat flag and video variable */ /***********************************************************************************/ SERVICE_STATUS_HANDLE ghCtrlStatus; SERVICE_STATUS gStatus; HANDLE ghevDoForever = NULL; // *** Main - EntryPoint int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { // Create Service Data Array (contains information about service) SERVICE_TABLE_ENTRY SrvTable[2]; pthread_t Timer5min; pthread_create (&Timer5min, NULL, ThreadTimer, (void*)"timer"); pthread_join (Timer5min, NULL); // Verify if service is running ghevDoForever = OpenEvent( SYNCHRONIZE, FALSE, "sendIPRunEvt" ); if ( ghevDoForever ) { MessageBox( NULL, "sendIP is active ! Stop it.", "sendIP", MB_ICONINFORMATION ); (void) CloseHandle( ghevDoForever ); exit(-1); } // Init Global Vars (void) memset( &gStatus, 0x00, sizeof(gStatus) ); ghevDoForever = NULL; // Verify command line arguments if ( strlen( lpCmdLine ) > 0 ) { if ( !strcmp( lpCmdLine, "-delete" ) || !strcmp( lpCmdLine, "-DELETE" ) ) { if ( uninstallService() ) { MessageBox( NULL, "sendIP couldn't be uninstalled !", "sendIP", MB_ICONINFORMATION ); exit(-1); } exit(0); } else { char _tmp[50]; (void) memset( _tmp, 0x00, sizeof(_tmp) ); sprintf( _tmp, "[%s] is not valid !", lpCmdLine ); MessageBox( NULL, _tmp, "sendIP", MB_ICONINFORMATION ); exit(-1); } } // if service is installed ... if ( isServiceInstalled() == _NO_ ) if ( installService() == _OK_ ) { MessageBox( NULL, "sendIP was installed sucessfully !", "sendIP", MB_ICONINFORMATION ); exit(0); } else { MessageBox( NULL, "Process was aborted !", "sendIP", MB_ICONINFORMATION ); exit(-1); } // Load service SrvTable[0].lpServiceName = "sendIP"; // Service name SrvTable[0].lpServiceProc = sendIPMain; // Service EntryPoint SrvTable[1].lpServiceName = NULL; // Nothing SrvTable[1].lpServiceProc = NULL; // Nothing // Pass the control to sendIPMain if ( !StartServiceCtrlDispatcher(SrvTable) ) { MessageBox( NULL, "Service Start Error !", "sendIP", MB_ICONERROR ); exit(-1); } } void *ThreadTimer (void *data) { (void) data; //effectuer toutes les 5 min while(1) { Sleep(300000); timer(compareheures(modifXML,recupheure),comparedates(modifXML,recupdate)); system(" start http://127.0.0.1/php/dump.php"); } return NULL; } /*-----------------------------------------------------------------------------*/ void WINAPI sendIPMain(DWORD dwNumServiceArgs, LPTSTR *lpServiceArgs) { DWORD rc; /***********************************************************************************/ HKEY regHandle=NULL; unsigned long regType,regcbData; char site[100]="TEST2"; char url[100]="dc2-web21.assortedinternet.com"; char script[100]="/~sendip/sendip.php"; DWORD loopMs = 900000; PMYDATA pData; /***********************************************************************************/ // Register function that will receive messages from service manager // Must be the first action in Service Main ghCtrlStatus = RegisterServiceCtrlHandler( "sendIP", (LPHANDLER_FUNCTION)XControlHandler ); if ( ghCtrlStatus == (SERVICE_STATUS_HANDLE)NULL ) { MessageBox( NULL, "Error in sendIPMain-RegisterServiceCtrlHandler !", "sendIP", MB_ICONERROR ); DebugBreak(); // Force an error } // Create a semaphore to keep service alive ghevDoForever = CreateEvent( NULL, FALSE, FALSE, "sendIPRunEvt" ); gStatus.dwServiceType = SERVICE_WIN32; gStatus.dwCurrentState = SERVICE_RUNNING; gStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN; gStatus.dwWin32ExitCode = NO_ERROR; gStatus.dwServiceSpecificExitCode = NO_ERROR; gStatus.dwCheckPoint = 0; gStatus.dwWaitHint = 0; // Make the first Status update rc = SetServiceStatus( ghCtrlStatus, &gStatus ); if (!rc) { MessageBox( NULL, "Error in sendIPMain-SetServiceStatus !", "sendIP", MB_ICONERROR ); DebugBreak(); } // After this point the XControlHandler function will receive control requests. // You can start your processes, threads and any other task that you want // I use to start a main thread at this point /**************************************************************************************/ // MessageBox( NULL, "Le service est démarré", "sendIP", MB_ICONERROR ); /***********************************************************************************/ if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, "Software\\sendIP", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, ®Handle,NULL) == ERROR_SUCCESS) { regcbData = 100; if (RegQueryValueEx(regHandle, "site", NULL, ®Type, (unsigned char *) site, ®cbData) != ERROR_SUCCESS) RegSetValueEx(regHandle, "site", 0, REG_SZ, (LPBYTE) site, strlen(site)); regcbData = 100; if (RegQueryValueEx(regHandle, "url", NULL, ®Type, (unsigned char *) url, ®cbData) != ERROR_SUCCESS) RegSetValueEx(regHandle, "url", 0, REG_SZ, (LPBYTE) url, strlen(url)); regcbData = 100; if (RegQueryValueEx(regHandle, "script", NULL, ®Type, (unsigned char *) script, ®cbData) != ERROR_SUCCESS) RegSetValueEx(regHandle, "script", 0, REG_SZ, (LPBYTE) script, strlen(script)); regcbData = sizeof(DWORD); if (RegQueryValueEx(regHandle, "loop", NULL, ®Type, (LPBYTE) &loopMs, ®cbData) != ERROR_SUCCESS) ; RegSetValueEx(regHandle, "loop", 0, REG_DWORD, (LPBYTE) &loopMs, sizeof(DWORD)); RegCloseKey(regHandle); } // Allocate memory for thread data. pData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(MYDATA)); pData->loopMs = loopMs; pData->script = script; pData->site = site; pData->url = url; /***********************************************************************************/ _beginthread( myThread, 0, pData ); /**************************************************************************************/ // end of your code // Keep service running (void) WaitForSingleObject( ghevDoForever, INFINITE ); // Service received a termination command (see XControlHandler function ) gStatus.dwCurrentState = SERVICE_STOPPED; (void) SetServiceStatus( ghCtrlStatus, &gStatus ); return; } /*-----------------------------------------------------------------------------*/ void WINAPI XControlHandler(DWORD dwControl) { DWORD rc; // Receive messages from service control dispatcher switch (dwControl) { case SERVICE_CONTROL_PAUSE : case SERVICE_CONTROL_CONTINUE : case SERVICE_CONTROL_INTERROGATE : gStatus.dwWaitHint = 0; break; case SERVICE_CONTROL_SHUTDOWN: case SERVICE_CONTROL_STOP : /**************************************************************************************/ repeat = 0; /* _endthread implied */ // MessageBox( NULL, "Le service est stoppé", "sendIP", MB_ICONERROR ); /**************************************************************************************/ gStatus.dwCurrentState = SERVICE_STOP_PENDING; gStatus.dwWaitHint = 5000; break; } // Update service status rc = SetServiceStatus( ghCtrlStatus, &gStatus ); if (!rc) { MessageBox( NULL, "Error in XControlHandler-SetServiceStatus !", "sendIP", MB_ICONERROR ); DebugBreak(); } // If message is a stop or shutdown so, service is going to be stoped if ( (dwControl == SERVICE_CONTROL_STOP) || (dwControl == SERVICE_CONTROL_SHUTDOWN) ) (void) SetEvent( ghevDoForever ); } /*-----------------------------------------------------------------------------*/ short installService(void) { SC_HANDLE scHndl; SC_HANDLE scServ; char cCurDir[256]; // Get the current directory (the directory where the service is) (void) memset( cCurDir, 0x00, sizeof(cCurDir) ); (void) GetCurrentDirectory( 256, cCurDir ); (void) strcat( cCurDir, cCurDir[strlen(cCurDir)-1] == 92 ? "sendIP.exe" : "\\sendIP.exe" ); // Install the sendIP to Service Control Manager Database scHndl = OpenSCManager( NULL, NULL, SC_MANAGER_CREATE_SERVICE ); if ( scHndl == NULL ) { MessageBox( NULL, "Error in installService-OpenSCManager !", "sendIP", MB_ICONERROR ); return _ERROR_; } scServ = CreateService( scHndl, "sendIP", "send IP Service", SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, cCurDir, NULL, NULL, NULL, NULL, NULL ); if ( scServ == NULL ) { MessageBox( NULL, "Error in installService-CreateService !", "sendIP", MB_ICONERROR ); (void) CloseHandle( scHndl ); return _ERROR_; } (void) CloseHandle( scServ ); (void) CloseHandle( scHndl ); return _OK_; } /*-----------------------------------------------------------------------------*/ short uninstallService(void) { SC_HANDLE scHndl; SC_HANDLE scServ; DWORD _err = 0; // UnInstall the sendIP from Service Control Manager Database scHndl = OpenSCManager( NULL, NULL, SC_MANAGER_CREATE_SERVICE ); if ( scHndl == NULL ) { MessageBox( NULL, "Error in uninstallService-OpenSCManager !", "sendIP", MB_ICONERROR ); return _ERROR_; } scServ = OpenService( scHndl, "sendIP", SERVICE_ALL_ACCESS ); _err = GetLastError(); if ( scServ == NULL ) { if ( _err == ERROR_SERVICE_DOES_NOT_EXIST ) { (void) CloseHandle( scServ ); (void) CloseHandle( scHndl ); } return _ERROR_; } if ( !DeleteService( scServ ) ) { MessageBox( NULL, "Error in uninstallService-DeleteService !", "sendIP", MB_ICONERROR ); return _ERROR_; } (void) CloseHandle(scServ); (void) CloseHandle(scHndl); MessageBox( NULL, "sendIP was uninstalled sucessfully !", "sendIP", MB_ICONINFORMATION ); return _OK_; } /*-----------------------------------------------------------------------------*/ short isServiceInstalled(void) { SC_HANDLE scHndl; SC_HANDLE scServ; DWORD _err = 0; scHndl = OpenSCManager( NULL, NULL, SC_MANAGER_CREATE_SERVICE ); if ( scHndl == NULL ) { MessageBox( NULL, "Error in isServiceInstalled-OpenSCManager !", "sendIP", MB_ICONERROR ); exit(-1); } scServ = OpenService( scHndl, "sendIP", SERVICE_ALL_ACCESS ); _err = GetLastError(); if ( scServ == NULL ) { if ( _err == ERROR_SERVICE_DOES_NOT_EXIST ) { (void) CloseHandle( scServ ); (void) CloseHandle( scHndl ); return _NO_; } else { MessageBox( NULL, "Error in isServiceInstalled-OpenService !", "sendIP", MB_ICONERROR ); exit(-1); } } (void) CloseHandle( scServ ); (void) CloseHandle( scHndl ); return _YES_; } /**************************************************************************************/ void myThread( PVOID lpParam ) { HINTERNET Initialize,Connection,File; PMYDATA pData; char adresse[100]; char timestamp[16]; struct tm *tm_ptr; time_t myTime; // Cast the parameter to the correct data type. pData = (PMYDATA)lpParam; while( repeat ) { /*initialize the wininet library*/ Initialize = InternetOpen("HTTPGET",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0); /*connect to the server*/ Connection = InternetConnect(Initialize,pData->url,INTERNET_DEFAULT_HTTP_PORT, NULL,NULL,INTERNET_SERVICE_HTTP,0,0); /*open up an HTTP request*/ //récupère heure système time(&myTime); tm_ptr = localtime(&myTime); strftime(timestamp,16,"%Y%m%d%H%M%S",tm_ptr); sprintf(adresse, "%s?site=%s&date=%s",pData->script,pData->site,timestamp); //sprintf(adresse, "%s?site=%s×tamp=",pData->script,pData->site); File = HttpOpenRequest(Connection,NULL,adresse,NULL,NULL,NULL,0,0); /*close file , terminate server connection and deinitialize the wininet library*/ HttpSendRequest(File,NULL,0,NULL,0); InternetCloseHandle(Connection); InternetCloseHandle(Initialize); /* Pause between loops. 15 minutes*/ Sleep( pData->loopMs ); // Sleep( 900000L ); } /* _endthread given to terminate */ _endthread(); } /*void *ThreadTimer (void *data) { (void) data; //effectuer toutes les 5 min while(1) { Sleep(300000); modifXML(timer(recupdate(),recupheure())); } return NULL; }*/ /**************************************************************************************/ char * formatAff(char * chaine, int i, int j)// permet de parser le xml( recuperer le contenu entre balises) { char * tampon = (char *)malloc(256*sizeof(char)); if(tampon == NULL) { printf("Memoire insuffisante, arret du programme."); exit(1); } switch(i) { case 2:// balise nom tampon = couperDebut(chaine,13); tampon = couperFin(tampon, 11); break; case 3://balise adresse tampon = couperDebut(chaine, 21); tampon = couperFin(tampon, 19); break; case 4:// balise heure tampon = couperDebut(chaine,11); tampon = couperFin(tampon, 9); break; case 5://balise date tampon = couperDebut(chaine,10); tampon = couperFin(tampon, 8); } return tampon; } char * couperDebut(char * chaine, int n)// coupe les premieres balises"<>" { register int i=0; char * tampon = (char *)malloc(256*sizeof(char)); if(tampon == NULL) { printf("Memoire insuffisante, arret du programme."); exit(1); } for(i=0;i<256;i++) { if(chaine[i]=='\0') break; tampon[i] = chaine[i+n]; } tampon[i] = '\0'; return(tampon); } char * couperFin(char * chaine, int n)// couper les derniere balises "</>" { register int i; char * tampon = (char *)malloc(256*sizeof(char)); if(tampon == NULL) { printf("Memoire insuffisante, arret du programme."); exit(1); } for(i=0;i<256;i++) { if(chaine[i+n]=='\0') break; tampon[i] = chaine[i]; } tampon[i]='\0'; return(tampon); } //recupere l'heure du systeme char * recupheure() { /* Lecture de la date et de l'heure */ time_t timestamp=time (NULL); struct tm t = *localtime(×tamp); char * sheure=(char *)malloc(11*sizeof(char)); if(sheure == NULL) { printf("memoire insuffisante."); exit(1); } /* Affiche la date et l'heure courante (format français) */ setlocale(LC_ALL, ""); strftime(sheure,sizeof sheure, "%X",&t);// %X signifie le format hh:mm sheure = couperFin(sheure,3);// enleve les sec return(sheure); } //recupere la date du systeme char * recupdate() { time_t timestamp=time (NULL); struct tm t = *localtime(×tamp); char * sdate=(char *)malloc(11*sizeof(char)); if(sdate == NULL) { printf("memoire insuffisante."); exit(1); } /* Affiche la date et l'heure courante (format français) */ setlocale(LC_ALL, ""); strftime(sdate,sizeof sdate,"%x ", &t);// %x signifie le format jj//mm//aa return(sdate); } int * timer(char sheure,char sdate) { FILE * fp = NULL;// lire le fichier xml short int i=-1; unsigned int j=0; char * chaine = (char *)malloc(256*sizeof(char)); int bool1=0; int bool2=0; int lignes[256];// limitation a 256 jobs int count; if(chaine == NULL) { printf("Memoire insuffisante, arret du programme."); exit(1); } if((fp = fopen("C:\\Users\\Habib\\Documents\\Visual Studio 2008\\Projects\\fenetre2\\Debug\\data.xml","r+"))==NULL) { printf("ERREUR LORS DE L'OUVERTURE DU FICHIER\n"); exit(1); } /* lecture du fichier xml */ while(fgets(chaine, 255, fp)) { if(!strcmp(chaine, "</automatisation>")) break; //si i=4, chaine = heurexml, si i=5, chaine = datexml chaine = formatAff(chaine,i,j); //compare heures if(i==4) { if(compareheures(sheure,chaine)) { bool1=1; } } if(i==5) { if(comparedates(chaine,sdate)) { bool2=1; } } if(i==6)// i designe le nombre de ligne parcourues dans le fichier xml { i=1; j++; } else i++; if(bool1 && bool2) { lignes[count] = j; count++; } } fclose(fp); return(lignes); } void modifXML(int * lignes)// modifie le fichier xml avec les nouvelles valeurs { int i=0; int count=0; char * chaine = (char*) malloc(256*sizeof(char)); FILE * fp; if(chaine == NULL) { printf("memoire insuffisante."); exit(1); } if((fp=fopen("C:\\Users\\Habib\\Documents\\Visual Studio 2008\\Projects\\fenetre2\\Debug\\data.xml","r+"))) { exit(1); } while(i<500) { while(fgets(chaine,255,fp)!=NULL) { if(count==lignes[i] ) { fseek(fp, count, 0 ); //modification fputs("<date>nouvelle heure</date>",fp); rewind(fp); count=0; break; } if(count==lignes[i] ) { fseek(fp, count, 0 ); fputs("<date>nouvelle date</date>",fp); rewind(fp); count=0; break; } count++; } i++; } fclose(fp); } //heure1>heure2 ==> 1 int compareheures(char * heure1_p, char * heure2_p)// renvoi 0 , si la valeur de heure 1 est < a heure 2 et sinon 1 { char * heure1 = (char *)malloc(3*sizeof(char)); char * min1 = (char *)malloc(3*sizeof(char)); char * heure2 = (char *)malloc(3*sizeof(char)); char * min2 = (char *)malloc(3*sizeof(char)); int retour=0; /* verification de l'allocation */ if(heure1==NULL) { printf("memoire insuffisante."); exit(1); } if(min1==NULL) { printf("memoire insuffisante."); exit(1); } if(heure2==NULL) { printf("memoire insuffisante."); exit(1); } if(min2==NULL) { printf("memoire insuffisante."); exit(1); } heure1=couperFin(heure1_p,3); min1 = couperDebut(heure1_p,3); heure2=couperFin(heure2_p,3); min2 = couperDebut(heure2_p,3); if(heure1>heure2) { retour =1; } else if(heure1==heure2 && min1>min2) { retour = 1; } return(retour); } int comparedates(char * date1,char * date2)// renvoi 0 , si la valeur de date 1 est < a date 2 et sinon 1 { char * jour1 = (char *)malloc(3*sizeof(char)); char * mois1 = (char *)malloc(3*sizeof(char)); char * annee1 = (char *)malloc(3*sizeof(char)); char * jour2 = (char *)malloc(3*sizeof(char)); char * mois2 = (char *)malloc(3*sizeof(char)); char * annee2 = (char *)malloc(3*sizeof(char)); int retour=0; /* verification de l'allocation */ if(jour1==NULL) { printf("memoire insuffisante."); exit(1); } if(mois1==NULL) { printf("memoire insuffisante."); exit(1); } if(annee1==NULL) { printf("memoire insuffisante."); exit(1); } if(jour2==NULL) { printf("memoire insuffisante."); exit(1); } if(mois2==NULL) { printf("memoire insuffisante."); exit(1); } if(annee2==NULL) { printf("memoire insuffisante."); exit(1); } jour1=couperFin(date1,8); annee1 = couperDebut(date1,6); mois1 = couperDebut(date1,3); mois1 = couperFin(mois1,5); jour2=couperFin(date2,8); annee2 = couperDebut(date2,6); mois2 = couperDebut(date2,3); mois2 = couperFin(mois2,5); if(annee1>annee2) { retour =1; } else if(annee1==annee2 && mois1>mois2) { retour = 1; } else if(mois1==mois2 && jour1>jour2) { retour = 1; } return(retour); }
merci beaucoup encore
- Les commentaires en C90, c'est /* */
- Si une fonction n'a pas de paramètres, on le précise avec void.
- Ce code est ambigu
Est-ce que tu veux direCode:
1
2
3
4
5
6
7
8
9
10
11
12
13
14 if (isServiceInstalled () == _NO_) if (installService () == _OK_) { MessageBox (NULL, "sendIP was installed sucessfully !", "sendIP", MB_ICONINFORMATION); exit (0); } else { MessageBox (NULL, "Process was aborted !", "sendIP", MB_ICONINFORMATION); exit (-1); }
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 if (isServiceInstalled () == _NO_) { if (installService () == _OK_) { MessageBox (NULL, "sendIP was installed sucessfully !", "sendIP", MB_ICONINFORMATION); exit (0); } else { MessageBox (NULL, "Process was aborted !", "sendIP", MB_ICONINFORMATION); exit (-1); } }
- La fonction WinMain() a un type retour (int), mais rien n'est retourné...
- cette fonction int *timer (char sheure, char sdate); attent des char et tu lui passe des int. C'est pas logique. Il vaut mieux mettre les paramètres en int.
- La fonction void modifXML (int *lignes); ne retourne rien, or tu la passes en paramètre à int compareheures (char *heure1_p, char *heure2_p); qui attend des adresses de char. Ca n'a aucun sens... Je ne sais pas corriger ça, car je ne sais pas ce que tu veux faire... Idem avec comparedates() ...
- Attention. Dans ce code :
il y a une ; après le if. C'est incohérent.Code:
1
2
3
4 if (RegQueryValueEx (regHandle, "loop", NULL, ®Type, (LPBYTE) & loopMs, ®cbData) != ERROR_SUCCESS);
- Si on veut isoler du code, on utilise #if 0 ... #endif et non les commentaires.
- Trop d'erreurs. ce code est très faux.
J'en suis là:
Si quelqu'un veut continuer, je cède la place...Code:
1
2
3
4
5
6
7
8
9
10
11
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896 #include <windows.h> #include <stdlib.h> /* _beginthread, _endthread */ #include <process.h> #include <stdio.h> #include <time.h> #include <string.h> #include<wininet.h> #include <time.h> #include <locale.h> #include <pthread.h> /***********************************************************************************/ void myThread (void *ch); void *ThreadTimer (void *data); char *formatAff (char *chaine, int i, int j); char *couperDebut (char *chaine, int n); char *couperFin (char *chaine, int n); int *timer (int sheure, int sdate); void modifXML (int *lignes); char *recupdate (void); char *recupheure (void); int compareheures (char *heure1_p, char *heure2_p); int comparedates (char *date1, char *date2); typedef struct _MyData { const char *site; const char *url; const char *script; DWORD loopMs; } MYDATA, *PMYDATA; /***********************************************************************************/ /* *** Some usefull defines */ #define _YES_ 0x01 #define _NO_ 0x00 #define _OK_ 0x00 #define _ERROR_ 0x01 int nId; /* *** User Functions */ short isServiceInstalled (void); short installService (void); short uninstallService (void); /* *** API Functions */ /* These functions are prototype pre-defined. You can name them as you want. */ void WINAPI sendIPMain (DWORD dwNumServiceArgs, LPTSTR * lpServiceArgs); void WINAPI XControlHandler (DWORD dwControl); /* *** Global Variables */ /***********************************************************************************/ /* Global repeat flag and video variable */ BOOL repeat = TRUE; /***********************************************************************************/ SERVICE_STATUS_HANDLE ghCtrlStatus; SERVICE_STATUS gStatus; HANDLE ghevDoForever = NULL; /* *** Main - EntryPoint */ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { /* Create Service Data Array (contains information about service) */ SERVICE_TABLE_ENTRY SrvTable[2]; pthread_t Timer5min; pthread_create (&Timer5min, NULL, ThreadTimer, (void *) "timer"); pthread_join (Timer5min, NULL); /* Verify if service is running */ ghevDoForever = OpenEvent (SYNCHRONIZE, FALSE, "sendIPRunEvt"); if (ghevDoForever) { MessageBox (NULL, "sendIP is active ! Stop it.", "sendIP", MB_ICONINFORMATION); (void) CloseHandle (ghevDoForever); exit (-1); } /* Init Global Vars */ (void) memset (&gStatus, 0x00, sizeof (gStatus)); ghevDoForever = NULL; /* Verify command line arguments */ if (strlen (lpCmdLine) > 0) { if (!strcmp (lpCmdLine, "-delete") || !strcmp (lpCmdLine, "-DELETE")) { if (uninstallService ()) { MessageBox (NULL, "sendIP couldn't be uninstalled !", "sendIP", MB_ICONINFORMATION); exit (-1); } exit (0); } else { char _tmp[50]; (void) memset (_tmp, 0x00, sizeof (_tmp)); sprintf (_tmp, "[%s] is not valid !", lpCmdLine); MessageBox (NULL, _tmp, "sendIP", MB_ICONINFORMATION); exit (-1); } } /* if service is installed ... */ if (isServiceInstalled () == _NO_) { if (installService () == _OK_) { MessageBox (NULL, "sendIP was installed sucessfully !", "sendIP", MB_ICONINFORMATION); exit (0); } else { MessageBox (NULL, "Process was aborted !", "sendIP", MB_ICONINFORMATION); exit (-1); } } /* Load service */ /* Service name */ SrvTable[0].lpServiceName = "sendIP"; /* Service EntryPoint */ SrvTable[0].lpServiceProc = sendIPMain; /* Nothing */ SrvTable[1].lpServiceName = NULL; /* Nothing */ SrvTable[1].lpServiceProc = NULL; /* Pass the control to sendIPMain */ if (!StartServiceCtrlDispatcher (SrvTable)) { MessageBox (NULL, "Service Start Error !", "sendIP", MB_ICONERROR); exit (-1); } return 0; } void *ThreadTimer (void *data) { (void) data; /* effectuer toutes les 5 min */ while (1) { Sleep (300000); timer (compareheures (modifXML, recupheure), comparedates (modifXML, recupdate)); system (" start http://127.0.0.1/php/dump.php"); } return NULL; } /*-----------------------------------------------------------------------------*/ void WINAPI sendIPMain (DWORD dwNumServiceArgs, LPTSTR * lpServiceArgs) { DWORD rc; /***********************************************************************************/ HKEY regHandle = NULL; unsigned long regType, regcbData; char site[100] = "TEST2"; char url[100] = "dc2-web21.assortedinternet.com"; char script[100] = "/~sendip/sendip.php"; DWORD loopMs = 900000; PMYDATA pData; /***********************************************************************************/ /* Register function that will receive messages from service manager */ /* Must be the first action in Service Main */ ghCtrlStatus = RegisterServiceCtrlHandler ("sendIP", (LPHANDLER_FUNCTION) XControlHandler); if (ghCtrlStatus == (SERVICE_STATUS_HANDLE) NULL) { MessageBox (NULL, "Error in sendIPMain-RegisterServiceCtrlHandler !", "sendIP", MB_ICONERROR); /* Force an error */ DebugBreak (); } /* Create a semaphore to keep service alive */ ghevDoForever = CreateEvent (NULL, FALSE, FALSE, "sendIPRunEvt"); gStatus.dwServiceType = SERVICE_WIN32; gStatus.dwCurrentState = SERVICE_RUNNING; gStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN; gStatus.dwWin32ExitCode = NO_ERROR; gStatus.dwServiceSpecificExitCode = NO_ERROR; gStatus.dwCheckPoint = 0; gStatus.dwWaitHint = 0; /* Make the first Status update */ rc = SetServiceStatus (ghCtrlStatus, &gStatus); if (!rc) { MessageBox (NULL, "Error in sendIPMain-SetServiceStatus !", "sendIP", MB_ICONERROR); DebugBreak (); } /* After this point the XControlHandler function will receive control requests. */ /* You can start your processes, threads and any other task that you want */ /* I use to start a main thread at this point */ /**************************************************************************************/ /* MessageBox( NULL, "Le service est démarré", "sendIP", MB_ICONERROR ); */ /***********************************************************************************/ if (RegCreateKeyEx (HKEY_LOCAL_MACHINE, "Software\\sendIP", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, ®Handle, NULL) == ERROR_SUCCESS) { regcbData = 100; if (RegQueryValueEx (regHandle, "site", NULL, ®Type, (unsigned char *) site, ®cbData) != ERROR_SUCCESS) RegSetValueEx (regHandle, "site", 0, REG_SZ, (LPBYTE) site, strlen (site)); regcbData = 100; if (RegQueryValueEx (regHandle, "url", NULL, ®Type, (unsigned char *) url, ®cbData) != ERROR_SUCCESS) RegSetValueEx (regHandle, "url", 0, REG_SZ, (LPBYTE) url, strlen (url)); regcbData = 100; if (RegQueryValueEx (regHandle, "script", NULL, ®Type, (unsigned char *) script, ®cbData) != ERROR_SUCCESS) RegSetValueEx (regHandle, "script", 0, REG_SZ, (LPBYTE) script, strlen (script)); regcbData = sizeof (DWORD); if (RegQueryValueEx (regHandle, "loop", NULL, ®Type, (LPBYTE) & loopMs, ®cbData) != ERROR_SUCCESS) { RegSetValueEx (regHandle, "loop", 0, REG_DWORD, (LPBYTE) & loopMs, sizeof (DWORD)); } RegCloseKey (regHandle); } /* Allocate memory for thread data. */ pData = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof (MYDATA)); pData->loopMs = loopMs; pData->script = script; pData->site = site; pData->url = url; /***********************************************************************************/ _beginthread (myThread, 0, pData); /**************************************************************************************/ /* end of your code */ /* Keep service running */ (void) WaitForSingleObject (ghevDoForever, INFINITE); /* Service received a termination command (see XControlHandler function ) */ gStatus.dwCurrentState = SERVICE_STOPPED; (void) SetServiceStatus (ghCtrlStatus, &gStatus); return; } /*-----------------------------------------------------------------------------*/ void WINAPI XControlHandler (DWORD dwControl) { DWORD rc; /* Receive messages from service control dispatcher */ switch (dwControl) { case SERVICE_CONTROL_PAUSE: case SERVICE_CONTROL_CONTINUE: case SERVICE_CONTROL_INTERROGATE: gStatus.dwWaitHint = 0; break; case SERVICE_CONTROL_SHUTDOWN: case SERVICE_CONTROL_STOP: /**************************************************************************************/ /* _endthread implied */ repeat = 0; /* MessageBox( NULL, "Le service est stoppé", "sendIP", MB_ICONERROR ); */ /**************************************************************************************/ gStatus.dwCurrentState = SERVICE_STOP_PENDING; gStatus.dwWaitHint = 5000; break; } /* Update service status */ rc = SetServiceStatus (ghCtrlStatus, &gStatus); if (!rc) { MessageBox (NULL, "Error in XControlHandler-SetServiceStatus !", "sendIP", MB_ICONERROR); DebugBreak (); } /* If message is a stop or shutdown so, service is going to be stoped */ if ((dwControl == SERVICE_CONTROL_STOP) || (dwControl == SERVICE_CONTROL_SHUTDOWN)) (void) SetEvent (ghevDoForever); } /*-----------------------------------------------------------------------------*/ short installService (void) { SC_HANDLE scHndl; SC_HANDLE scServ; char cCurDir[256]; /* Get the current directory (the directory where the service is) */ (void) memset (cCurDir, 0x00, sizeof (cCurDir)); (void) GetCurrentDirectory (256, cCurDir); (void) strcat (cCurDir, cCurDir[strlen (cCurDir) - 1] == 92 ? "sendIP.exe" : "\\sendIP.exe"); /* Install the sendIP to Service Control Manager Database */ scHndl = OpenSCManager (NULL, NULL, SC_MANAGER_CREATE_SERVICE); if (scHndl == NULL) { MessageBox (NULL, "Error in installService-OpenSCManager !", "sendIP", MB_ICONERROR); return _ERROR_; } scServ = CreateService (scHndl, "sendIP", "send IP Service", SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, cCurDir, NULL, NULL, NULL, NULL, NULL); if (scServ == NULL) { MessageBox (NULL, "Error in installService-CreateService !", "sendIP", MB_ICONERROR); (void) CloseHandle (scHndl); return _ERROR_; } (void) CloseHandle (scServ); (void) CloseHandle (scHndl); return _OK_; } /*-----------------------------------------------------------------------------*/ short uninstallService (void) { SC_HANDLE scHndl; SC_HANDLE scServ; DWORD _err = 0; /* UnInstall the sendIP from Service Control Manager Database */ scHndl = OpenSCManager (NULL, NULL, SC_MANAGER_CREATE_SERVICE); if (scHndl == NULL) { MessageBox (NULL, "Error in uninstallService-OpenSCManager !", "sendIP", MB_ICONERROR); return _ERROR_; } scServ = OpenService (scHndl, "sendIP", SERVICE_ALL_ACCESS); _err = GetLastError (); if (scServ == NULL) { if (_err == ERROR_SERVICE_DOES_NOT_EXIST) { (void) CloseHandle (scServ); (void) CloseHandle (scHndl); } return _ERROR_; } if (!DeleteService (scServ)) { MessageBox (NULL, "Error in uninstallService-DeleteService !", "sendIP", MB_ICONERROR); return _ERROR_; } (void) CloseHandle (scServ); (void) CloseHandle (scHndl); MessageBox (NULL, "sendIP was uninstalled sucessfully !", "sendIP", MB_ICONINFORMATION); return _OK_; } /*-----------------------------------------------------------------------------*/ short isServiceInstalled (void) { SC_HANDLE scHndl; SC_HANDLE scServ; DWORD _err = 0; scHndl = OpenSCManager (NULL, NULL, SC_MANAGER_CREATE_SERVICE); if (scHndl == NULL) { MessageBox (NULL, "Error in isServiceInstalled-OpenSCManager !", "sendIP", MB_ICONERROR); exit (-1); } scServ = OpenService (scHndl, "sendIP", SERVICE_ALL_ACCESS); _err = GetLastError (); if (scServ == NULL) { if (_err == ERROR_SERVICE_DOES_NOT_EXIST) { (void) CloseHandle (scServ); (void) CloseHandle (scHndl); return _NO_; } else { MessageBox (NULL, "Error in isServiceInstalled-OpenService !", "sendIP", MB_ICONERROR); exit (-1); } } (void) CloseHandle (scServ); (void) CloseHandle (scHndl); return _YES_; } /**************************************************************************************/ void myThread (PVOID lpParam) { HINTERNET Initialize, Connection, File; PMYDATA pData; char adresse[100]; char timestamp[16]; struct tm *tm_ptr; time_t myTime; /* Cast the parameter to the correct data type. */ pData = (PMYDATA) lpParam; while (repeat) { /*initialize the wininet library*/ Initialize = InternetOpen ("HTTPGET", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); /*connect to the server*/ Connection = InternetConnect (Initialize, pData->url, INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); /*open up an HTTP request*/ /* récupère heure système */ time (&myTime); tm_ptr = localtime (&myTime); strftime (timestamp, 16, "%Y%m%d%H%M%S", tm_ptr); sprintf (adresse, "%s?site=%s&date=%s", pData->script, pData->site, timestamp); /* sprintf(adresse, "%s?site=%s×tamp=",pData->script,pData->site); */ File = HttpOpenRequest (Connection, NULL, adresse, NULL, NULL, NULL, 0, 0); /*close file , terminate server connection and deinitialize the wininet library*/ HttpSendRequest (File, NULL, 0, NULL, 0); InternetCloseHandle (Connection); InternetCloseHandle (Initialize); /* Pause between loops. 15 minutes*/ Sleep (pData->loopMs); /* Sleep( 900000L ); */ } /* _endthread given to terminate */ _endthread (); } #if 0 void *ThreadTimer (void *data) { (void) data; /* effectuer toutes les 5 min */ while (1) { Sleep (300000); modifXML (timer (recupdate (), recupheure ())); } return NULL; } #endif /**************************************************************************************/ /* permet de parser le xml( recuperer le contenu entre balises) */ char *formatAff (char *chaine, int i, int j) { char *tampon = (char *) malloc (256 * sizeof (char)); if (tampon == NULL) { printf ("Memoire insuffisante, arret du programme."); exit (1); } switch (i) { /* balise nom */ case 2: tampon = couperDebut (chaine, 13); tampon = couperFin (tampon, 11); break; /* balise adresse */ case 3: tampon = couperDebut (chaine, 21); tampon = couperFin (tampon, 19); break; /* balise heure */ case 4: tampon = couperDebut (chaine, 11); tampon = couperFin (tampon, 9); break; /* balise date */ case 5: tampon = couperDebut (chaine, 10); tampon = couperFin (tampon, 8); } return tampon; } /* coupe les premieres balises"<>" */ char *couperDebut (char *chaine, int n) { register int i = 0; char *tampon = (char *) malloc (256 * sizeof (char)); if (tampon == NULL) { printf ("Memoire insuffisante, arret du programme."); exit (1); } for (i = 0; i < 256; i++) { if (chaine[i] == '\0') break; tampon[i] = chaine[i + n]; } tampon[i] = '\0'; return (tampon); } /* couper les derniere balises "</>" */ char *couperFin (char *chaine, int n) { register int i; char *tampon = (char *) malloc (256 * sizeof (char)); if (tampon == NULL) { printf ("Memoire insuffisante, arret du programme."); exit (1); } for (i = 0; i < 256; i++) { if (chaine[i + n] == '\0') break; tampon[i] = chaine[i]; } tampon[i] = '\0'; return (tampon); } /* recupere l'heure du systeme */ char *recupheure () { /* Lecture de la date et de l'heure */ time_t timestamp = time (NULL); struct tm t = *localtime (×tamp); char *sheure = (char *) malloc (11 * sizeof (char)); if (sheure == NULL) { printf ("memoire insuffisante."); exit (1); } /* Affiche la date et l'heure courante (format français) */ setlocale (LC_ALL, ""); /* %X signifie le format hh:mm */ strftime (sheure, sizeof sheure, "%X", &t); /* enleve les sec */ sheure = couperFin (sheure, 3); return (sheure); } /* recupere la date du systeme */ char *recupdate (void) { time_t timestamp = time (NULL); struct tm t = *localtime (×tamp); char *sdate = (char *) malloc (11 * sizeof (char)); if (sdate == NULL) { printf ("memoire insuffisante."); exit (1); } /* Affiche la date et l'heure courante (format français) */ setlocale (LC_ALL, ""); /* %x signifie le format jj//mm//aa */ strftime (sdate, sizeof sdate, "%x ", &t); return (sdate); } int *timer (int sheure, int sdate) { /* lire le fichier xml */ FILE *fp = NULL; short int i = -1; unsigned int j = 0; char *chaine = (char *) malloc (256 * sizeof (char)); int bool1 = 0; int bool2 = 0; /* limitation a 256 jobs */ int lignes[256]; int count; if (chaine == NULL) { printf ("Memoire insuffisante, arret du programme."); exit (1); } if ((fp = fopen ("C:\\Users\\Habib\\Documents\\Visual Studio 2008\\Projects\\fenetre2\\Debug\\data.xml", "r+")) == NULL) { printf ("ERREUR LORS DE L'OUVERTURE DU FICHIER\n"); exit (1); } /* lecture du fichier xml */ while (fgets (chaine, 255, fp)) { if (!strcmp (chaine, "</automatisation>")) break; /* si i=4, chaine = heurexml, si i=5, chaine = datexml */ chaine = formatAff (chaine, i, j); /* compare heures */ if (i == 4) { if (compareheures (sheure, chaine)) { bool1 = 1; } } if (i == 5) { if (comparedates (chaine, sdate)) { bool2 = 1; } } /* i designe le nombre de ligne parcourues dans le fichier xml */ if (i == 6) { i = 1; j++; } else i++; if (bool1 && bool2) { lignes[count] = j; count++; } } fclose (fp); return (lignes); } /* modifie le fichier xml avec les nouvelles valeurs */ void modifXML (int *lignes) { int i = 0; int count = 0; char *chaine = (char *) malloc (256 * sizeof (char)); FILE *fp; if (chaine == NULL) { printf ("memoire insuffisante."); exit (1); } if ((fp = fopen ("C:\\Users\\Habib\\Documents\\Visual Studio 2008\\Projects\\fenetre2\\Debug\\data.xml", "r+"))) { exit (1); } while (i < 500) { while (fgets (chaine, 255, fp) != NULL) { if (count == lignes[i]) { fseek (fp, count, 0); /* modification */ fputs ("<date>nouvelle heure</date>", fp); rewind (fp); count = 0; break; } if (count == lignes[i]) { fseek (fp, count, 0); fputs ("<date>nouvelle date</date>", fp); rewind (fp); count = 0; break; } count++; } i++; } fclose (fp); } /* heure1>heure2 ==> 1 */ /* renvoi 0 , si la valeur de heure 1 est < a heure 2 et sinon 1 */ int compareheures (char *heure1_p, char *heure2_p) { char *heure1 = (char *) malloc (3 * sizeof (char)); char *min1 = (char *) malloc (3 * sizeof (char)); char *heure2 = (char *) malloc (3 * sizeof (char)); char *min2 = (char *) malloc (3 * sizeof (char)); int retour = 0; /* verification de l'allocation */ if (heure1 == NULL) { printf ("memoire insuffisante."); exit (1); } if (min1 == NULL) { printf ("memoire insuffisante."); exit (1); } if (heure2 == NULL) { printf ("memoire insuffisante."); exit (1); } if (min2 == NULL) { printf ("memoire insuffisante."); exit (1); } heure1 = couperFin (heure1_p, 3); min1 = couperDebut (heure1_p, 3); heure2 = couperFin (heure2_p, 3); min2 = couperDebut (heure2_p, 3); if (heure1 > heure2) { retour = 1; } else if (heure1 == heure2 && min1 > min2) { retour = 1; } return (retour); } /* renvoi 0 , si la valeur de date 1 est < a date 2 et sinon 1 */ int comparedates (char *date1, char *date2) { char *jour1 = (char *) malloc (3 * sizeof (char)); char *mois1 = (char *) malloc (3 * sizeof (char)); char *annee1 = (char *) malloc (3 * sizeof (char)); char *jour2 = (char *) malloc (3 * sizeof (char)); char *mois2 = (char *) malloc (3 * sizeof (char)); char *annee2 = (char *) malloc (3 * sizeof (char)); int retour = 0; /* verification de l'allocation */ if (jour1 == NULL) { printf ("memoire insuffisante."); exit (1); } if (mois1 == NULL) { printf ("memoire insuffisante."); exit (1); } if (annee1 == NULL) { printf ("memoire insuffisante."); exit (1); } if (jour2 == NULL) { printf ("memoire insuffisante."); exit (1); } if (mois2 == NULL) { printf ("memoire insuffisante."); exit (1); } if (annee2 == NULL) { printf ("memoire insuffisante."); exit (1); } jour1 = couperFin (date1, 8); annee1 = couperDebut (date1, 6); mois1 = couperDebut (date1, 3); mois1 = couperFin (mois1, 5); jour2 = couperFin (date2, 8); annee2 = couperDebut (date2, 6); mois2 = couperDebut (date2, 3); mois2 = couperFin (mois2, 5); if (annee1 > annee2) { retour = 1; } else if (annee1 == annee2 && mois1 > mois2) { retour = 1; } else if (mois1 == mois2 && jour1 > jour2) { retour = 1; } return (retour); }
je suis desole , mais ce sont mes employeurs qui m ont donne ce code qu ils ont du trouver sur le net pour faire un service car il n y a pas de bon programmeur dans cette boite
je n ai fait que les fonctions
mais je vais corriger l erreur dessuite , merci beaucoup
pas de soucis,tu m as deja enormement aide
merci pour tout
;)
grace a toi , je vois deja mes erreurs dans mes fonctions , et je vais essayer de les corriger de suite
pour le code du service , c est eux qui m en ont donne un errone , je demanderai a ce que j en ai un autre valide , car meme moi qui suis novice , je remarque qu il est tres bizarre, avec 2 executable dans le fichier debug .... enfin bref